npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stripe-migrate

v1.0.15

Published

A Node-based CLI tool to migrate content from between Stripe accounts.

Downloads

7

Readme

stripe-migrate

A Node-based CLI tool to migrate content from between Stripe accounts. Implements some of the checklist for recreating settings in a new Stripe account.

Installation

npm install -g stripe-migrate

Usage

Before using this CLI, ensure you use the Stripe CLI to copy PAN data across Stripe accounts. This copies Customers, Cards, Sources, Payment Methods and Bank Accounts, preserving the original Customer IDs. You can learn more about that here.

Next up, run this CLI to migrate the rest of your data. It will migrate your Products, Plans, Coupons, Subscriptions and Webhooks with maximum consistency.

stripe-migrate webhooks --from sk_test_123 --to sk_test_456
stripe-migrate products --from sk_test_123 --to sk_test_456
stripe-migrate plans --from sk_test_123 --to sk_test_456
stripe-migrate coupons --from sk_test_123 --to sk_test_456
stripe-migrate subscriptions --from sk_test_123 --to sk_test_456

You can also do a dry run of subscriptions, which anonymises and mocks 10 subscribed customers from your old account for testing. This is useful if you're running on a Test Mode account as your destination.

stripe-migrate subscriptions --from sk_test_123 --to sk_test_456 --dry-run

Additionally, you can pass in a list of customer IDs to migrate subscriptions for. This works with --dry-run too.

stripe-migrate subscriptions --from sk_test_123 --to sk_test_456 --customers cus_123,cus_456

Once your account has been migrated, simply update your API keys and redeploy your app.

Webhook, Product, Plan and Coupon migrations check for existing matching data and skips it if required. This means you can run it multiple times to ensure everything is migrated.

Notes

I highly recommend testing this with a Test Mode account first as you can delete all test data and start again. Once you're happy with the results, you can run it against your Live Mode account. Also, this tool does not migrate anything not mentioned above. I take no responsibility for any data loss or corruption.

Known Issues

  • Stripe rate limits API requests to 100 per second. This tool does not currently handle this, so you may need to run it multiple times to migrate all your data.
  • Can't migrate overdue subscriptions. This is because the Stripe API doesn't allow you to create a subscription with a past due date. You'll need to manually deal with these.
  • Nothing to do with this repo, but I noticed Stripe's PAN copy tool doesn't capture Link payment methods.
  • When migrating products, prices have an unset tax behaviour. Needs fixing.

Other

To cancel all the subscriptions in your old account, run this:

import Stripe from 'stripe';

const stripe = new Stripe('[your secret key]', {
  apiVersion: '2022-11-15',
  telemetry: false,
});

export const fetchSubscriptions = async (stripe: Stripe) => {
  const subscriptions = [];

  let startingAfter: Stripe.Subscription['id'] = '';
  let hasMoreSubscriptions: boolean = true;

  while (hasMoreSubscriptions) {
    const listParams: Stripe.SubscriptionListParams = {
      limit: 100,
    };

    if (startingAfter) {
      listParams.starting_after = startingAfter;
    }

    const response = await stripe.subscriptions.list(listParams);

    if (response.data.length > 0) {
      subscriptions.push(...response.data);
      startingAfter = response.data[response.data.length - 1].id;
    } else {
      hasMoreSubscriptions = false;
    }
  }

  return subscriptions;
};

const main = async () => {
  const subscriptions = await fetchSubscriptions(stripe);

  const promises = subscriptions.map(async (subscription) => {
    await stripe.subscriptions.del(subscription.id);
  });

  await Promise.all(promises);

  console.log('done');
};

main();