nwellnhof
nwellnhof

Reputation: 33618

Prevent duplicate subscriptions with Stripe Checkout

Consider the following course of events:

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.

Upvotes: 9

Views: 6630

Answers (4)

Janomine
Janomine

Reputation: 11

You can do the following before creating a new checkout session on your backend:

  1. Cancel any open checkout sessions by listing all checkout sessions for the specified customer and expiring them List all Checkout Sessions Cancel Checkout

  2. Cancel all pending subscriptions with state incomplete (They expire after 23 hours by default) List subscriptions Cancel subscription

  3. Use webhooks as described in previous answers to listen for duplicate subscription creation events and automatically cancel/refund, remind that this will trigger another cancel webhook event, which you maight have to deal with.

Upvotes: 1

Tristan
Tristan

Reputation: 519

Stripe as of 2024-01-22 has the ability in its Checkout product to limit customers to one subscription and if a customer clicks on a Checkout link, it'll redirect them to manage their existing subscription instead of buying another one.

It is a toggle you can set on Checkout or Payment Links settings.

Docs: https://stripe.com/docs/payments/checkout/limit-subscriptions

Upvotes: 2

phpwebdev
phpwebdev

Reputation: 103

Stripe should prevent multiple subscriptions to the same product, by the same customer by default. Instead, we will have to save the customer id from stripe and then use that to check if the user is already a subscriber.

Using the webhooks or manual lookups of the customer ID in stripes api is the only solution as of now.

Upvotes: 0

Justin Michael
Justin Michael

Reputation: 6460

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.

Upvotes: 9

Related Questions