#Preet
1 messages ยท Page 1 of 1 (latest)
Hello ๐
Just to clarify, you're seeing this client-side correct? When you try to load checkout?
yes
How exactly are you redirecting to checkout?
is the error printing out when you log res or are you seeing a response object being printed where there's a checkout URL?
You can try setting the Checkout session URL to window.location.href
Typically, you'd want to handle the redirect using a form as shown in our docs example as the <form> can follow server redirect
https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=checkout#redirect-customers
If you'd rather use axios then you'd want to set the URL to the window directly as I mentioned above
i.e.
window.location.href = CHECKOUT_URL_HERE
let me know if that helps @quartz stag
I think I found the issue.
Cors issue is being thrown at this request
any idea why?
that's because axios.post can't follow the redirect your server is trying to make
I haven't used axios enough but there might be a way to tell it to follow the server side redirect ๐
The easiest way would be to respond with session.url from your server side and then tell your client-side code to go to that URL
so instead of res.redirect(...)
You can do
res.json({ url: session.url })
and on client side,
const data = res.json();
window.location.href = data.url
okay I think it will work now, thanks !
Hey Hanzo, I have another doubt.
This is the url it redirects to after successful payment
As per my applications flow, I want to run some logic once the payment is done, for example like updating database, etc. Someone advised me about using webhooks but I dont know how to start
Hi, stepping in -- please give me some time to catch up here
okay
I have added this webhook api in my server. The only doubt is how to call this api once the payment is done by the user
Can you clarify what you mean with 'how to call this api once the payment is done by the user'?
Like are you trying to retrieve an object so you can attain details to update your database? if so, you can retrieve the Checkout Session: https://stripe.com/docs/api/checkout/sessions/retrieve after you get the session id
yes so basically once the user let's say pays the amount and gets redirected to whatever the success URL is, in the meantime I want that particular payment info to be added to my database plus some other logic to run.
Yeap, you can retrieve the object id and expand: https://stripe.com/docs/expand#multiple-levels to get the payment method details.
I am still a bit confused. So I create the checkout object and send it to the client side. The client side then redirects the user to the checkout URL it got from the object.
Where does this step of retrieving the checkout object comes into the picture? Do I make a separate API for it? Where does its code go?
You'd need to make a separate API call to retrieve this data on the server side, after the session is complete
but how would I know if the session is complete? Arent we doing this to check if the session is complete?
After you get the session webhook event that the session is complete. After the session is complete, you want to dave the payment details into your database no? If not, can you please help me better understand what you're ultimately trying to achieve?
yes, that's what I want to do. So I will have to call the webhook api in order to check if the session is completed right?
Yeap, you can listen to https://stripe.com/docs/api/events/types#event_types-checkout.session.completed and retrieve that information by calling the API.
is there a way other than using stripe cli to create a webhook point where the events could get transferred to?
locally
you can just make API calls and as long as you're listening to the events, and set up an webhook endpoint in the Dashboard: https://dashboard.stripe.com/test/webhooks and look at events in the Dashboard.
I tried adding my localhost:3001/webhook as the webhook URL from the dashboard but it only accepts public URLs. There's an option for testing in a local environment but I will have to use stripe cli to create a webhook.