RenzoDocs

Billing

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

View as Markdown

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.

Endpoints

OperationWhat it doesAuth
GET/api/v1/billingYour live subscription and first page of orders in one call.Token
GET/api/v1/billing/subscriptionRead your live subscription.Token
GET/api/v1/billing/ordersList your orders and payments, newest first. Cursor-paginated.Token
GET/api/v1/billing/checkout-sessions/previewShow what a checkout charges now and at the next bill: ?price_id=....Token and username
POST/api/v1/billing/checkout-sessionsStart a hosted checkout. Answers 201. Declares Idempotency-Key.Token and username
POST/api/v1/billing/subscription/price/previewQuote a move to another price.Token and username
PUT/api/v1/billing/subscription/priceMake the move. Declares Idempotency-Key.Token and username
PUT/api/v1/billing/subscription/cancellationCancel at the end of the period.Token and username
DELETE/api/v1/billing/subscription/cancellationUndo a cancellation.Token and username
POST/api/v1/billing/portal-sessionsOpen the provider's billing portal. Answers 201.Token and username

Without a username, calls that need one answer 409 profile_incomplete. See Account. Checkout uses a durable provider key for the pending purchase; plan changes also use provider idempotency. Any mutating call accepts it. See Idempotency.

Example: buy a plan

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

curl "$BASE/api/v1/billing/checkout-sessions/preview?price_id=e20b39bd-9326-5178-9074-9c31733f3a2f" \
  -H "Authorization: Bearer $TOKEN"
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:

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"}'
Response
{
  "id": "cs_test_a1B2c3D4e5F6g7H8",
  "url": "https://checkout.stripe.com/c/pay/cs_test_a1B2c3D4e5F6g7H8",
  "expires_at": "2026-11-04T14:00:00Z"
}

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:

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"}'
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:

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"}'

The answer is 200 with the subscription:

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. Change its price instead.
  • Price must be for sale. A retired price answers 409 product_price_not_for_sale. An unknown price ID answers 404 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.
  • 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. 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. 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. 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.
  • 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. Preview again and retry.
  • Yearly lock. A yearly plan cannot move to a monthly price mid-term. It answers 409 subscription_interval_locked.
  • Declined card. An upgrade whose card is refused answers 402 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.
  • Busy. If another change to the subscription is still running, you get 409 subscription_change_in_progress. Retry shortly.
  • Provider failures. 502 billing_provider_failed means the provider refused or failed the call, and nothing was saved. 502 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.

Errors

CodeStatusWhen
subscription_already_active409You already have a live subscription, so a new checkout is refused.
checkout_in_progress409Another checkout request of this account is still running.
checkout_return_to_invalid422return_to is not a path on this site.
subscription_not_found404You have no live subscription.
subscription_not_changeable409The subscription cannot be changed here, for example a staff grant.
subscription_change_in_progress409Another change to this subscription is still running.
subscription_interval_locked409A yearly plan cannot switch to a monthly price mid-term.
subscription_price_quote_stale409An upgrade needs a recent quote and there is none.
product_price_not_found404No price has this ID.
product_price_not_for_sale409The price is retired or cannot be bought.
billing_payment_declined402The card was declined.
billing_provider_failed502The payment provider refused or failed the call. Nothing was saved.
billing_provider_outcome_unknown502The provider did not answer, so the result is not known.
profile_incomplete409The account has no username yet.

Sign-in and request errors, such as token_expired and validation_failed, can come from any call. See Errors.

Reference

On this page