Reputation: 1435
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
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
Reputation: 2204
There's no built in way to cancel all subscriptions. But you could do it this way:
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
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:
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