#Adal-Checkout
1 messages ยท Page 1 of 1 (latest)
Hi! thanks for responding, yes, first and second screenshots are frontend and third is the API
Cool, can you do a console.log and see what does the fetch('/api/checkout_sessions') returns?
Ideally the fetch('/api/checkout_sessions') should return a session object, and so that you can call window.open(session.url) to open the checkout page.
Alternatively you can open devtool and check the response from your server on the network tab.
humm.. it says "Failed to load response data: No content available because this request was redirected"
on the response inside network tab
Ah, I see, you return 302 in your backend.
In the headers I get a 303 status code "see other"
can you send me the backend end?
It's the boilerplate from the code example in the docs ๐ I just changed the price part to get the ID from the item from the front end
Got it, if you are returning 303 from backend, you need to use form submit.
And in my console I get my console logs
Oooooh yeah yeah, that's what the example is using
Yeah, can you check to form and try again?
But I didn't think it was suitable to my case so I used a button ๐
The boiler plate with the form works, but I have to hardcode in the backend the price id
If you don't want to use form, you can return a 200 with a session object
That's why I switched to a button, so I could use the onClick function which grabs the price id from the specific product
Ok ok, I'll try that!
then use window.open(session.url) to open the checkout page at your frontend js
Ok let me test that
wait, so do I just change the 303 for 200? and then window.open(session.url);, or do I switch it to res.status and then the window.open? ๐ค
You can replace res.redirect() with res.send(session) to return a 200 with session object to client end.
huummm
if I change the previous to res.send(session) I get my console logs correctly, but still don't redirect, in the network tab I can see the payload correctly as my price_id and from response I get
an object with a lot of stripe info
You need to add some code in your button handling, something like
const session = await fetch('/api/checkout_sessions'...
window.open(session.url);
Hmm I think I'm close, it's weird because
if I do this
It finally opens the stripe site, the bad thing is that it tries to open as a pop up window and can be blocked... and also I find worry that since I didn't access it using the session.url I won't be able to redirect..
Try window.open(session.url, '_self');
Nice! Happy to know that your problem is resolved!
The function is firing at render time tho ๐ but that must be me being dumb having problems with syntax somewhere lol, but looks like the redirecting problem is solved
Do you think there won't be any problem for not using the "session" thing?
What do you mean not using the session thing? You are using Checkout Session API.
I mean haha, because when I tried to redirect to data.session.url I gont undefined, but it worked as data.url since I inspected in the console, I guess I just renamed the whole object as data
That's just a variable name, you can name it whatever you want.
Don't worry! I'm happy to help ๐