#netdesignr-something-went-wrong
1 messages · Page 1 of 1 (latest)
Do you have the id of a Checkout Session that this happened for?
And this is happening consistently when you direct people to your Checkout page?
To mention that this is a work in progress application and it's currently on my localhost
I've stopped working on it for about 3 months and now when I got back to it I'm seeing this error
The session id looks like this -> cs_test_a1qMwOJGfjozSKqMCit4kZeLIoBiwPjktSkVZQ687Wz7oQ2B278BCVTANt#fidkdWxOYHwnPydwa2FgY2xrYGEnKSdobGF2Jz9%2BJ2JwbGEnPycyNjJgMTVhMCgxZ2AwKDEzZDUoZD1jZyg0ZDA2YDYyYWY1ZDBjM2E9NjYnKSdocGxhJz8nZzZhZDFjMDIoZDc1NCgxMDY9KD1gYWQoZ2E2MjA0MDw2ZDYzZ2dkN2cwJykndmxhJz8nN2M8Nz0wZGQoMT0wNygxND0yKGQ3NTMoNjQ3ZzUwPDRkNzBmNjYwPTUzJ3gpJ2dgcWR2Jz9eWCknaWR8anBxUXx1YCc%2FJ3Zsa2JpYFpscWBoJyknd2BjYHd3YHdKd2xibGsnPydtcXF1PyoqaWpmZGltanZxPzY1NTUneCUl
Inside dashboard.stripe.com / logs / It comes back with a status 200 OK
Thank you. Checking that out
@turbid rapids 99% of the time this is because you redirect with the wrong API key
So you create the Session on account A with its secret key, but client-side you redirect to Checkout with the Publishable API key from account B
If you look at that request creation where you see the 200, there's a URL in it to redirect, and that one works fine. So check your client-side code where you call redirectToCheckout and confirm that you have initialized Stripe.js with the correct publishable key
Sure, checking it now
To confirm, I'm using a Secret Key in Test Mode
yes that's not a Live/Test issue
So presumably I'm using the wrong key? When I used the Test publishable API key I was getting -> This API call cannot be made with a publishable API key. Please use a secret API key
there are 2 separate keys, and 2 separate parts of your code
one part creates the Session. That's something your server-side code does with stripe-node with the secret key that works
one other part, client-side, is likely calling redirectToCheckout() in your Javascript code in the browser. That code loads Stripe.js var stripe = Stripe('pk_test_123');
That code uses the Publishable key possibly from a different account
That's it @devout panther! I've redone .env.local and didn't realise I haven't re-set the NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY_TEST value in there and the Stripe API Key for the client side was missing. Interesting that I had no code/logs complains about it.
Thank you and consider this thread as solved.
@turbid rapids now
while I have you! Redirecting client-side is more complex and error prone
you can redirect directly from the server instead if you prefer since the Session has the exact url in the response
you don't have to, what you do works totally fine if you don't mixup the keys, but that would have saved you some troubles 🙂
Ah..sorry to be a pain
Is there any way I can define a trial period?
const session = await stripe.checkout.sessions.create({ mode: 'subscription', payment_method_types: ['card'], line_items: [ { price: subscriptionType, quantity, }, ], success_url: ${req.headers.origin}/payment/result?session_id={CHECKOUT_SESSION_ID}, cancel_url: ${req.headers.origin}/, });
no pain at all, we're here to help!
There's the subscription_data parameter for subscription-specific parameters. You want https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data-trial_period_days
Perfect, is working like a charm!