[Answered ]-Retrieve stripe session id at success page

1👍

When using the prebuilt checkout page, you provide Stripe with the success url to send the user to when they successfully complete a payment. This is done like so:

checkout_session = stripe.checkout.Session.create(
                        line_items=[{'price': price, 'quantity': 1}],
                        payment_method_types=['card'],
                        mode='payment',
                        success_url="http://yoursite.com/order/success?session_id={CHECKOUT_SESSION_ID}"
                        cancel_url=domain + cancelURL,
                    )

return redirect(checkout_session.url)

This will create a Stripe checkout session and send the user to it.
Once the user successfully pays, Stripe will send them to the success_url you provided and put in the correct checkout session id.

You will have to use webhooks to get the data you want, save it to your database, and then query the database in the success page view. Getting the checkout session id from the success page URL will depend on if you are using a GET like in the example above or as part of the URL like https://yoursite.com/order/12345. If you use the GET method, see here for more info.

Leave a comment