#yodasgerbil - Checkout Redirect

1 messages · Page 1 of 1 (latest)

lofty spire
#

Hello! Can you provide more details about what you need help with specifically?

turbid kernel
#

Thanks

#

I am able to create the session

#

exports.handler = async (event) => {
const body = JSON.parse(event.body);
const session = await stripe.checkout.sessions.create({
success_url: 'http://localhost:8888/thank-you',
cancel_url: 'http://localhost:8888/404',
payment_method_types: ['card'],
line_items: body,
mode: 'payment',
});

#

but not sure how to call the stripe checkout page with the created session id

lofty spire
#

After that code runs session.url should contain the link you redirect your customer to.

turbid kernel
#

right, I see the url in the returned session.

#

do I then call the redirectToCheckout function like this?

#

.then(async response => {
const { id } = await response.json()
const { error } = await stripe.redirectToCheckout({ sessionId: id })
alert(error.message)
})
.catch(err => alert(err.message))

lofty spire
#

No, you don't need to call redirectToCheckout at all if you're using the URL from the Checkout Session.

#

Your frontend code would get the URL and send your customer to it.

#

So the steps would be:

  1. Send session.url to your frontend code
  2. Send your customer to that URL