#Valentino - Redirect to Checkout

1 messages ยท Page 1 of 1 (latest)

open seal
#

HI ๐Ÿ‘‹

bold plaza
#

Hi! yes it is

#

and I am using { loadStripe } from '@stripe/stripe-js' to instance the stripe const

open seal
#

Okay can you share the code where this is called?

bold plaza
#

yes

#

here, or should I make a repo in github?

open seal
#

You can just paste here between three ` marks to make a code block

bold plaza
#
  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()?

open seal
#

Okay so now that we have this reference, what is the redirect behavior that is not functioning as you expect?

bold plaza
#

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

open seal
#

Okay, what is the "first page" in this scenario? The Checkout interface?

bold plaza
#

yes

open seal
#

When you say "doesn't work" what do you mean? Do you get redirected to the page? Is the interface broken?

bold plaza
#

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.

open seal
#

Okay thank you. That screenshot helps. Can you share the Checkout session ID you see in the URL bar? Staring with cs_test_?

bold plaza
#

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

open seal
#

Okay so when do you get sent to the second Session?

bold plaza
#

never

#

I just searched in the logs the data and copy pasted the url it provides

open seal
#

Hmmm.. I as able to find the Checkout session from your first ID and it took me to the checkout session.

bold plaza
#

thats strange...

#

and it shows you the same info?

#

as the second picture?

open seal
#

Yup.

bold plaza
#

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?

open seal
#

Each Checkout Session has a unique ID and that is part of the URL

bold plaza
#

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?

open seal
#

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?

bold plaza
#

exactly

#

thats the first thing that I wrote haha

bold plaza
open seal
#

Sorry the wording was kind of confusing and I wasn't sure what we were talking about yet

bold plaza
#

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

bold plaza
#

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?

tulip valve
#

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

bold plaza
#

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!

tulip valve
#

Happy to help. We did adjust all of our docs samples to use the server-side redirect as opposed to redirectToCheckout