#Valentino - Redirect to Checkout
1 messages ยท Page 1 of 1 (latest)
HI ๐
Just double checking, you are referencing this function, correct?
https://stripe.com/docs/js/checkout/redirect_to_checkout
Hi! yes it is
and I am using { loadStripe } from '@stripe/stripe-js' to instance the stripe const
Okay can you share the code where this is called?
You can just paste here between three ` marks to make a code block
const handleCheckout = async () => {
const stripe = await getStripe();
const response = await fetch('/api/stripe', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(cartItems),
});
if(response.statusCode === 500) return;
const data = await response.json();
toast.loading('Redirecting...');
stripe.redirectToCheckout({ sessionId: data.id });
}
do you need to see the body of the request? or the GetStripe()?
Okay so now that we have this reference, what is the redirect behavior that is not functioning as you expect?
First, the page dosnt work
it gives the error:
Something went wrong
You might be having a network connection problem, the link might be expired, or the payment provider cannot be reached at the moment.
Second, the url that I get redirected to is not the same as the url that comes in the body of the response
it is simmilar though
Okay, what is the "first page" in this scenario? The Checkout interface?
yes
When you say "doesn't work" what do you mean? Do you get redirected to the page? Is the interface broken?
Maybe I am not being clear. As I already wrote, I am getting redirected to an url shich should be give me the checkout interface, but it only shows me an error.
Okay thank you. That screenshot helps. Can you share the Checkout session ID you see in the URL bar? Staring with cs_test_?
cs_test_a1HstYQ4cyOtVWb7fqsyMbmPjMPP1D1HajrqOr6RNvfJWReARmrcLXu6j7#fidkdWxOYHwnPydwa2FgY2xrYGEnKSdobGF2Jz9%2BJ2JwbGEnPydmMTQ1MGc2NShhPTJgKDFnZDEoPTJgYygxYDw8YDU1NDY3PTNhYT08Z2MnKSdocGxhJz8nMTc8PTw1MTAoPTcyMSgxNzA9KGc3NDAoYT1hPGEwNTExNWYwMzwyYDRjJykndmxhJz8nNjwyZjFmYTIoYzVgNCgxMmFhKGQwNmAoM2c1PGc2Yz0wMzBjMmA9NmE8J3gpJ2dgcWR2Jz9eWCknaWR8anBxUXx1YCc%2FJ3Zsa2JpYFpscWBoJyknd2BjYHd3YHdKd2xibGsnPydtcXF1PyoqaWpmZGltanZxPzY1NTUneCUl
.
and this is the one that come in the response:
cs_test_a1HstYQ4cyOtVWb7fqsyMbmPjMPP1D1HajrqOr6RNvfJWReARmrcLXu6j7#fidkdWxOYHwnPyd1blpxYHZxWjA0SWQ2fFZGQFR%2FZzA1ZnBtNUc1PFJIRF0zf1I1bV9LQVNXbGNpdEc2Zn1nMHxVM0tNRFNUQGpXZl8wTH92V3NuTWJtY09Cf2Mxb05OaUtnfWZLfzN8TGA2NTVXfHJmZ3RPdicpJ2N3amhWYHdzYHcnP3F3cGApJ2lkfGpwcVF8dWAnPyd2bGtiaWBabHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic%2FcXdwYHgl
wich does show me the interface
Okay so when do you get sent to the second Session?
Hmmm.. I as able to find the Checkout session from your first ID and it took me to the checkout session.
Yup.
I am now sending both links to a friend to see if maybe it has something to do with my pc
but why are the 2 url different?
Each Checkout Session has a unique ID and that is part of the URL
the unique ID would be this one cs_test_a1HstYQ4cyOtVWb7fqsyMbmPjMPP1D1HajrqOr6RNvfJWReARmrcLXu6j7
but why is the url that I am being redirected to different from the one provided in the response data?
You mean the URL you are seeing in the record for that ID does not match the URL you are being redirected to when calling redirectToCheckout?
you can see both them here. They are different urls
Sorry the wording was kind of confusing and I wasn't sure what we were talking about yet
I sent both url to a friend, and in the first one (the one that I am being redirected to) he gets the same error, and in the second one (the one that I find in the logs) he can see the checkout interface
So in summary, the url that stripe.redirectToCheckout() redirects me to, is not the same url that I find in the Records. Any idea why this might be happening?
๐ stepping in as Snufkin had to step away
Overall redirectToCheckout is not recommended. You should be redirecting from your Server.
Also, there is no reason you should ever grab the URL that redirectToCheckout is providing. You should access the Session URL directly.
Lastly, if you are going to be providing a URL to a customer, I'd recommend Payment Links instead here
well that was quite easy and straightforward haha
I think if thats the case, you should add somewhere in the docs, that redirectToCheckout is deprecated
with you I mean Stripe of course
Thanks for the Help!
Happy to help. We did adjust all of our docs samples to use the server-side redirect as opposed to redirectToCheckout