#daniel-a_error
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1317177260842946621
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Here are some screenshots of all the code.
The Stripe logs show the session being created successfully and returning a response body with a session object, so the error HAS to be something in the Javascript, which is copied straight from Stripe's docs.
Hi ๐
So you are trying to use Stripe embedded checkout and that is where the error is occurring?
Can you share a session ID?
here's a log screenshot
If you look at the console screenshot, it looks like it's getting non-JSON back, but that's all I can see of the error. I don't know if the Javascript is executing too soon or what.
this is a screenshot, which is less useful to me.
Can you copy/paste the ID value as text here?
cs_live_b1FxPCRo79oircPe70a17gXVOcKrEvvjHTGUFW1CF654Q5DICp8fjMeAZt
Okay I can see the session creation, everything is looking good there. When you return the client_secret to your front-end, can you log that value?
No. I don't know what it's returning in the Javascript file I included here. It does an asynchronous call and returns the value to a const, but I don't know how to enumerate the values.
You should be able to await the response and log the value that is returned
Checking that would be the recommended next step
the log comes back with [object Object]. No way to know what's in it though
What is the exact log line you are calling?
I am just doing 'alert(checkout);' in the javascript file in the line right above the checkout.mount call
Well yeah, that won't work
- you need to extract the actual
client_secretstring
- Log it to the Console
So if I use console.log(checkout.client_secret) then it says it's undefined.
says the value is [object Object]
Try console.log(JSON.stringify(checkout))
which will write the object to a string and log that
Says TypeError: Converting circular structure to JSON
Okay so it looks like the problem is what your C# code is returning to the Javascript
Can you just return the following?
return Json(new {clientSecret = session.ClientSecret});
there is no session object in the C# code. And the Stripe example didn't have it either
apart from changing the priceid and key values, what is in the screenshot of the C# file I sent is what's in the stripe example
THe session object is created in this section here
var service = new SessionService();
Session session = service.Create(options);
Your code isn't the same as our example if the session object doesn't exist. I recommend you review this code here
https://docs.stripe.com/payments/accept-a-payment?platform=web&ui=embedded-form#create-checkout-session
The code in the Checkout subscription example is this:
var options = new Stripe.Checkout.SessionCreateOptions
{
Mode = "subscription",
LineItems = new List<Stripe.Checkout.SessionLineItemOptions>
{
new Stripe.Checkout.SessionLineItemOptions
{
Price = "{{PRICE_ID}}",
Quantity = 1,
},
},
UiMode = "embedded",
ReturnUrl = "https://example.com/checkout/return?session_id={CHECKOUT_SESSION_ID}",
};
var service = new Stripe.Checkout.SessionService();
service.Create(options);
And if you look at my code, all I did was update the price id and the return url. That's what Stripe's example is. The one you're citing is for Checkout Payments for a one-time purchase
In which doc? Do you have that link?
let me find it...brb
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
it's under the "Create A Session" section
That is not a code snippet that is designed to fit into an integration
It just provides an example of how to make the API call
I think part of the issue here is that there are no examples available that show how to do this using ASP.NET WebForms (not MVC or Core). Trying to make this work this way is tough
I recommend you just trying to declare the Session object as the value returned by the Checkout service
so you can manipulate it in your code
BTW, I see what you mean about the code and made the change, but that code is executing in the codebehind of the web page, so I can assign the session id to a public variable, but I don't know how to get that to the javascript code
Can you log the session object in the back end a see what it looks like?
I think you should still be able to use the return statement here
return Json(new {clientSecret = session.ClientSecret});
It's returning a valid session object (ID=cs_live_b1ZpZgkqdhEHPlaXV8KEJFtGSkFjp239RSZwSZg2DBbgdbl8opurDSdu1h_secret_fid2cGd2ZndsdXFsamtQa2x0cGBrYHZ2QGtkZ2lgYSc%2FcXdwYCkncGxIamFgJz8nYGhnYGFhYGEnKSdpZHxqcHFRfHVgJz8naHBpcWxabHFgaCcpJ3dgYWx3YGZxSmtGamh1aWBxbGprJz8nZGlyZHx2JyknZ2RmbmJ3anBrYUZqaWp3Jz8nJjA3MGMyYyd4JSUl). What I have to do is figure out how to get the value from the C# codebehind to the Javascript where it belongs. The Page_Load event can't "return" anything. All I can do is set a public variable that can be seen by the front end, but I don't know how to pass that value into the Javascript for use.
Actually, since the codebehind is ALREADY Creating a session, the Javascript code I have doesn't need to. All I need to do is pass the created sesison id to the javascript code calling the checkout
The JS was never creating a checkout session. It just mounts the session to the DOM
hmm...so once I have the clientsecret value in the codebehind, now I have to figure out how to get it to the checkout instance...
Okay I think you mean your back-end code (server-side) when you say "codebehind".
In that case, you are creating a Checkout Session and we can see the client_secret value in the ID. You need to get that string to your front-end and use it to initialize the embedded checkout in JS
I know not all our code is the same but I think you should still review the example we have here: https://docs.stripe.com/checkout/embedded/quickstart
Sure, but the problem is, Stripe deprecated the initialization method that let you pass in a clientsecret in favor an async fetch.
Hello
Taking over here..
This seems like a long running thread. Can you give me a quick summary of what you're stuck on?
So, I am trying to use an embedded Stripe checkout in an ASP.NET WebForms (NOT MVC or Core) application. I have a web page that is creating a Stripe Checkout Session in the code-behind, and somehow I have to figure out how to pass the clientSecret object back the the Javascript in the front-end in order to instantiate the checkout. So, I can't figure out how to get the created clientSecret to the initEmbeddedCheckout method in the front-end Javascript
I'm not very familiar with ASP.NET but it seems like you should look up documentation about how you can perform client-server communication using webforms.
Unfortunately, my team on discord can help with any issues you're having with Stripe SDKs.
Based on the brief convo above, it looks like your backend code is able to call Stripe's API
there's no documentation on this, because all their support has shifted to MVC and .NET Core
I see.. No one on my team would be familiar with this unfortunately. Maybe try find tutorials for a similar implementation and transplant some code in your app?
Yes, I am successfully communicating with Stripe. But I need to figure out how to call the checkout.initEmbeddedCheckout method and pass the clientSecret object to it. There are no tutorials or docs for this as far as I can find.
I am reaching out to Stripe's engineering teams to see if they can help. More than anything, it would be great of they could just give me access to their legacy documentation, which included support for WebForms coding. Thank you to all of you for trying though. I appreciate it.