0
votes

I have a checkout flow in which a customer can apply a coupon code to their purchase. Each customer has a limited set of coupons they can apply to get some percentage off their price. When a customer applies the coupon, the application registers in the database an attempt to use such coupon.

I plan to use a stripe webhook to listen to cancellations and succesful payments and mark the coupon as unusable or usable again for future purchases for that specific customer. In the case where the payment intent was cancelled, then the coupon can be used again by the customer. This works if the customer completes the checkout flow and enters a credit card number.

However, the problem happens when the customer does not complete the whole checkout flow, and the coupon code was applied and the attempt was marked in the database.

My question is if stripe has any automatic cancellation policy for incomplete payment intents, such a scheduled cancellation after certain period of time after creation. I read somewhere that payment intents under a checkout session expire after 24 hours. But I could not find anywhere in the official docs if this is what really happens or if it applies to payment intents alone. That would be nice for me because I could use a webhook to handle that automatic cancellation.

If that is not the case, how would I be able to handle this situation? By the way, I am using my own customer and coupon system. Not integrating those with Stripe at the moment. Thanks for your help!

1

1 Answers

0
votes

Stripe does not have any automatic cancellation policy for incomplete payment intents. For example, I just checked my dashboard and I have a payment intent that's still marked as "Incomplete" that was initially created on December 17th, 2019.

One approach that you can take would be to only mark a coupon as redeemed if the given payment intent it was used on succeeded. You can listen for the payment_intent.succeeded webhook event and increment the associated coupon's redemption count in your database. With this flow you would need to track each time a coupon is applied to a payment intent, and manually cancel any incomplete payment intents that the coupon was applied to before.