Credits
Credit is money a customer can spend on future invoices, such as prepaid credit they bought or free credit you gave them. This page covers how credit is added, the order in which it pays invoices, when it expires, and how your app reads what is left.
Think of a gift card with several top-ups. Each top-up is its own block, and each invoice spends from the blocks in a fixed order.
The credit ledger
Section titled “The credit ledger”Each customer’s credit is a ledger: a list of entries, one for each change.
| Entry | What it is | Who writes it |
|---|---|---|
grant |
Credit added: a block that invoices can spend. | You, or Hardcount for a prepaid commit or a credit note (a document that lowers what a customer owes on an invoice) |
usage |
Credit an invoice spent. | Hardcount |
expiry |
The unspent part of a block that passed its expiry date. | Hardcount |
adjustment |
A correction, up or down. | You, or Hardcount when it takes back prepaid-commit credit |
The balance is kept per currency, and credit pays only invoices in its own currency. A customer with USD and EUR credit has two balances, which are never added together or converted.
Read them with:
GET /: the settled balance per currency. It changes only when an invoice, grant, adjustment or expiry is written; usage not invoiced yet does not lower it (the live balance).v1/ credits/ balance/ {customer_ id} GET /: every entry.v1/ credits/ ledger/ {customer_ id} GET /: each block, with what is used, what is left and when it expires.v1/ credits/ grants/ {customer_ id}
Adding credit
Section titled “Adding credit”There are three ways:
- A grant:
POST /withv1/ credits/ grant customer_,id currency,amount_(up to 100,000,000, so $1,000,000), acents description, and optionallyexpires_andat "grant_. Use it for goodwill credit or free promotional credit.kind": "promotional" - A prepaid commit: the customer pays up front on a top-up and gets credit when it is paid. See Prepaid commits.
- An adjustment:
POST /with a positive or negativev1/ credits/ adjust amount_. An adjustment down that is larger than the balance is refused withcents 422.
Hardcount also adds credit itself, for a credit note that gives credit to the balance.
The order credit is spent
Section titled “The order credit is spent”When an invoice spends credit, it takes from the blocks in this order:
- Promotional credit first, so free credit is used before any other credit.
- Then the block that expires soonest. A block with no expiry comes last.
- Then the oldest block.
Only blocks in the invoice’s currency count, and a block past its expiry is skipped.
When credit pays an invoice
Section titled “When credit pays an invoice”Credit pays an invoice right after it is issued, before any card charge:
- It lowers
amount_, anddue_ cents credits_shows by how much. The invoice’s total does not change.applied_ cents - It pays the whole amount due, tax included.
- If credit covers it all, the invoice is marked
paidand no card is charged. - Each payment retry uses any credit the customer got since the last try. So credit you add later can pay an older unpaid invoice.
- An invoice that sells a prepaid commit is never paid with credit.
Expiry
Section titled “Expiry”A block with an expires_ cannot be spent after that time. Hardcount’s
billing run writes an expiry entry for its unspent part. A block past its
date is never spent, even before that entry is written.
One exception: a block still valid when a period ends, or one that expires at that moment, pays that period’s invoice, even when the invoice is built after the block expires. It is retired once the period’s invoice has drawn on it, and it stays in the ledger balance until then. No later invoice draws from it (ADR-071 §2).
Credit given back
Section titled “Credit given back”When a void, or a credit note on an unpaid invoice, gives back credit the invoice spent, the credit goes back to the blocks it came from, with their expiry and kind. A share whose block has already expired expires at once. A credit note on a paid invoice always raises the balance by its full credit amount.
Prepaid commits
Section titled “Prepaid commits”A prepaid commit is credit the customer pays for up front, such as “pay $9,000, get $10,000 of credit”. You sell it on a top-up: a one-off invoice whose only line is the commit line.
unit_is what the customer pays;amount_ cents commit_is the credit they get, and can be more.granted_ cents
A top-up is a draft with no number until it is paid. When it is paid, by
the saved card, on its hosted page or recorded by you, it is numbered and
issued, and the customer gets a block of kind commit. The block expires
topup_ after the payment, as the setting stood when the
top-up was made; unset, it never expires. The purchase is not taxed; the
usage the credit pays for is. To withdraw a top-up nobody paid, void it: it
granted nothing.
More: Sell prepaid credit, with every call and what the customer sees, and tax on prepaid credit.
Worked example: $10,000 of credit, one month of usage
Section titled “Worked example: $10,000 of credit, one month of usage”A customer buys a commit: they pay $9,000 and get $10,000 of credit, with no expiry. You also grant them $500 of promotional credit that expires on December 31. Their USD blocks:
| Block | Kind | Amount | Expires |
|---|---|---|---|
| 1 | commit |
$10,000.00 | never |
| 2 | promotional |
$500.00 | December 31 |
In July they use $1,200.00 of tokens. With 10% tax, the July invoice is $1,200.00 + $120.00 = $1,320.00. It is issued on August 1 and spends credit in order:
- Block 2 first, because it is promotional: $500.00. Nothing is left in it.
- Then block 1: $1,320.00 − $500.00 = $820.00. $9,180.00 is left.
The invoice shows credits_ 132,000 and amount_
0, so it is paid and no card is charged. The customer’s balance is now
$10,500.00 − $1,320.00 = $9,180.00.
If you void that July invoice later, its $1,320.00 goes back: $500.00 to block 2, still expiring on December 31, and $820.00 to block 1.
Your app’s view: the live balance
Section titled “Your app’s view: the live balance”The settled balance changes only when an invoice, grant, adjustment or
expiry is written. Usage not invoiced yet does not lower it. To know what a
customer can still spend right now, read the live balance:
GET /. It subtracts the period’s
usage not yet invoiced.
To stop serving a customer whose credit has run out, see Stop usage when credit runs out.
Webhooks
Section titled “Webhooks”| Event | When |
|---|---|
credit. |
A currency’s balance falls below the low-balance threshold in your settings. With no threshold set, it is never sent. |
credit. |
A currency’s balance reaches 0. |
credit. |
A currency’s balance goes back above 0. |
credit. |
A credit note took back commit credit. |
These follow the settled balance, so they can come weeks after the live balance reached 0. Use them for top-up reminders, not to stop usage.
More: every event, with an example message: Webhook events.
Next: the payments that settle what credit does not cover: Payments.
Stuck, or found a bug? Ask in Discussions · Open an issue