Joseph
Joseph

Reputation: 2712

Cancelling a Stripe payment after it's processed

I'm integrating with the Stripe API following the instructions in their guide at https://stripe.com/docs/payments/quickstart using PHP as the backend.

Everything is working fine from beginning to end but I have a scenario that I want to support and I'm not sure how to go about it, or if it's even possible.

The scenario

The website is selling tickets to an event which may suddenly become fully booked. I can check for this at the point that the customer presses the pay button and then simply not let the Stripe process proceed if the event is fully booked. However, in some cases, customers will be redirected to 3D secure authentication by their card provider. They could take 5 seconds to complete 3D secure or, in some cases, they could take several minutes. During this time, it's possible that the event will become fully booked, but by that time Stripe will already have authorised the payment and the next thing that will happen is that the customer will be redirected to the return URL.

Obviously I can display a message at the return URL to tell the customer that the event is now fully booked and that they will be given a refund. I can even automate that refund. However, this means that Stripe will keep the transaction fees which is not ideal.

Looking at https://stripe.com/docs/api/payment_intents/cancel it seems as though there should be a way to cancel a payment that's been authorised but not "captured" yet. This would be a good solution as it would allow a split-second check at the point that Stripe finally authorises the payment where I could either cancel or capture the payment and then let the customer go to the return URL to see the result. And in the case of the payment being cancelled, no refund would be needed as an actual charge would never have occurred.

However, I can't see which part of the process detailed in the instructions to introduce this check as there isn't a "capture" stage mentioned.

Upvotes: 0

Views: 632

Answers (1)

Nolan H
Nolan H

Reputation: 7419

The best way to handle cases of volatile stock like this is using separate auth & capture by setting capture_method=manual when you create the Payment Intent (for payment methods that support manual capture). This allows you to complete the authentication/authorization flow but defer the capture, giving you a chance to re-check your stock availability prior to capturing payment. If stock is available, you reserve it for the customer and capture the payment. If stock is not available, you can then cancel as you mention.

Upvotes: 1

Related Questions