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

# Upgrades, downgrades and cancellation

> Move a paying customer up or down a plan in one idempotent call, with grants, seats, discounts and tax carried over, or let them cancel at the period end.

Let customers move between your plans whenever they want, with one call each way. An upgrade charges now and grants the new plan at once; a downgrade starts at the period end or right away with a prorated refund; a cancellation stops renewal at the period end. Credits, seats, discounts and tax carry over, and every change is idempotent, so a retry never charges or refunds twice.

The calls on this page move a customer on a plan with a Stripe subscription: any paid plan, [pay as you go](https://docs.integrateledger.com/pricing/pay-as-you-go.md) included. A customer on a **free** plan, or with no plan, moves up with [`attach`](https://docs.integrateledger.com/billing/checkout-and-attach), and a [lifetime plan](https://docs.integrateledger.com/pricing/lifetime.md) moves to a recurring plan through attach with `replaceLifetime: true`.

| The customer wants | Call | When it takes effect |
| - | - | - |
| A pricier paid plan, or a longer interval | `upgradePaidPlan` | Now, with a full charge and a new period |
| A cheaper paid plan, or a shorter interval | `downgradePaidPlan` | At the period end (default), or now |
| To stop paying | `setSubscriptionCancellation` | At the period end |

Each upgrade and downgrade takes an idempotency key that identifies this one intended change. Store it and reuse it on every retry, so a retry never charges or refunds twice. Create the key when the customer confirms the change, for example the ID of a row you save for it, so a customer who later moves back to the same plan gets a fresh change. A key lasts 24 hours; after that it is a new request.

## Upgrade

```typescript TypeScript theme={"system"}
const upgrade = await billing.upgradePaidPlan({
	idempotencyKey: `upgrade_${planChange.id}`, // saved when the customer confirmed
	body: { customerId, planId: "scale" },
});
if (upgrade.status === "pending_payment" && upgrade.paymentUrl) {
	return res.redirect(303, upgrade.paymentUrl);
}
```

```python Python theme={"system"}
upgrade = billing.upgrade_paid_plan(
    customer_id=customer_id,
    plan_id="scale",
    idempotency_key=f"upgrade_{plan_change.id}",  # saved when the customer confirmed
)
if upgrade["status"] == "pending_payment" and upgrade.get("paymentUrl"):
    return redirect(upgrade["paymentUrl"], code=303)
```

```bash cURL theme={"system"}
curl https://api.integrateledger.com/v1/billing/upgrade \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: upgrade_pc_123" \
  -d '{"customerId": "user_123", "planId": "scale"}'
```

```json Response theme={"system"}
{ "upgradeId": 18, "status": "applied", "paymentUrl": null }
```

The TypeScript reply is `UpgradeResponse | AddOnItemAttachResponse`: a bill holding [add-ons](#with-add-ons), a plan riding on another product line's bill, or an [entity's plan](#within-a-group), answers an item change instead. Narrow it with `"itemChangeId" in upgrade` before reading `upgradeId` or `itemChangeId`; `status` and `paymentUrl` are on both.

Stripe charges the full new price and starts a new period. Act on `status`:

| `status` | Meaning | What to do |
| - | - | - |
| `applied` | Charged; the new plan and its grants are active. | Show the new plan. |
| `pending_payment` | The invoice needs the customer, usually for 3-D Secure. | Send them to `paymentUrl`; the upgrade applies when they pay. |
| `processing` | Ledger is still reconciling with Stripe. | Retry with the same key in a moment. |
| `closed` | The payment failed or expired. Nothing changed. | Offer it again with a **new** key. |

What carries over:

* **Credits and metered allowances.** The new plan's grants start with its period. The old plan's unspent credits and metered allowances stay until the old period would have ended ([spend order](https://docs.integrateledger.com/concepts/balances.md#spend-order-for-credits)). Packs are untouched.
* **Held counts** carry over, and the new plan's limit applies at once. **Boolean features** switch when the upgrade is applied.
* **Seats.** The count carries to the new plan's [seat price](https://docs.integrateledger.com/pricing/per-seat.md), billed in full on the upgrade invoice with the new plan.
* **License seats.** An upgrade to a plan that sells the same seat plan moves the [license](https://docs.integrateledger.com/pricing/seat-licenses.md#change-the-parent-plan): the seats, who holds them and what they've used, at the new plan's seat price.
* **Prepaid quantities.** A [prepaid quantity](https://docs.integrateledger.com/pricing/prepaid-quantity.md#plan-changes) carries to a plan that sells the same feature, billed as its packs on the upgrade invoice.
* **Intervals.** Monthly to [annual](https://docs.integrateledger.com/pricing/annual.md) is always an upgrade, whatever the price: the year is charged in full now, starts from the upgrade, and its first month is granted at once.
* **Discounts.** A coupon on the Stripe subscription stays on it. See [Discounts](#discounts).
* **Tax.** A taxed subscription stays taxed. With [Automatic tax](https://docs.integrateledger.com/billing/tax.md) on, an untaxed one starts being taxed when Stripe knows the customer's location.

On `502 stripe_upgrade_failed` or `503 upgrade_reconciliation_required`, retry with the **same** key.

## Downgrade

```typescript TypeScript theme={"system"}
const downgrade = await billing.downgradePaidPlan({
	idempotencyKey: `downgrade_${planChange.id}`,
	body: { customerId, planId: "starter" }, // timing: "period_end" by default
});
```

```python Python theme={"system"}
downgrade = billing.downgrade_paid_plan(
    customer_id=customer_id,
    plan_id="starter",
    idempotency_key=f"downgrade_{plan_change.id}",
)  # timing="period_end" by default
```

```bash cURL theme={"system"}
curl https://api.integrateledger.com/v1/billing/downgrade \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: downgrade_pc_124" \
  -d '{"customerId": "user_123", "planId": "starter"}'
```

```json Response theme={"system"}
{
  "downgradeId": 9,
  "status": "scheduled",
  "fromPlanId": "scale",
  "planId": "starter",
  "timing": "period_end",
  "refund": "none",
  "oldPlanCredits": "keep",
  "overageOnPlanChange": "carry_to_renewal",
  "effectiveAt": "2026-12-07T07:25:02.000Z",
  "refundAmountCents": null,
  "creditNoteId": null
}
```

### At the period end (default)

The customer keeps the current plan and its grants until the period ends, and the renewal starts the cheaper plan. The response is `scheduled`, with `effectiveAt` set to the renewal. Undo it any time before then with `cancelScheduledDowngrade({ downgradeId, customerId })`; `getScheduledDowngrade` returns the one that's pending. Held counts stay stored; past the new limit, see below.

### Immediately

With `timing: "immediately"`, the cheaper plan starts now and the renewal date stays. The response is `applied`.

* **Credits.** The new plan's credits are prorated to the rest of the period. The old plan's remaining credits end, or stay with `oldPlanCredits: "keep"`.
* **Metered allowances** are prorated per feature: the new allowance times the unused share of the period, counting what the customer already used of that feature. A customer who already used more than the new allowance gets the new plan's full allowance at the renewal.
* **Held counts** above the new limit are kept, never deleted. Removes work as usual, and adds resume once the count is back under the limit (until then they answer `limit_reached` with `remaining` at 0). **Boolean features** the cheaper plan lacks go off at once.
* **Seats** move to the cheaper plan's seat price, at the same count.
* **Refund.** `refund: "prorated"` refunds the unused share of the price difference to the card, plus the tax charged on it. On a discounted invoice the refund is on what the customer paid: a 50%-off customer gets half the list-price refund, never more than they paid.
* **Overage** from the old plan bills at its own rate on the next renewal, or now with `overageOnPlanChange: "bill_now"`.

### Annual, seat and free plans

* **Annual to monthly** happens at the year's end, where Stripe restarts the billing cycle for the new interval. Monthly grants carry on until the year ends; then the monthly plan renews.
* **Between two annual plans**, an immediate downgrade with `refund: "prorated"` refunds the price difference times the unused share of the year. The cheaper plan's allowance runs to the end of the current month, and the next month is granted in full.
* **A plan with seat prices** downgrades immediately, seats and all. To move it at the period end, cancel at the period end and attach the cheaper plan.
* **To a free plan**: cancel at the period end, then attach the free plan.

## Within a group

Each [plan group](https://docs.integrateledger.com/pricing/plan-groups.md) is its own ladder. An upgrade or downgrade replaces the customer's plan in the target's group and leaves their other product lines as they are: upgrading to `campaigns_pro` moves Campaigns Starter and keeps Starter.

* **The bill's own plan** (the first paid plan on the Stripe bill) moves as described above.
* **A plan riding on another product line's bill** moves up in one prorated Stripe change, with the period kept. The old plan's credits run to the period end, and the new plan's are granted for the rest of it. The answer is an item change: `{ "itemChangeId", "status", "paymentUrl", "item" }`, read as for an [add-on attach](https://docs.integrateledger.com/pricing/add-ons.md#attach-it).
* **An entity's plan** moves the same way: pass `entityId`, and only that entity moves. Other entities on the old plan stay on it. See [Plans per workspace or user](https://docs.integrateledger.com/pricing/entity-plans.md).

```typescript TypeScript theme={"system"}
const change = await billing.upgradePaidPlan({
	idempotencyKey: `upgrade_${planChange.id}`, // saved when the customer confirmed
	body: { customerId: "acme", planId: "workspace_max", entityId: "ws-1" },
});
if ("itemChangeId" in change && change.paymentUrl) {
	return res.redirect(303, change.paymentUrl);
}
```

```python Python theme={"system"}
change = billing.upgrade_paid_plan(
    customer_id="acme",
    plan_id="workspace_max",
    entity_id="ws-1",
    idempotency_key=f"upgrade_{plan_change.id}",  # saved when the customer confirmed
)
if "itemChangeId" in change and change.get("paymentUrl"):
    return redirect(change["paymentUrl"], code=303)
```

```bash cURL theme={"system"}
curl https://api.integrateledger.com/v1/billing/upgrade \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: upgrade_pc_124" \
  -d '{"customerId": "acme", "planId": "workspace_max", "entityId": "ws-1"}'
```

## With add-ons

A customer holding [recurring add-ons](https://docs.integrateledger.com/pricing/add-ons.md) moves their base plan up or down with the same calls. Only the base plan changes: each add-on stays on the bill at its quantity, with its grants and discounts, and the customer keeps one invoice.

* **Upgrade.** One prorated Stripe change, with the period kept. The invoice prorates the old and new base plan only, so no add-on is billed twice. The new plan's credits are granted for the rest of the period, prorated, and the old plan's run to the period end. The renewal bills the new plan and every add-on in full.
* **Downgrade at the period end.** The renewal starts the cheaper plan beside every add-on, billed in full with no proration.
* **Downgrade now.** The base plan moves to the cheaper price at once, and the add-ons carry on untouched.
* **Discounts.** A coupon on the bill stays through both, and discounts the upgrade invoice and the renewal.
* **Any currency.** A bill in [euros or another currency](https://docs.integrateledger.com/pricing/currencies.md#bill-a-customer-in-their-currency) upgrades, downgrades and changes add-ons in that currency.

An upgrade beside add-ons answers with the item-change shape, `{ "itemChangeId", "status", "paymentUrl", "item" }`, and its `status` reads as for an [add-on attach](https://docs.integrateledger.com/pricing/add-ons.md#attach-it). In TypeScript, narrow the reply on `itemChangeId`:

```typescript TypeScript theme={"system"}
const upgrade = await billing.upgradePaidPlan({
	idempotencyKey: `upgrade_${planChange.id}`, // saved when the customer confirmed
	body: { customerId, planId: "premium" },
});
if (upgrade.status === "pending_payment" && upgrade.paymentUrl) {
	return res.redirect(303, upgrade.paymentUrl);
}
if ("itemChangeId" in upgrade) {
	// AddOnItemAttachResponse: the base plan moved beside the add-ons
	return res.json({ itemChangeId: upgrade.itemChangeId, item: upgrade.item });
}
// UpgradeResponse: the bill held only the base plan
return res.json({ upgradeId: upgrade.upgradeId });
```

```python Python theme={"system"}
upgrade = billing.upgrade_paid_plan(
    customer_id=customer_id,
    plan_id="premium",
    idempotency_key=f"upgrade_{plan_change.id}",  # saved when the customer confirmed
)
if upgrade["status"] == "pending_payment" and upgrade.get("paymentUrl"):
    return redirect(upgrade["paymentUrl"], code=303)
```

```bash cURL theme={"system"}
curl https://api.integrateledger.com/v1/billing/upgrade \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: upgrade_pc_125" \
  -d '{"customerId": "user_123", "planId": "premium"}'
```

```json Response theme={"system"}
{
  "itemChangeId": 44,
  "status": "applied",
  "paymentUrl": null,
  "item": { "planId": "premium", "quantity": 1 }
}
```

## Discounts

A coupon or promotion code on the Stripe subscription stays on it through upgrades and downgrades, with its end date unchanged, and keeps discounting whatever it covers. A coupon for every product discounts the new plan too; one limited to the old plan's product stays with that plan, and applies again if the customer moves back. Each plan still grants its full credits. A period-end downgrade keeps the subscription's discounts on both phases of its schedule, and a prorated refund is on what the discounted invoice took. See [Discounts and promotion codes](https://docs.integrateledger.com/billing/discounts.md).

## Cancel at period end

Renewal is set on the subscription's numeric `id`. Find the active paid subscription in `listCustomerSubscriptions` and offer the control only when its `cancellation.manageable` is `true`:

```typescript TypeScript theme={"system"}
const { items } = await billing.listCustomerSubscriptions({ customerId });
const paid = items.find(
	(item) => item.status === "active" && item.cancellation?.manageable === true,
);

if (paid) {
	await billing.setSubscriptionCancellation({
		customerId,
		subscriptionId: paid.id,
		body: { cancelAtPeriodEnd: true }, // false resumes
	});
}
```

```python Python theme={"system"}
subscriptions = billing.list_customer_subscriptions(customer_id=customer_id)
paid = next(
    (
        item
        for item in subscriptions["items"]
        if item["status"] == "active" and (item["cancellation"] or {}).get("manageable")
    ),
    None,
)

if paid:
    billing.set_subscription_cancellation(
        customer_id=customer_id,
        subscription_id=paid["id"],
        cancel_at_period_end=True,  # False resumes
    )
```

```bash cURL theme={"system"}
curl "https://api.integrateledger.com/v1/customers/subscriptions/42/cancellation?customerId=user_123" \
  -H "Authorization: Bearer $LEDGER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"cancelAtPeriodEnd": true}'
```

```json Response theme={"system"}
{ "cancelAtPeriodEnd": true, "cancelsAt": "2026-12-07T07:25:02.000Z" }
```

Show `cancelsAt` and a **Resume** button. The plan and its grants last until then, with no further charge. When the period ends, the subscription is `canceled`: its credits and metered allowances expire, its boolean features go off, and packs stay. Held counts stay stored, so attaching a plan later restores them against its limit. Attach your free plan to give the customer an allowance again.

**A past-due subscription can be cancelled too,** at the period end, by its `id`. Its unpaid invoice stays open for Stripe to collect. At `cancelsAt` the plan ends without granting again.

### Cancel now

To end a subscription immediately, cancel it in Stripe; Ledger follows Stripe's `customer.subscription.deleted` event. The plan ends at once, the current month's grants with it (on an annual plan, too). Any unbilled overage, credit and metered, is billed on a final invoice, so no usage goes unpaid. The subscription's unpaid invoices follow your [Stripe subscription settings](https://dashboard.stripe.com/settings/billing/automatic). Cancellations carry no refund from Ledger; refund in Stripe when you want to.

## Rules

* One change at a time: while an upgrade waits for payment, or a downgrade or cancellation is scheduled, the others answer `409` (`upgrade_pending`, `downgrade_scheduled`, `cancellation_scheduled`). Undo the scheduled one first.
* Build each idempotency key from the confirmed change, not from the customer and plan alone, or a later move back to the same plan replays the first result.
* Upgrades and downgrades stay in a group: a target in a group the customer (or entity) holds nothing in answers `400 plan_not_in_group`; attach it instead.
* A plan riding on another product line's bill, and an entity's plan, move by upgrade (`409 downgrade_unavailable_for_item`).
* An upgrade goes to a synced paid plan that costs more or bills on a longer interval (`400 ineligible_upgrade`).
* A downgrade goes to a cheaper synced paid plan, or one on a shorter interval (`400 ineligible_downgrade`).
* Upgrades and downgrades work on subscriptions whose schedule Ledger set (`400 ineligible_stripe_subscription`).
* A base plan with seat prices, [seat licenses](https://docs.integrateledger.com/pricing/seat-licenses.md) or [prepaid](https://docs.integrateledger.com/pricing/prepaid-quantity.md) units moves on a bill without add-ons (`400 ineligible_stripe_subscription`).
* While an add-on is canceling at the period end, the base plan moves by upgrade; a downgrade waits until the add-on has ended (`409 subscription_change_pending`).
* Annual to monthly uses the default `timing: "period_end"` (`400 interval_change_at_period_end`).
* A plan with seat prices downgrades with `timing: "immediately"` (`400 seat_plan_downgrade_now_only`).
* `refund` and `overageOnPlanChange` go with `timing: "immediately"` (`400 refund_not_available`, `overage_option_not_available`).
* `refund: "prorated"` and `oldPlanCredits: "keep"` are sent one or the other.
* A prorated refund needs a paid invoice; without one, downgrade without `refund` (`409 no_payment_to_refund`).
* An immediate downgrade waits until the renewal invoice is paid, since it bills the current plan (`409 renewal_pending`, in the hour before Stripe charges and after a failed payment).
* Seats and prepaid quantities move by upgrade: a downgrade to or from a plan with [prepaid](https://docs.integrateledger.com/pricing/prepaid-quantity.md) units is `400 prepaid_change_unavailable`, and a downgrade from a plan with a [license](https://docs.integrateledger.com/pricing/seat-licenses.md) is `400 license_change_unavailable`. Cancel at the period end, then attach the new plan.
* An upgrade keeps the customer's prepaid quantity; change it after with `POST /v1/billing/quantities`.
* `cancellation` is `null` for free plans, pending Checkouts, and when Ledger couldn't read the subscription from Stripe.
* `409 subscription_not_manageable` means the Stripe subscription has a change of its own, such as a pause or a custom cancellation date; resolve it in Stripe.

> [!NOTE]
>
> **Other ways.** Customers in the dashboard have a **Manage subscription** sheet for one-off changes. Over HTTP, see [upgrade](https://docs.integrateledger.com/api-reference/billing/upgrade.md), [downgrade](https://docs.integrateledger.com/api-reference/billing/downgrade.md) and [cancellation](https://docs.integrateledger.com/api-reference/customers/cancellation.md). Every error code is in [Errors](https://docs.integrateledger.com/errors.md).


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