#daniel-a_error

1 messages ยท Page 1 of 1 (latest)

heavy lodgeBOT
#

๐Ÿ‘‹ 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.

gray gyro
#

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.

terse jay
#

Hi ๐Ÿ‘‹

So you are trying to use Stripe embedded checkout and that is where the error is occurring?

#

Can you share a session ID?

gray gyro
#

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.

terse jay
#

this is a screenshot, which is less useful to me.

#

Can you copy/paste the ID value as text here?

gray gyro
#

cs_live_b1FxPCRo79oircPe70a17gXVOcKrEvvjHTGUFW1CF654Q5DICp8fjMeAZt

terse jay
#

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?

gray gyro
#

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.

terse jay
#

You should be able to await the response and log the value that is returned

#

Checking that would be the recommended next step

gray gyro
#

the log comes back with [object Object]. No way to know what's in it though

terse jay
#

What is the exact log line you are calling?

gray gyro
#

I am just doing 'alert(checkout);' in the javascript file in the line right above the checkout.mount call

terse jay
#

Well yeah, that won't work

#
  1. you need to extract the actual client_secret string
#
  1. Log it to the Console
gray gyro
#

So if I use console.log(checkout.client_secret) then it says it's undefined.

terse jay
#

Okay so step back

#

do console.log(checkout) to see what that value is

gray gyro
#

says the value is [object Object]

terse jay
#

Try console.log(JSON.stringify(checkout))

#

which will write the object to a string and log that

gray gyro
#

Says TypeError: Converting circular structure to JSON

terse jay
#

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});
gray gyro
#

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

terse jay
#

THe session object is created in this section here

var service = new SessionService();
Session session = service.Create(options);
gray gyro
#

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);

terse jay
#

No it isn't. the last line is incorrect

#

Session session = service.Create(options);

gray gyro
#

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

terse jay
#

In which doc? Do you have that link?

gray gyro
#

let me find it...brb

terse jay
#

That is the API reference doc

#

I am asking for the integration doc you are following

gray gyro
#

it's under the "Create A Session" section

terse jay
#

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

gray gyro
#

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

terse jay
#

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

gray gyro
#

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

terse jay
#

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});
gray gyro
#

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.

terse jay
#

OK! That's progress

#

The value in ID is what you need to load

gray gyro
#

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

terse jay
#

The JS was never creating a checkout session. It just mounts the session to the DOM

heavy lodgeBOT
gray gyro
#

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...

terse jay
#

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

gray gyro
#

Sure, but the problem is, Stripe deprecated the initialization method that let you pass in a clientsecret in favor an async fetch.

twilit mountain
#

Hello
Taking over here..
This seems like a long running thread. Can you give me a quick summary of what you're stuck on?

gray gyro
#

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

twilit mountain
#

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

gray gyro
#

there's no documentation on this, because all their support has shifted to MVC and .NET Core

twilit mountain
#

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?

gray gyro
#

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.