Plans and billing

How plans, prices and entitlements are set, how Stripe Checkout and the webhook keep subscriptions in sync, and how to test payments in Stripe test mode.

Updated · 3 min read

Each organisation is on a plan, and organisations pay through Stripe. You define plans and what they unlock in one file; Stripe holds the prices charged. Owners and admins subscribe in Stripe Checkout and manage their card, plan and cancellation in Stripe's Customer Portal. Billing is optional: without Stripe keys every organisation is on Free.

The example plans

The starter ships three plans as a starting point:

PlanPrice shownTrialSeatsProjectsFeatures
Free$0None13None
Pro$19 a month14 days525API access
Team$49 a month14 days25No limitAPI access, priority support, audit log

Plans, their descriptions, trial lengths and entitlements live in packages/contracts/src/billing.ts, which both the API and the web app read. The price there is a label for your pricing page. The amount actually charged comes from the Stripe price, and Checkout shows it. The trial applies to an organisation's first subscription.

Entitlements are defined and served to your code, but the starter doesn't enforce them yet. The seat and project limits are examples for your app to apply where it creates seats or projects. Check them on the server.

Connect Stripe

Billing switches on when the server has both STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET. Without both, the billing page says billing is switched off, checkout and the portal answer 503, and the server logs which keys are missing. Plans already stored keep resolving, so losing the keys never drops paying organisations to Free.

VariableHolds
STRIPE_SECRET_KEYA secret or restricted key. sk_test_... until you go live.
STRIPE_WEBHOOK_SECRETThe signing secret (whsec_...) of your webhook endpoint.
STRIPE_PRICE_PROThe Stripe price id for Pro.
STRIPE_PRICE_TEAMThe Stripe price id for Team.

A price variable can hold several ids separated by commas. Checkout offers the first; the others keep existing subscribers on older prices mapped to the plan. A plan with no price isn't offered.

Test it in Stripe test mode

  1. In Stripe test mode, create a recurring price for Pro and one for Team. Put their ids in STRIPE_PRICE_PRO and STRIPE_PRICE_TEAM in apps/server/.env.

  2. Set STRIPE_SECRET_KEY to your sk_test_... key.

  3. Forward webhooks to your local API with the Stripe CLI:

    stripe listen --forward-to localhost:4301/api/billing/webhook
    
  4. Set STRIPE_WEBHOOK_SECRET to the whsec_... it prints, and restart the server.

  5. Open an organisation's billing page, choose a plan and pay with a Stripe test card. The plan turns active once the webhook arrives.

What your customers see

The billing page at /organisations/<id>/billing shows the current plan, the plan cards, Manage billing (the Customer Portal), recent invoices and alerts. Every member sees the plan, its limits and any failed payment. Only owners and admins can change the plan or see invoices.

After Checkout succeeds, the page checks every 2 seconds for up to a minute until the webhook has recorded the plan. If a payment fails, owners and admins of the organisation see a banner on other pages too. A subscription that is past_due keeps its plan while Stripe retries the card.

The webhook is the source of truth

Only Stripe's webhook writes subscription state. No request from the browser can set a plan. Each event is verified against its signature, recorded once, and applied in one transaction, so a redelivered event changes nothing and an older event arriving late can't roll a subscription back. If anything fails, nothing is recorded, the webhook answers 500 and Stripe retries.

When you go live, add a webhook endpoint in Stripe at https://<your domain>/api/billing/webhook on API version 2026-10-28.endive, for exactly these events:

  • checkout.session.completed
  • customer.subscription.created, customer.subscription.updated, customer.subscription.deleted
  • invoice.paid, invoice.payment_failed
  • charge.refunded, charge.dispute.closed

Go live

  1. In Stripe live mode, create the live prices and set STRIPE_PRICE_PRO and STRIPE_PRICE_TEAM on server.
  2. Add the webhook endpoint above and set its STRIPE_WEBHOOK_SECRET.
  3. Set STRIPE_SECRET_KEY to your sk_live_... or rk_live_... key and redeploy.
  4. In the Customer Portal settings, allow payment method updates, cancellation and switching between the paid prices.
  5. Subscribe once and check the endpoint's delivery log shows 200s. The server warns if a live key is set outside production.

To change a price later, create the new price in Stripe, put its id first in the variable with the old id after a comma, update the label in billing.ts, and allow the new price in the Customer Portal.

Paid invoices also drive affiliate commissions. See The affiliate program.

Something unclear or missing? Ask us and we'll answer, then fix the page.