Grants
A plan allowance is the plan’s
monthlyCredits; a pack grants its creditAmount.
Creating a customer grants nothing. A customer can hold pack credits with no plan at all.
Spend order
Whentrack records a use, Ledger spends grants in this order:
- Plan allowances, the one that expires soonest first. After an upgrade, the old plan’s leftover credits expire first, so they’re spent before the new plan’s.
- Credit packs and manual adjustments, the one that expires soonest first, then oldest first. Packs never expire, so they’re kept for last.
- Overage, on a paid Sandbox plan with overage terms, up to the customer’s monthly cap.
track refuses it and charges nothing.
Worked example
A customer on Pro (1,000 credits a month) has bought one 500-credit pack, then tracks 1,200 credits of usage this period:
On Dec 7 Pro renews: a new allowance of 1,000 arrives and the old one expires. The balance becomes 1,300, and the pack’s 300 credits wait until the new allowance is spent.
A check reads the balance without reserving anything, so two requests can both see
allowed: true for the last credit; track decides each in its own transaction, and one of them gets 409 insufficient_credits. Balances shows how to read a customer’s balance.
Next steps
Gating features
Gate features on the balance and record each use once.
Billing lifecycle
When paid grants arrive, renew and end.