# Billing

> Checkout, your subscription, plan changes, cancellation and orders.

URL: https://renzo-digital.com/docs/resources/billing

Billing lets a customer buy a plan, see the subscription, change or cancel it, and read past orders. Payments run on the payment provider's hosted pages. The API never takes card details. Every call needs a token. Calls that change something or start a checkout also need a username.

Entitlements read the subscription that Renzo has stored, not the provider. The subscription exists only after the provider confirms the payment. List the plans in [Products](https://renzo-digital.com/docs/resources/products).

## Endpoints

| Operation | What it does | Auth |
| --- | --- | --- |
| `GET /api/v1/billing` | Your live subscription and first page of orders in one call. | Token |
| `GET /api/v1/billing/subscription` | Read your live subscription. | Token |
| `GET /api/v1/billing/orders` | List your orders and payments, newest first. Cursor-paginated. | Token |
| `GET /api/v1/billing/checkout-sessions/preview` | Show what a checkout charges now and at the next bill: `?price_id=...`. | Token and username |
| `POST /api/v1/billing/checkout-sessions` | Start a hosted checkout. Answers `201`. Declares `Idempotency-Key`. | Token and username |
| `POST /api/v1/billing/subscription/price/preview` | Quote a move to another price. | Token and username |
| `PUT /api/v1/billing/subscription/price` | Make the move. Declares `Idempotency-Key`. | Token and username |
| `PUT /api/v1/billing/subscription/cancellation` | Cancel at the end of the period. | Token and username |
| `DELETE /api/v1/billing/subscription/cancellation` | Undo a cancellation. | Token and username |
| `POST /api/v1/billing/portal-sessions` | Open the provider's billing portal. Answers `201`. | Token and username |

Without a username, calls that need one answer `409` [`profile_incomplete`](https://renzo-digital.com/docs/error-codes#profile_incomplete). See [Account](https://renzo-digital.com/docs/resources/account). Checkout uses a durable provider key for the pending purchase; plan changes also use provider idempotency. Any mutating call accepts it. See [Idempotency](https://renzo-digital.com/docs/concepts/idempotency).

## Example: buy a plan

Pick a price `id` from `GET /api/v1/products`. Preview the charge first:

```bash tab="curl"
curl "$BASE/api/v1/billing/checkout-sessions/preview?price_id=e20b39bd-9326-5178-9074-9c31733f3a2f" \
  -H "Authorization: Bearer $TOKEN"
```

```python tab="Python"
import os

import requests

BASE = os.environ["BASE"]
TOKEN = os.environ["TOKEN"]

answer = requests.get(
    f"{BASE}/api/v1/billing/checkout-sessions/preview",
    headers={"Authorization": f"Bearer {TOKEN}"},
    params={"price_id": "e20b39bd-9326-5178-9074-9c31733f3a2f"},
)
answer.raise_for_status()
print(answer.json())
```

```js tab="Node.js"
const { BASE, TOKEN } = process.env;

const answer = await fetch(`${BASE}/api/v1/billing/checkout-sessions/preview?price_id=e20b39bd-9326-5178-9074-9c31733f3a2f`, {
  headers: { Authorization: `Bearer ${TOKEN}` },
});
if (!answer.ok) throw new Error(`HTTP ${answer.status}`);
console.log(await answer.json());
```

```json title="Response"
{
  "full_price_cents": 1900,
  "referral_discount_percent": 20,
  "discount_cents": 380,
  "amount_today_cents": 1520,
  "grant_days_left": 12,
  "grant_credit_cents": 760,
  "next_bill_at": "2026-12-04T13:30:00Z",
  "next_bill_cents": 1140
}
```

Then start the checkout. The answer is `201`:

```bash tab="curl"
curl -X POST "$BASE/api/v1/billing/checkout-sessions" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: 3c8e1f52-7b9d-4a60-8e14-d25f6a0b9c71" \
  -H "Content-Type: application/json" \
  -d '{"price_id": "e20b39bd-9326-5178-9074-9c31733f3a2f"}'
```

```python tab="Python"
import os

import requests

BASE = os.environ["BASE"]
TOKEN = os.environ["TOKEN"]

answer = requests.post(
    f"{BASE}/api/v1/billing/checkout-sessions",
    headers={
        "Authorization": f"Bearer {TOKEN}",
        "Idempotency-Key": "3c8e1f52-7b9d-4a60-8e14-d25f6a0b9c71",
    },
    json={"price_id": "e20b39bd-9326-5178-9074-9c31733f3a2f"},
)
answer.raise_for_status()
print(answer.json())
```

```js tab="Node.js"
const { BASE, TOKEN } = process.env;

const answer = await fetch(`${BASE}/api/v1/billing/checkout-sessions`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${TOKEN}`,
    "Idempotency-Key": "3c8e1f52-7b9d-4a60-8e14-d25f6a0b9c71",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ price_id: "e20b39bd-9326-5178-9074-9c31733f3a2f" }),
});
if (!answer.ok) throw new Error(`HTTP ${answer.status}`);
console.log(await answer.json());
```

```json title="Response"
{
  "id": "cs_test_a1B2c3D4e5F6g7H8",
  "url": "https://checkout.stripe.com/c/pay/cs_test_a1B2c3D4e5F6g7H8",
  "expires_at": "2026-11-04T14:00:00Z"
}
```

> **Warning:** Send the reader to `url`. When they return, poll `GET /api/v1/billing/subscription`. Do not assume the payment worked.

## Example: upgrade a subscription

Quote the change:

```bash tab="curl"
curl -X POST "$BASE/api/v1/billing/subscription/price/preview" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"price_id": "026b9c9b-b877-592c-9954-cc9d8ee8e9d1"}'
```

```python tab="Python"
import os

import requests

BASE = os.environ["BASE"]
TOKEN = os.environ["TOKEN"]

answer = requests.post(
    f"{BASE}/api/v1/billing/subscription/price/preview",
    headers={"Authorization": f"Bearer {TOKEN}"},
    json={"price_id": "026b9c9b-b877-592c-9954-cc9d8ee8e9d1"},
)
answer.raise_for_status()
print(answer.json())
```

```js tab="Node.js"
const { BASE, TOKEN } = process.env;

const answer = await fetch(`${BASE}/api/v1/billing/subscription/price/preview`, {
  method: "POST",
  headers: { Authorization: `Bearer ${TOKEN}`, "Content-Type": "application/json" },
  body: JSON.stringify({ price_id: "026b9c9b-b877-592c-9954-cc9d8ee8e9d1" }),
});
if (!answer.ok) throw new Error(`HTTP ${answer.status}`);
console.log(await answer.json());
```

```json title="Response"
{
  "change": "upgrade",
  "price": {
    "id": "026b9c9b-b877-592c-9954-cc9d8ee8e9d1",
    "product_id": "52108830-cd62-51b4-9ce3-f0051ed42666",
    "product_code": "premium",
    "product_name": "Premium",
    "amount_cents": 19000,
    "currency": "USD",
    "interval": "year"
  },
  "takes_effect_at": "2026-11-04T13:30:00Z",
  "currency": "USD",
  "lines": [
    { "description": "Unused time on Premium (monthly)", "amount_cents": -1500 },
    { "description": "Premium (yearly)", "amount_cents": 19000 }
  ],
  "subtotal_cents": 17500,
  "tax_cents": 0,
  "amount_due_cents": 17500,
  "next_billing_at": "2027-11-04T13:30:00Z",
  "next_amount_cents": 19000,
  "proration_date": "2026-11-04T13:30:00Z"
}
```

Confirm it. Send the `proration_date` back:

```bash tab="curl"
curl -X PUT "$BASE/api/v1/billing/subscription/price" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: 8a4d2b17-5e60-4c93-b1f8-6d09e3a7c254" \
  -H "Content-Type: application/json" \
  -d '{"price_id": "026b9c9b-b877-592c-9954-cc9d8ee8e9d1", "proration_date": "2026-11-04T13:30:00Z"}'
```

```python tab="Python"
import os

import requests

BASE = os.environ["BASE"]
TOKEN = os.environ["TOKEN"]

answer = requests.put(
    f"{BASE}/api/v1/billing/subscription/price",
    headers={
        "Authorization": f"Bearer {TOKEN}",
        "Idempotency-Key": "8a4d2b17-5e60-4c93-b1f8-6d09e3a7c254",
    },
    json={
        "price_id": "026b9c9b-b877-592c-9954-cc9d8ee8e9d1",
        "proration_date": "2026-11-04T13:30:00Z",
    },
)
answer.raise_for_status()
print(answer.json())
```

```js tab="Node.js"
const { BASE, TOKEN } = process.env;

const answer = await fetch(`${BASE}/api/v1/billing/subscription/price`, {
  method: "PUT",
  headers: {
    Authorization: `Bearer ${TOKEN}`,
    "Idempotency-Key": "8a4d2b17-5e60-4c93-b1f8-6d09e3a7c254",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    price_id: "026b9c9b-b877-592c-9954-cc9d8ee8e9d1",
    proration_date: "2026-11-04T13:30:00Z",
  }),
});
if (!answer.ok) throw new Error(`HTTP ${answer.status}`);
console.log(await answer.json());
```

The answer is `200` with the subscription:

```json title="Response"
{
  "id": "cf4b1077-d871-5ff7-82f3-9a9bbe9514d3",
  "status": "active",
  "source": "provider",
  "referral_grant": false,
  "product_code": "premium",
  "price": {
    "id": "026b9c9b-b877-592c-9954-cc9d8ee8e9d1",
    "product_id": "52108830-cd62-51b4-9ce3-f0051ed42666",
    "product_code": "premium",
    "product_name": "Premium",
    "amount_cents": 19000,
    "currency": "USD",
    "interval": "year"
  },
  "current_period_start": "2026-11-04T13:30:00Z",
  "current_period_end": "2027-11-04T13:30:00Z",
  "cancel_at_period_end": false,
  "scheduled_price": null,
  "payment_url": null
}
```

## Rules and edge cases

- **One live subscription.** Checkout is refused while you have one. It answers `409` [`subscription_already_active`](https://renzo-digital.com/docs/error-codes#subscription_already_active). Change its price instead.
- **Price must be for sale.** A retired price answers `409` [`product_price_not_for_sale`](https://renzo-digital.com/docs/error-codes#product_price_not_for_sale). An unknown price ID answers `404` [`product_price_not_found`](https://renzo-digital.com/docs/error-codes#product_price_not_found). The checkout preview has the same three answers.
- **Checkout preview.** It changes nothing. It shows the referral discount and any referral credit. `referral_discount_percent` is `null` when no code applies. See [Referrals](https://renzo-digital.com/docs/resources/referrals).
- **Checkout URL.** `expires_at` is when the payment page stops working. It is `null` when the page does not expire.
- **Return path.** Send `return_to`, a path on the Renzo site such as `/en/articles/fed-cut`, to bring the reader back there after payment. It must start with one `/`. A full URL, another host (`//host`), a backslash, a space or a control character answers `422` [`checkout_return_to_invalid`](https://renzo-digital.com/docs/error-codes#checkout_return_to_invalid). Its limit is 512 characters. After payment the provider sends the reader to the Renzo success page with `?return_to=` and the encoded path.
- **One open checkout.** Starting a checkout for the same price and `return_to` again answers the same open page. A different price or `return_to` closes the open page first, so its URL stops working. If another checkout of your account is still starting, you get `409` [`checkout_in_progress`](https://renzo-digital.com/docs/error-codes#checkout_in_progress). Retry shortly.
- **Subscription status.** `status` is `trialing`, `active` or `past_due`. `source` is `provider` for a paid plan and `manual` for a grant. `referral_grant` is `true` for a grant earned by referring. A purchase ends it. A grant can have `price` as `null` and no period dates.
- **No subscription.** `GET /api/v1/billing/subscription` answers `404` [`subscription_not_found`](https://renzo-digital.com/docs/error-codes#subscription_not_found). `GET /api/v1/billing` answers `200` with `subscription` as `null`.
- **Orders.** `GET /api/v1/billing/orders` and the `orders` part of `GET /api/v1/billing` hold orders with `payments`. An order `status` is `pending`, `paid`, `failed`, `void`, `refunded` or `partially_refunded`. Refunds show `amount_cents`, `currency`, `status` and `created_at`. Failed payments may include `failure_message`. Provider IDs and staff refund notes are not included. Amounts are in cents. `limit` defaults to 20 and may not pass 100. See [Pagination](https://renzo-digital.com/docs/concepts/pagination).
- **Upgrade and downgrade.** A dearer price is an upgrade. It charges the quoted amount now. A cheaper price is a downgrade. It applies at the period end and shows as `scheduled_price` on the subscription. The preview field `change` is `upgrade`, `downgrade`, `none` or `clear_pending`.
- **Fresh quote.** An upgrade needs a `proration_date` from a preview made at most 15 minutes before. With none, or an old one, `PUT /api/v1/billing/subscription/price` answers `409` [`subscription_price_quote_stale`](https://renzo-digital.com/docs/error-codes#subscription_price_quote_stale). Preview again and retry.
- **Yearly lock.** A yearly plan cannot move to a monthly price mid-term. It answers `409` [`subscription_interval_locked`](https://renzo-digital.com/docs/error-codes#subscription_interval_locked).
- **Declined card.** An upgrade whose card is refused answers `402` [`billing_payment_declined`](https://renzo-digital.com/docs/error-codes#billing_payment_declined), and nothing changes.
- **Payment needs approval.** When the bank asks the reader to approve the charge, or the charge does not go through at once, the answer is `200` with a `payment_url`. Send the reader there. The price stays the same until the payment is made.
- **Cancelling.** `PUT` on the cancellation cancels at the period end. Access stays until `current_period_end`, with no refund, and a booked downgrade is dropped. `cancel_at_period_end` turns `true`. `DELETE` keeps the subscription. A subscription that was not set to cancel comes back unchanged.
- **Not changeable.** A subscription that cannot be changed here, such as a staff grant, answers `409` [`subscription_not_changeable`](https://renzo-digital.com/docs/error-codes#subscription_not_changeable).
- **Busy.** If another change to the subscription is still running, you get `409` [`subscription_change_in_progress`](https://renzo-digital.com/docs/error-codes#subscription_change_in_progress). Retry shortly.
- **Provider failures.** `502` [`billing_provider_failed`](https://renzo-digital.com/docs/error-codes#billing_provider_failed) means the provider refused or failed the call, and nothing was saved. `502` [`billing_provider_outcome_unknown`](https://renzo-digital.com/docs/error-codes#billing_provider_outcome_unknown) means the result is not known. Retry with the same `Idempotency-Key`, then read the subscription.
- **Portal.** `POST /api/v1/billing/portal-sessions` returns a short-lived `url` of the provider's portal, to update the card and download invoices. Each call opens a new session. Without a subscription it answers `404` [`subscription_not_found`](https://renzo-digital.com/docs/error-codes#subscription_not_found).

## Errors

| Code | Status | When |
| --- | --- | --- |
| [`subscription_already_active`](https://renzo-digital.com/docs/error-codes#subscription_already_active) | 409 | You already have a live subscription, so a new checkout is refused. |
| [`checkout_in_progress`](https://renzo-digital.com/docs/error-codes#checkout_in_progress) | 409 | Another checkout request of this account is still running. |
| [`checkout_return_to_invalid`](https://renzo-digital.com/docs/error-codes#checkout_return_to_invalid) | 422 | `return_to` is not a path on this site. |
| [`subscription_not_found`](https://renzo-digital.com/docs/error-codes#subscription_not_found) | 404 | You have no live subscription. |
| [`subscription_not_changeable`](https://renzo-digital.com/docs/error-codes#subscription_not_changeable) | 409 | The subscription cannot be changed here, for example a staff grant. |
| [`subscription_change_in_progress`](https://renzo-digital.com/docs/error-codes#subscription_change_in_progress) | 409 | Another change to this subscription is still running. |
| [`subscription_interval_locked`](https://renzo-digital.com/docs/error-codes#subscription_interval_locked) | 409 | A yearly plan cannot switch to a monthly price mid-term. |
| [`subscription_price_quote_stale`](https://renzo-digital.com/docs/error-codes#subscription_price_quote_stale) | 409 | An upgrade needs a recent quote and there is none. |
| [`product_price_not_found`](https://renzo-digital.com/docs/error-codes#product_price_not_found) | 404 | No price has this ID. |
| [`product_price_not_for_sale`](https://renzo-digital.com/docs/error-codes#product_price_not_for_sale) | 409 | The price is retired or cannot be bought. |
| [`billing_payment_declined`](https://renzo-digital.com/docs/error-codes#billing_payment_declined) | 402 | The card was declined. |
| [`billing_provider_failed`](https://renzo-digital.com/docs/error-codes#billing_provider_failed) | 502 | The payment provider refused or failed the call. Nothing was saved. |
| [`billing_provider_outcome_unknown`](https://renzo-digital.com/docs/error-codes#billing_provider_outcome_unknown) | 502 | The provider did not answer, so the result is not known. |
| [`profile_incomplete`](https://renzo-digital.com/docs/error-codes#profile_incomplete) | 409 | The account has no username yet. |

Sign-in and request errors, such as [`token_expired`](https://renzo-digital.com/docs/error-codes#token_expired) and [`validation_failed`](https://renzo-digital.com/docs/error-codes#validation_failed), can come from any call. See [Errors](https://renzo-digital.com/docs/concepts/errors).

## Reference

- [Billing in the API reference](https://renzo-digital.com/docs/api#tag/billing)
