Marcos
Marcos

Reputation: 1435

How do you cancel a batch of Stripe Subscriptions?

Business went under, what do I do? The Dashboard doesn't let me cancel all subscriptions and schedules in a batch at once with a simple command.

Upvotes: 1

Views: 3095

Answers (3)

Frederik
Frederik

Reputation: 719

If you have a list of subscription IDs can also use the Stripe CLI to cancel them like this:

stripe subscriptions cancel <subscription-ID> --live

Or update them to cancel at the end of the current period:

stripe subscriptions update <subscription-ID> -d cancel_at_period_end=true --live

You might have to update your API key used by the CLI to update the "all Billing resources" resource type to "write" beforehand.

Upvotes: 0

soma
soma

Reputation: 2204

There's no built in way to cancel all subscriptions. But you could do it this way:

  1. List all subscriptions using this endpoint
  2. Then cancel each of the subscription using this endpoint

In Node.js it would look something like this:

const subscriptions = await stripe.subscriptions.list();
subscriptions.autoPagingEach(subscription => {
  await stripe.subscriptions.del(subscription.id);
});

Upvotes: 0

Marcos
Marcos

Reputation: 1435

I had to create what I call the "end of the world" script for when you need to cancel all your customers' subscriptions, or at least a fair number of them.

Steps:

  1. Go to https://dashboard.stripe.com/subscriptions
  2. Click Export (and filter according to your needs if you're lucky to keep a few customers)
  3. Copy and paste the subscription ids into this script or parse the ids from csv file into the variable
  4. Run it.
  5. Check https://dashboard.stripe.com/subscriptions again to make sure it's all gone
  6. Check https://dashboard.stripe.com/subscription_schedules in case you had schedules
  7. Check https://dashboard.stripe.com/invoices?closed=false&status=open in case you need to stop collection on any invoices

fml.js

const stripe = require('stripe')('your api key goes here');

const subscriptions = [
    // paste all subscriptions ids here or parse the array from the first column of the CSV file
];

async function cancelSubscription(s) {
    try {
        const deleted = await stripe.subscriptions.del(s);
        console.log(deleted.id);
    } catch (e) {
        console.log(e)
    }
}

function delay(t, val) {
    return new Promise(function(resolve) {
        setTimeout(function() {
            resolve(val);
        }, t);
    });
}

(async () => {
    for (const sub of subscriptions) {
        await cancelSubscription(sub)
        await delay(1000) // this delay prevents going over the API limit, you can decrease it
        // but you'll miss the opportunity to say goodbye to the ids rolling through your screen
    }
})()

Wish you all the best and may you never need to use this piece of code.

Upvotes: 3

Related Questions