#Emily Marin - Checkout URL

1 messages · Page 1 of 1 (latest)

whole apex
#

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?

languid merlin
#
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);
   
});
whole apex
languid merlin
#

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.

wind gust
#

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?

languid merlin
#

No, the redirect is the part that doesn't work 🙂 I'm trying to redirect to that checkout url (second picture)

wind gust
#

Can I see you frontend code?

languid merlin
#

Well, the redirect will work if I pass it a valid url

wind gust
#

Can you open the browser console and see if there is any error?

languid merlin
wind gust
#

I see a undefined is passed to the URL, is this the correct route that your server expect?

languid merlin
#

The route I want to pass is the url I circled in pink

#

Not sure how to access that.

wind gust
#

I don't see the pink circle in the screenshot you posted earlier

languid merlin
#

This is the response body from the post request

#

I'm trying to access the url here.

wind gust
#

So after entering /us-central1/createCheckoutSession in the browser address bar, you get redirected to /us-central1/undefined ?

languid merlin
#

that's correct

#

it creates the session successfully, but does not direct me to the session.

wind gust
#

Got it, I think something is missing in your code. can you add await in this line
const session = await stripe.checkout.sessions.create({

languid merlin
#

IT WORKS

#

You are my hero. I've been struggling with this for days. I could cry tears of joy

#

Thank you so much ❤️

wind gust
#

No problem! I'm happy that the problem is resolved!