How to expire stripe paymentIntent?

Viewed 1366

I am implementing ecommerce functionality. I have a situation where I want to restore product back into stock when stripe paymentIntent is not confirmed for a long time (say 10 minutes). To go into detail what I am doing is that when customer goes to checkout I lock stock of the products in cart. Then I ran a cronjob to identify carts which are lying unused for more than 30 minutes and restore stock back into inventory. This is fine, but there might be a case where user is paying and cart might be restored, inorder to tackle this, when payment is initiated I change cart state to inProgress so that cronjob is not restoring this cart. But if user is initiating payment and never completes it then cart will never be restored. So I am looking for a way in which paymentIntent will be expired and I can restore this cart in stripe webhooks. Any other alternative is appreciated.

1 Answers

There’s no automatic way which Stripe can do this right now, unless you are eligible for the Checkout abandonment beta [0]. The only way to do that which I can think of is to cancel the PaymentIntent [1] if it is not in status succeeded, canceled or processing [2] after a period of time, and trigger the inventory release on the payment_intent.canceled event [3].

[0]https://stripe.com/docs/payments/checkout/abandoned-carts [1]https://stripe.com/docs/api/payment_intents/cancel [2]https://stripe.com/docs/api/payment_intents/object#payment_intent_object-status [3]https://stripe.com/docs/api/events/types#event_types-payment_intent.canceled

Related