Connect your Stripe account
Ledger has to work in the Stripe account your subscriptions live in. In Settings › Stripe, connect that account: sign in with Stripe and pick it, or paste its secret key (sk_test_… in Sandbox, sk_live_… in Live). Check that the webhook shows Receiving: every renewal’s credits arrive through it.
Try the whole migration in Sandbox first, with test-mode copies of a few customers.
Run one command
From your app’s repo, with a Sandbox API key inLEDGER_API_KEY (or saved with ledger login):
- Proposes a catalog. One paid plan for each monthly USD Price your customers are on, named after its Product and priced like it. It asks each new plan’s monthly credits, and a feature with its credit cost if your config has none. A plan already in your config keeps its credits.
- Shows a report. Each plan, each customer it will import with their next renewal date, and each subscription it will skip, with the reason (see what can be imported).
- Asks before changing anything. Then it writes the plans to your config (
ledger.config.tsorledger.catalog.json; a new one isledger.catalog.json), publishes the catalog, and imports each customer, one progress line each. - Ends with a summary. Imported, already imported, skipped by reason, failed, and the range of next renewals.
Safe to rerun. Every step is idempotent. Progress and your answers are saved in
.ledger/migrate-stripe.sandbox.json (gitignored), so after a failure or an outage you run the same command again: it asks nothing, skips the customers already imported, and retries the rest. It exits 1 when any customer failed.
Each customer starts the current period with the plan’s full credits, coupons and trials included. A coupon on the subscription imports with it and keeps discounting renewals, which still grant in full. A customer whose latest invoice was credited or refunded, or paid partly from a customer balance, starts with 0, and their next paid renewal grants the plan’s credits. To carry over what they’ve already used, see Other ways.
Other ways
ledger migrate stripe is the recommended way to migrate. To script it yourself, for example to carry over usage with startingBalance, the command is built on calls you can make directly: Preview a Stripe migration (client.previewStripeMigration()) returns the same report as JSON, then for each customer create them, link their Stripe customer and import their subscription onto a plan with the same monthly price. Every call is safe to repeat.
The onboarding skill runs the command for you when it finds Stripe subscriptions in your app.
Customers on a free plan
Create customers on a free plan and attach the free plan. Link their Stripe customer too, so a later upgrade uses the card they already saved.What changes in Stripe
Ledger changes two things in your Stripe account:- Metadata. The customer and subscription get
ledger_organization_idandledger_env, and the customer also getsledger_customer_id. Your own metadata keys stay as they are. - The subscription’s Price. Its item moves from your Price to the Ledger plan’s Price, which has the same amount, with no proration. Nothing is charged, no invoice is created (a trialing subscription gets a $0 one), and the renewal date stays the same. From the next renewal on, the invoice line shows the Ledger plan’s name.
Which subscriptions can be imported
Ledger imports active subscriptions, subscriptions set to cancel at the period end (the plan ends when Stripe ends the subscription), and trialing subscriptions (the trial becomes the plan’s first period, with its credits). Ledger checks each subscription before changing it. The command reports any subscription that needs attention as skipped, with the reason, and leaves it as it is:
Fix the cause in Stripe and run the command again; it picks up the newly importable customers.
The import moves each flat monthly subscription onto a monthly Ledger plan. Customers on yearly, seat or usage-priced Stripe subscriptions keep billing in Stripe as before, and new annual and per-seat customers subscribe through Ledger.
Live
Migration works the same way in Live, with a Live API key and your live Stripe account connected:ledger migrate stripe --live. It works before you choose Go to production, because it starts no charge: your customers keep paying what they already paid, on the same dates. A new charge through Ledger, such as an upgrade, starts once Live is turned on.
See Import a Stripe subscription and Link a Stripe customer for every field and error.
Rules
- The import takes a subscription with one flat monthly USD price at quantity one; others are skipped with the reason in the table above.
- Import brings in one Stripe subscription per customer. Consolidate a customer’s Stripe subscriptions before importing.
- While Ledger has suspended a workspace’s Live billing, importing returns
live_charges_disabled. Subscriptions already imported keep renewing.