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

# Customers and subscriptions

> Bill any user, team or organization by your own ID, and attach a plan to give them a subscription that grants its balances each period.

Ledger bills whoever you sell to, a user, a team or an organization, by the ID your app already has. A **customer** takes your own ID as `customerId` and pass that ID to every call. A **subscription** is the customer's plan: attaching a plan creates one, and it grants what the plan includes each period.

```mermaid theme={"system"}
%%{init: {"theme": "base", "themeVariables": {"fontFamily": "IBM Plex Sans, sans-serif", "fontSize": "14px", "primaryColor": "#f7f6f3", "primaryBorderColor": "#c4bfb5", "primaryTextColor": "#1a1816", "lineColor": "#6b655c", "edgeLabelBackground": "#ffffff"}}}%%
flowchart LR
    c["Customer<br/>your customerId"] -- "attach" --> s["Subscription<br/>plan · status · period"]
    s -- "each period" --> g["Grants<br/>allowances · credits · limits"]
    c -- "buys" --> p["Credit packs"]
    c -. "optional" .-> e["Entities<br/>users or workspaces inside"]
    style s fill:#eff2fd,stroke:#2443c4
```

## Customers

* **Your ID is the key.** Use the user or organization ID your app already has. It's unique per environment: the same ID in Sandbox and Live is two separate customers.
* **Attaching a plan grants its balances.** Attach one at signup, usually the free one. [Creating customers](https://docs.integrateledger.com/customers/creating-customers.md) covers it.
* **Ledger creates the Stripe customer** at the customer's first paid purchase, or you [link](https://docs.integrateledger.com/integrate/migrate-from-stripe.md) one they already have.
* **Entities** split one customer's credits between its users, seats or workspaces, each with its own credit allowance or cap, and each can hold [plans of its own](https://docs.integrateledger.com/pricing/entity-plans.md) billed on the customer's invoice. See [Entities](https://docs.integrateledger.com/customers/entities.md).

## Subscriptions

A customer holds one base plan per [group](https://docs.integrateledger.com/pricing/plan-groups.md), so each product line has its plan, plus any [recurring add-ons](https://docs.integrateledger.com/pricing/add-ons.md) and the [plans of its entities](https://docs.integrateledger.com/pricing/entity-plans.md). Every paid one rides on one Stripe bill, with any [seat licenses](https://docs.integrateledger.com/pricing/seat-licenses.md) and [prepaid quantities](https://docs.integrateledger.com/pricing/prepaid-quantity.md) the customer bought; an add-on bought first [starts that bill](https://docs.integrateledger.com/pricing/add-ons.md#sell-an-add-on-before-a-paid-plan) and a paid plan joins it. A [custom deal](https://docs.integrateledger.com/billing/custom-plans.md) gives one customer their own terms on a plan. `GET /v1/customers` returns the `default` group's plan as `currentPlan`, with its period, and a `features` list with each feature's balance across every plan the customer holds. `listCustomerSubscriptions` returns every plan they've had, newest first.

| `status` | Means |
| - | - |
| `active` | Paid up, or on a free plan |
| `trialing` | In a [free trial](https://docs.integrateledger.com/pricing/trials.md), until `trialEndsAt` |
| `pending_checkout` | Checkout for the customer's first plan hasn't completed |
| `incomplete` | The first invoice is still being paid |
| `past_due`, `unpaid`, `paused` | Stripe is waiting on a payment. The plan stays, without overage, upgrades or early renewal grants, unless the plan or customer [ignores past due](https://docs.integrateledger.com/billing/renewals-and-lifecycle.md#ignore-past-due) |
| `canceled`, `incomplete_expired` | Ended, or Checkout expired before payment. Nothing applies |

A customer on the free plan keeps it as `currentPlan` until a new paid plan is paid for.

## The life of a subscription

* **Start.** A free plan starts on attach. A paid plan starts when Stripe's signed webhook confirms the first payment; then the free plan in its group ends, with its unspent credits. See [Checkout and attach](https://docs.integrateledger.com/billing/checkout-and-attach.md).
* **Renew.** Stripe renews a paid plan each interval; Ledger renews a free plan itself. Each renewal grants a fresh period. See [Renewals and lifecycle](https://docs.integrateledger.com/billing/renewals-and-lifecycle.md).
* **Change.** An upgrade bills now and starts a new period; a downgrade waits for the period end by default. See [Upgrades and downgrades](https://docs.integrateledger.com/billing/upgrades-and-downgrades.md). Seats and prepaid quantities change on their own ([seat count](https://docs.integrateledger.com/pricing/seat-licenses.md#change-the-seat-count), [quantity](https://docs.integrateledger.com/pricing/prepaid-quantity.md#change-a-quantity)), and a plan's version moves with a [migration](https://docs.integrateledger.com/billing/plan-versions.md).
* **Use.** [Usage limits](https://docs.integrateledger.com/pricing/usage-limits.md) cap uses per day, week or month, and [usage alerts](https://docs.integrateledger.com/pricing/usage-alerts.md) send a webhook at a threshold, set on the plan or one customer.
* **End.** Cancelling at the period end keeps the plan until then; [cancelling an add-on](https://docs.integrateledger.com/pricing/add-ons.md#cancel-an-add-on) ends just that item. When the subscription ends, its grants end, and Ledger bills any remaining overage. Credit packs stay.

A [lifetime plan](https://docs.integrateledger.com/pricing/lifetime.md) is paid once, with no Stripe subscription, and stays the customer's plan until another plan replaces it.

## Rules

* `check` and `track` work on existing customers: an unknown `customerId` returns `404 customer_not_found`, so create the customer at signup.
* Attach starts a customer's first paid plan in a group, over a free one in that group. After that, move them with an [upgrade or downgrade](https://docs.integrateledger.com/billing/upgrades-and-downgrades.md) within the group: attaching over any other current plan in the group returns `409 subscription_exists`.
* Treat a `status` value you don't recognise as not paid up, so new values stay safe.

## Next steps

> [card] [Balances](https://docs.integrateledger.com/concepts/balances.md)
>
> What the subscription's grants add up to.

> [card] [Checkout and attach](https://docs.integrateledger.com/billing/checkout-and-attach.md)
>
> Start a plan, free or paid.


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