Django.fun

Create complex order with Stripe payment

I am trying to allow my users to pay for their booking (for an event) on my website using Stripe. I've got most of the processing working well but I don't know how to connect the response I get from Stripe which indicates that the payment has been successful to my database so that it knows all the details required to make the booking.

In the standard situation of "buying X number of products", I know that I can create an order on the server which contains those details. Then I can put that order ID into the Stripe request and I can use that when the payment is successful to go and fulfil that order.

But in my case, I have to accept a load more information than that. Each booking can have multiple attendees attached to it - each attendee will have a name and load more information about them which needs to be used when the booking is created.

Is the only way to do this to add ALL of this attendee information in to the request to Stripe so that it can be used when the payment succeeds? Or is there another way?

If it helps to answer this question, I'm using Django on the backend.

Answers: 1

Answered by soma, Nov. 25, 2021, 5:25 p.m.

The main way to achieve this is to:

  1. Store the information related to the order in your own database with the corresponding payment intent ID (or checkout session ID).
  2. Listen to the webhook event payment_intent.succeeded (or checkout.session.completed) to know when the payment is successful.
  3. In the webhook event, get the payment ID with event.data.object.id and use that to look into your database to retrieve the information needed to fulfill the order.

You can learn more on how to fulfill orders in the Stripe documentation here.

Another option would be to use the metadata field of your payment intent (or checkout session) to directly store all the information related to the order. But I wouldn’t recommend this since it has some limitations (number of keys, length of values, etc.).