> ## Documentation Index
> Fetch the complete documentation index at: https://docs.integrateledger.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Migrate from Stripe Billing

> Move the customers you bill with Stripe subscriptions onto Ledger with one command. Everyone keeps their card, price and renewal date, and nobody is charged.

One command moves your monthly Stripe subscriptions onto Ledger. Each customer keeps their subscription, card and renewal date. Ledger grants their plan's credits for the current period now, and the credits for every later period when Stripe renews.

## 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 in `LEDGER_API_KEY` (or saved with `ledger login`):

```bash theme={"system"}
npx integrateledger-cli migrate stripe
```

It reads your Stripe account, changing nothing until you confirm, and:

1. **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.
2. **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](#which-subscriptions-can-be-imported)).
3. **Asks before changing anything.** Then it writes the plans to your config (`ledger.config.ts` or `ledger.catalog.json`; a new one is `ledger.catalog.json`), publishes the catalog, and imports each customer, one progress line each.
4. **Ends with a summary.** Imported, already imported, skipped by reason, failed, and the range of next renewals.

```text theme={"system"}
Sandbox · workspace · https://api.integrateledger.com · key from LEDGER_API_KEY

Plans
  pro  $49/mo  2000 credits/mo  new  price_1Pro… · 2 to import
  starter  $19/mo  500 credits/mo  new  price_1Sta… · 2 to import

Import 4
  user_di → pro  sub_1… · renews 2026-12-07
  …

Skip 2
  cus_Fay…  sub_1…  unsupported_subscription (schedule)
  cus_Ed…   sub_1…  unsupported_subscription (not_monthly)

[1/4] user_di → pro  imported, renews 2026-12-07
…
Imported 4, already imported 0, skipped 2, failed 0.
Next renewals: 2026-12-07 to 2026-12-07. Ledger grants each one's credits when Stripe renews it.
```

| Flag | Use it to |
| - | - |
| `--dry-run` | See the report only. |
| `--customer-id user_id` | Use your own customer ID from that Stripe customer metadata key. By default the Ledger customer ID is the Stripe customer ID (`cus_…`). Your app passes the same ID to check and track. |
| `--credits price_…=1000` | Give a new plan's monthly credits without the prompt (repeatable; for CI and agents). |
| `--feature generate=1` | Add a feature when the config has none (repeatable). |
| `--yes` | Skip the confirmation. |
| `--live` | Migrate Live. You type `live` to confirm, or pass `--yes`. |

**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).

## 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](https://docs.integrateledger.com/api-reference/migrate/stripe-preview.md) (`client.previewStripeMigration()`) returns the same report as JSON, then for each customer [create](https://docs.integrateledger.com/api-reference/customers/create.md) them, [link their Stripe customer](https://docs.integrateledger.com/api-reference/customers/stripe-customer.md) and [import their subscription](https://docs.integrateledger.com/api-reference/billing/import.md) onto a plan with the same monthly price. Every call is safe to repeat.

The [onboarding skill](https://docs.integrateledger.com/integrate/ai-agents.md) 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](https://docs.integrateledger.com/api-reference/billing/attach.md) 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_id` and `ledger_env`, and the customer also gets `ledger_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.

Ledger puts the subscription on its own Price so it can verify every invoice against the plan before granting credits. Your old Price stays in your account.

## 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:

| Error | What to do |
| - | - |
| `subscription_past_due`, `latest_invoice_unpaid` | Collect or void the open invoice in Stripe, then import. |
| `subscription_incomplete` | The first payment never succeeded: let the customer pay, or cancel it. |
| `subscription_ended`, `subscription_not_billable` | A canceled, expired, unpaid or paused subscription has nothing to import. |
| `multiple_subscriptions` | Import takes one Stripe subscription per customer. Consolidate the customer's subscriptions in Stripe first. |
| `stripe_customer_owned_elsewhere` | The customer's Ledger metadata names another Ledger workspace or environment. |
| `unsupported_subscription` | The `reason` names what the import can't move: several items (`multiple_items`) or a quantity above one (`quantity`), a price that isn't the plan's monthly USD amount (`price_mismatch`), a yearly (`not_monthly`) or usage-based (`metered_price`) price, invoices sent for manual payment, a subscription schedule or pending update, paused collection, billing thresholds, pending invoice items, or a customer balance. |

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](https://docs.integrateledger.com/pricing/annual.md) and [per-seat](https://docs.integrateledger.com/pricing/per-seat.md) 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](https://docs.integrateledger.com/api-reference/billing/import.md) and [Link a Stripe customer](https://docs.integrateledger.com/api-reference/customers/stripe-customer.md) 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.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.