Skip to content

Instantly share code, notes, and snippets.

@sarthaktexas
Created December 1, 2020 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sarthaktexas/e6176c65db856d217ddd305a08cccdeb to your computer and use it in GitHub Desktop.
Save sarthaktexas/e6176c65db856d217ddd305a08cccdeb to your computer and use it in GitHub Desktop.
This script updates prices for up to 100 customers at a time. There IS manual config to do after running.
const stripe = require('stripe')('put your stripe secret key here');
const stripeFunction = async () => {
const subscriptions = await stripe.subscriptions.list({
limit: 100, // The max limit is 100, so you can do 100 at a time; change to whatever number you need to change
price: 'replace this with your price id' // This is the price id you want to replace
});
const count = subscriptions.data.length; // this is an optional line, just counts how many customers the Stripe API returns
subscriptions.data.forEach(async (data) => {
console.log( // Log update subscription object
await stripe.subscriptions.update(
data.id, {
cancel_at: 1606888800, // REPLACE THIS: Unix Timestamp (Epoch Time) on when to "cancel" it.
proration_behavior: 'create_prorations', // To prorate, or to not; replace with 'none' if you don't want proration
items: [{
id: data.items.data[0].id,
price: 'price_1HtRZ1D9X4XcXS1qi1lVnAC0' // Price ID you want to change it to
}]
})
);
});
console.log(count); // Logs the number of users returned; intialized on line 8
}
stripeFunction();
// IMPORTANT: You will need to manually click "Don't Cancel" in the Stripe console for each user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment