Does Stripe Checkout V3 provide some sort of automatic cancellation of 'Incomplete' payment intents?

Viewed 1169

I am currently migrating a number of my clients from Stripe's old checkout window to the latest version of the Stripe checkout window to get it SCA ready. I have migrated the majority of my clients but one particular client tracks stock levels on server side. This was fine with the previous Stripe checkout window because my application would simply update the stock level of an item when the /charge succeeded with Stripe.

Now, because of V3 of the checkout, I have to create a Checkout Session before the end customer has paid for the item. At this point I then update the stock level of an item and if purchased that is fine. If they cancel the payment then I can replenish the stock level and that works fine too. My problem comes when a customer doesn't cancel the payment but instead exits the checkout window, or leaves it open in their browser without completing it. This leaves the Payment Intent 'Incomplete' on my Stripe dashboard but never triggers the stock replenishment function because I haven't received a payment intent cancellation. Is there any way round this? With a maximum time before an incomplete payment is automatically cancelled perhaps?

Any help would be greatly appreciated. Thanks again

2 Answers

If the customer leaves the CheckoutSession incomplete, it will expire and cancel the PaymentIntent automatically after 24 hours. If you don't want to wait that long, you'd likely want to use the Stripe API to poll for PaymentIntents that are older than a certain number of minutes and cancel incomplete ones manually.

As the answer before rightfully mentions, your PaymentIntent will be canceled automatically after 24 hours. This is because it's the default expiration time for a session.

However, it's not correct that would be able to cancel a PaymentIntent that has a checkout session attached to it:

stripe.com/docs/api/payment_intents/cancel

"You cannot cancel the PaymentIntent for a Checkout Session. Expire the Checkout Session instead"

You can trigger the expiration of the checkout session manually:

https://stripe.com/docs/api/checkout/sessions/expire

This will immediately expire the session and immediately cancel the payment intent.

Related