Search code examples
stripe-paymentspayment-gatewaysubscriptionbillingcancellation

How can I prevent customers from canceling their monthly subscriptions on Stripe until three months have passed?


I am implementing a subscription service using Stripe, and I want to enforce a policy where customers cannot cancel their monthly subscriptions until at least three months have passed since the subscription start date. How can I achieve this using Stripe API or any other available methods ? I want to ensure that customers adhere to this policy to reduce churn and maximize revenue. Any insights or code examples would be greatly appreciated.

i am creating a portal session in node js

  const session = await stripe.billingPortal.sessions.create({
      customer: customer.stripeCustomerId,
      return_url: 'https://my-website.com',
  });

I have created a customer poral session now i want my customers cannot cancel their monthly subscriptions until at least three months have passed since the subscription start date.


Solution

  • Create two Billing Portal Configurations: one that allows cancellation, and one that doesn't using this parameter.

    Then, depending on how long the user was subscribed, create a Billing Portal with the correct configuration. Something like this:

    const session = await stripe.billingPortal.sessions.create({
      customer: 'cus_xxx',
      return_url: 'https://example.com/account',
      configuration: canCancel ? 'bpc_xx1' : 'bpc_xx2', 
    });