#Emily Marin - Checkout URL
1 messages · Page 1 of 1 (latest)
Hello! Generally speaking you usually wouldn't go from a Payment Intent to a Checkout Session URL. Can you tell me what you're trying to accomplish so I can recommend the best approach?
exports.createCheckoutSession = functions.https.onRequest(async (request, response) => {
const session = stripe.checkout.sessions.create({
line_items:[
{
// Provide the exact Price ID (for example, pr_1234) of the product you want to sell
price: 'price_1LKSC3Pe3Sdo1GEV8xfUw111',
quantity: 1,
},
{price: 'price_1LIkRZPe3Sdo1GEVwR48UWAa',
quantity: 1,}
],
mode: 'payment',
success_url:`http://google.com`,
cancel_url: `http://facebook.com`
})
response.redirect(303, session.url);
});
You can list the Checkout Session associated with a given PaymentIntent, but there's probably a better way to approach this: https://stripe.com/docs/api/checkout/sessions/list#list_checkout_sessions-payment_intent
Sorry, maybe I'm approaching the question wrong//phrasing incorrectly.
When I run that code^^ in my stripe dashboard logs it shows that I've successfully created a Checkout Session {attached}, and the response body has a URL parameter {attached}. I'm trying to navigate to redirect to that url.
When I copy and paste that url into my browser, it takes me to the checkout session. So I know it works, and I know it's the url I'm attempting to redirect to. I'm just doing it incorrectly somehow.
Hi @languid merlin I'm taking over this thread, give me a sec to catch up the chat history.
I see you are doing a 303 redirect after creating the checkout session. Is this redirect working in your webpage?
No, the redirect is the part that doesn't work 🙂 I'm trying to redirect to that checkout url (second picture)
Can I see you frontend code?
Well, the redirect will work if I pass it a valid url
Can you open the browser console and see if there is any error?
I see a undefined is passed to the URL, is this the correct route that your server expect?
The route I want to pass is the url I circled in pink
Not sure how to access that.
I don't see the pink circle in the screenshot you posted earlier
This is the response body from the post request
I'm trying to access the url here.
So after entering /us-central1/createCheckoutSession in the browser address bar, you get redirected to /us-central1/undefined ?
that's correct
it creates the session successfully, but does not direct me to the session.
Got it, I think something is missing in your code. can you add await in this line
const session = await stripe.checkout.sessions.create({
IT WORKS
You are my hero. I've been struggling with this for days. I could cry tears of joy
Thank you so much ❤️
No problem! I'm happy that the problem is resolved!