Reputation: 33618
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
Reputation: 11
You can do the following before creating a new checkout session on your backend:
Cancel any open checkout sessions by listing all checkout sessions for the specified customer and expiring them List all Checkout Sessions Cancel Checkout
Cancel all pending subscriptions with state incomplete (They expire after 23 hours by default) List subscriptions Cancel subscription
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
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
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
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:
customer.subscription.created
events.Upvotes: 9