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:
| Plan | Price shown | Trial | Seats | Projects | Features |
|---|---|---|---|---|---|
| Free | $0 | None | 1 | 3 | None |
| Pro | $19 a month | 14 days | 5 | 25 | API access |
| Team | $49 a month | 14 days | 25 | No limit | API 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.
| Variable | Holds |
|---|---|
STRIPE_SECRET_KEY | A secret or restricted key. sk_test_... until you go live. |
STRIPE_WEBHOOK_SECRET | The signing secret (whsec_...) of your webhook endpoint. |
STRIPE_PRICE_PRO | The Stripe price id for Pro. |
STRIPE_PRICE_TEAM | The 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
-
In Stripe test mode, create a recurring price for Pro and one for Team. Put their ids in
STRIPE_PRICE_PROandSTRIPE_PRICE_TEAMinapps/server/.env. -
Set
STRIPE_SECRET_KEYto yoursk_test_...key. -
Forward webhooks to your local API with the Stripe CLI:
stripe listen --forward-to localhost:4301/api/billing/webhook -
Set
STRIPE_WEBHOOK_SECRETto thewhsec_...it prints, and restart the server. -
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.completedcustomer.subscription.created,customer.subscription.updated,customer.subscription.deletedinvoice.paid,invoice.payment_failedcharge.refunded,charge.dispute.closed
Go live
- In Stripe live mode, create the live prices and set
STRIPE_PRICE_PROandSTRIPE_PRICE_TEAMonserver. - Add the webhook endpoint above and set its
STRIPE_WEBHOOK_SECRET. - Set
STRIPE_SECRET_KEYto yoursk_live_...orrk_live_...key and redeploy. - In the Customer Portal settings, allow payment method updates, cancellation and switching between the paid prices.
- 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.


