Prevent duplicate subscriptions with Stripe Checkout
Asked Answered
N

4

9

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.

Nephrolith answered 6/5, 2021 at 17:10 Comment(1)
Thanks for asking this! I never thought of this edge case but just threw in some logic to handle just incase. <3Antilogism
E
9

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.
Elitism answered 6/5, 2021 at 18:47 Comment(0)
D
1

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

Dennie answered 22/1 at 18:7 Comment(0)
C
0

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.

Catechol answered 31/7, 2023 at 1:30 Comment(1)
no, it doesnt and it shouldnt. This is a great feature which I useTanny
S
0

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.

Slit answered 18/6 at 7:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.