Skip to navigation

Credit grants

A credit grant adds credits in a credit currency to a customer’s balance. Most grants come from the prices your customer buys: a credit bundle grants credits each interval, and a top-up grants them once. You can also grant credits by hand, for goodwill or compensation. Each grant carries its own expiry, rollover and refill, so one balance can mix credits with different lifetimes and Paid still spends them in a fair, predictable order.

Use a credit grant to:

  • Sell credits with a recurring or one-time price that carries grants. See Grants from prices.
  • Give a usage allowance that resets, such as 50 messages every 4 hours, with a refill.
  • Make things right with goodwill or compensation credits, by granting credits by hand.
  • Track what’s left of each grant, and when it expires, by listing grants.

How grants work

  1. A grant arrives from a price on an order, at the start of each interval by default, or when you create one by hand.
  2. It adds an amount of credits to the customer’s shared balance, or to one seat’s balance.
  3. Usage spends it in the spend order: scoped grants first, then the credits forfeited soonest, then the oldest.
  4. It ends when it expires, after any rollover, or when you void it. Credits left at the end are forfeited with a ledger entry, so the ledger always reconciles.

Credit amounts are in the credit currency, as decimal strings with up to 15 decimal places.

Grants from prices

Add grants to a recurring or one-time price to make it grant credits. Adatum sells a yearly credit bundle on a sliding scale: 70¢ a credit up to 50,000, 65¢ up to 100,000 and 60¢ above that. One price covers every bundle size, because the order line’s quantity sets both the number of credits and the price on the curve.

Create a price in money, with a grants entry in the credit currency. grants on prices, and the credit grant endpoints, are in the credits=v1 beta; send Paid-Beta: credits=v1.

POST /v1/prices
{
"product": "adatum_platform",
"name": "Adatum credits",
"currency": "usd",
"type": "recurring",
"recurring": {
"interval": "year",
"unit": "credit",
"pricing": {
"type": "graduated",
"graduated": {
"tiers": [
{ "upTo": "50000", "unitAmount": "70" },
{ "upTo": "100000", "unitAmount": "65" },
{ "upTo": null, "unitAmount": "60" }
]
}
},
"grants": [
{
"creditCurrency": "adatum_credits",
"amountPerUnit": "1",
"expiresAfter": { "value": "12", "unit": "month" },
"rollover": { "maxAmount": null, "duration": { "value": "3", "unit": "month" } }
}
]
}
}

The price’s amounts are in cents, and amountPerUnit is in credits: one credit for each unit of the order line’s quantity.

An order line with quantity: 120000 on this price grants 120,000 credits each year, and costs:

TierCreditsAmount
Up to 50,000 at 70¢50,00050,000 × 70¢ = 3,500,000¢
50,001 to 100,000 at 65¢50,00050,000 × 65¢ = 3,250,000¢
Above 100,000 at 60¢20,00020,000 × 60¢ = 1,200,000¢
Total120,0007,950,000¢ = $79,500.00 a year

Each entry in grants, up to 5, becomes its own credit grant on the order:

FieldDescription
creditCurrencyThe credit currency granted.
amountPerUnitCredits per unit of the order line’s quantity, each interval. Or set unlimited: true for a grant whose spends are recorded but never run it down.
grantedOnWhen the credits arrive: activation (the default, at the start of each interval), invoiceFinalized or invoicePaid.
expiresAfterHow long each grant lasts, such as { "value": "12", "unit": "month" }. By default, until the order line ends, or never if the order has no end date.
rolloverKeeps unspent credits spendable for a duration past expiry, up to maxAmount (null for all of them). The rest is forfeited.
refillResets the grant to its full amount on a schedule. See Refills.
scopeLimits what the credits can pay for to some products or some prices, never both.
recipientcustomer (the default) for the shared balance, or seat to give each seat its own. seat needs a seat price.

A one-time price with grants is a top-up: it grants credits once, when it’s bought, such as by an amendment or an auto top-up.

A grant from a price names where it came from in source. grant is the index of the entry in the price’s grants list that made it, counting from 0:

"source": {
"type": "order",
"order": { "order": "ord_7Gk3Xs", "orderLine": "oli_2Wd8Nf", "price": "prc_5Hv1Lp", "grant": 0, "amendment": null }
}

Change the quantity mid-interval

When an amendment raises a bundle line’s quantity mid-interval, the extra credits are granted straight away for each entry in the price’s grants, prorated by day for the rest of the interval. They arrive as that entry’s grantedOn says. Each prorated grant expires and rolls over with the interval’s grant, and its source.order.amendment names the amendment.

Brightrail raises its yearly bundle from 20,000 to 30,000 credits with 73 days of the 365-day year left:

StepValue
Extra quantity30,000 - 20,000 = 10,000
Prorated credits10,000 × 1 credit × 73 ÷ 365 = 2,000 credits

Prorated credits are rounded down to 15 decimal places. Lowering the quantity never takes back credits already granted: the next interval’s grant uses the new quantity. A refilling grant gets no prorated grant: the new quantity sets its amount from its next window.

Refills

A grant with refill resets to its full amount every every, such as every 4 hours, until it expires. Unspent credits don’t carry over: the grant goes back to its amount, never above it. every is a whole number of hours, days or weeks, from 1 hour to 1 year.

Lucerne’s monthly plan gives each subscriber 2,000 messages a month plus 50 every 4 hours. One price carries both grants:

"grants": [
{
"creditCurrency": "messages",
"amountPerUnit": "2000",
"expiresAfter": { "value": "1", "unit": "month" }
},
{
"creditCurrency": "messages",
"amountPerUnit": "50",
"expiresAfter": { "value": "1", "unit": "month" },
"refill": { "every": { "value": "4", "unit": "hour" } }
}
]

The 4-hour allowance is spent first, because its credits are lost soonest. A subscriber who sends 70 messages in one window spends:

Step4-hour grantMonthly grant
Start of the window502,000
70 messages50 - 50 = 02,000 - (70 - 50) = 1,980
Next refill, with a refill entry of 50501,980

A window with no spend writes no ledger entry. A grant’s refilledAt and nextRefillAt say when its current window started and when it refills next, so you can show “refills in 1h 20m” in your app. refill can’t be combined with rollover or unlimited.

Grant credits by hand

Adatum gives Brightrail 5,000 credits of onboarding goodwill:

Create a credit grant with an Idempotency-Key header, which is required, so a retry never grants twice.

{
"customer": "cus_3Vb9Rk",
"creditCurrency": "adatum_credits",
"amount": "5000",
"expiresAt": "2027-06-30T00:00:00Z",
"reason": "Onboarding goodwill"
}

startsAt defaults to now and can be in the future. Leave out expiresAt, or send null, for credits that never expire. A manual grant can also set scope, rollover and refill.

The credit currency must not be archived. Manual grants are spent in the same order as grants from prices.

Track grants

List credit grants by customer, creditCurrency, seat, status, source.type (manual or order) or order to see each grant’s amount, what’s used and what’s available. For a refilling grant, used counts since its last refill.

statusThe grant
scheduledstarts in the future.
activecan be spent.
depletedhas nothing left. A refilling grant is active again at its next refill.
expiredhas passed its expiresAt, and any rollover.
voidedwas ended early.

How it bills

Brightrail renews its yearly bundle for 2027 with a quantity of 25,000, on the price above: 12 months’ expiry, and everything rolls over for 3 months.

DateWhat happensBrightrail’s credits
1 Jan 2027Bundle invoiced: 25,000 × 70¢ = 1,750,000¢ = $17,500.00. A grant of 25,000 arrives.25,000
During 2027Usage spends 21,000 credits.25,000 - 21,000 = 4,000
1 Jan 2028The 2027 grant reaches expiresAt; its 4,000 credits roll over until 1 April. The 2028 bundle is invoiced and grants 25,000.4,000 + 25,000 = 29,000
Jan to Mar 2028Usage spends 3,000 credits, all from the rolled-over credits, because they’re forfeited first.29,000 - 3,000 = 26,000
1 Apr 2028Rollover ends. The last 4,000 - 3,000 = 1,000 rolled-over credits are forfeited, with an expiry entry.26,000 - 1,000 = 25,000

Brightrail pays only for the bundles. Credits spent are never invoiced again, and nothing is billed as overage while the balance covers the usage.

Change or end a grant

Update a grant to change its reason or metadata, or to move its expiresAt later. expiresAt can’t move earlier, and an expired grant can’t be revived. The amount, credit currency, startsAt and refill can’t change: void the grant and create a new one instead.

Void a grant to end it early. What’s left is forfeited with a void ledger entry, so voiding a grant with credits left needs forfeitRemaining: true.