Prevent duplicate subscriptions with Stripe Checkout

Viewed 1289

Consider the following course of events:

  • A user selects one of multiple subscription options on my website and clicks the "pay" button.
  • They're redirected to the Stripe Checkout page but don't complete the payment yet.
  • They somehow manage to get back to the page where they select the subscription while keeping the Stripe Checkout page open. (I know this is somewhat contrived but technically possible.)
  • They choose a different subscription option and click on "pay" again.
  • A second checkout session is created and another Stripe Checkout page opens.
  • Now they complete payments on both checkout pages.

How can I prevent this? Is there a way to cancel a checkout session? When I create a checkout session for a subscription, I don't receive a payment intent that I could cancel. There also doesn't seem to be a way to cancel checkout sessions directly.

1 Answers

I don't know of a way to prevent the scenario you described as the customer in question is explicitly deciding to pay you twice for two different subscriptions.

That said, if your use case requires a customer to have only a single Subscription you could add logic on your end that would do the following:

  1. Set up a webhook endpoint to listen for customer.subscription.created events.
  2. Whenever a new Subscription is created list the Subscriptions belonging to the Customer.
  3. If the Customer has more than one active Subscription cancel the newest one(s) and refund the associated payments. You may also want to send the customer an email letting them know what happened.
Related