Home > Enterprise >  How to use stripe checkout for first come, first served buying experience
How to use stripe checkout for first come, first served buying experience

Time:10-14

I'm trying to use Stripe checkout in a first-come, first-served buying process. Multiple buyers may be trying to buy the same item at the same time, and only the one who completes the stripe checkout process first should get it. At the moment, the stripe checkout session duration requires me to 'book' the stock item and only release them back into stock once the session duration expires (even if they close the tab).

Is there a way to set up Stripe Checkout in a way that would detect whether the item has already been purchased by another buyer (e.g. the stock is no longer available), and for example show an error when the user tries to pay?

If not, any suggestions as to alternative ways of implementing this functionality while still using Stripe?

CodePudding user response:

You can use the paymentIntent that allows you to confirm or reject the payment later. You can create the paymentIntent for all the customers are trying at the same time and next take the first one and confirm only this paymentIntent and reject the others

Read the Stripe documentation: Stripe | PaymentIntent

CodePudding user response:

You can listen for checkout.session.completed events and add some event handler logic to retrieve the Session object while expanding the line_items:

https://stripe.com/docs/payments/checkout/fulfill-orders https://stripe.com/docs/api/expanding_objects

This will allow you to inspect the price and product IDs for the completed Session. You could then have some logic to expire any other Checkout sessions so no other customers are able to go through the payment flow:

https://stripe.com/docs/payments/checkout/managing-limited-inventory https://stripe.com/docs/api/checkout/sessions/expire

  • Related