Search code examples
node.jsstripe-paymentsnetlify

How do you reflect order confirmation data to the frontend when using stripe + netlify?


The setup:

/order has a button on it that once clicked, calls stripe.redirectToCheckout({...}), which redirects the browser to stripes payment page.

Stripe does its thing, and finally redirects to /success.

Heres my question: How would I 'reflect back' the customers order to them on the /success page?

It seems like there should be 2 options:

Option 1) /success somehow gets JSON data sent to it (I can not find documentation for how to do this but it seems the most natural way... maybe)

Option 2) On the backend, after stripe has confirmed the order, thats when I add/update the user data in the database. After they land back at /success, I grab that same data from the database and reflect it back to them using that.

Thoughts?


Solution

  • Pass in the session_id in the success_url and cancel_url, e.g. /success?session_id={CHECKOUT_SESSION_ID}`. When handling the routes, extract the query parameters and retrieve the Session by calling Stripe API https://stripe.com/docs/api/checkout/sessions/retrieve.

    If you have stored data in your database, I would also recommend adding relevant metadatas (https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-metadata) such as transaction id or user id so you can query your database.