Invoices
An invoice is the bill for one customer: what they used and what they owe. This page covers when Hardcount makes one, how it works out the total, how an invoice moves from draft to paid, and what it sends your app at each step.
When Hardcount makes an invoice
Section titled “When Hardcount makes an invoice”Hardcount makes a subscription’s invoice when a billing period ends:
- The period ends, for example at 00:00 on July 1.
- Hardcount waits the invoice grace period,
INVOICE_, so usage that arrives a little late is still billed. It is 1 hour by default.GRACE_ PERIOD - The next billing run makes the invoice. The run is hourly, or every 5
minutes when
APP_ENVislocalor not set.
So by default the invoice appears 1 to 2 hours after the period ends. A period with nothing to bill makes no invoice.
Hardcount also makes an invoice:
- for the part of a period before a cancel;
- on the first day, for a plan whose base fee is billed in advance.
A period’s usage is billed once: on the invoice at the period’s end, or on the invoice of a cancel. To limit what a customer can owe before then, sell prepaid credit and stop usage when credit runs out.
You make one-off invoices yourself, for example to bill late usage:
POST /, then add lines and finalize it. A top-up, the invoice
that sells prepaid credit, is made with the same call and one credit line.
Its payment issues it, so you never finalize it
(Sell prepaid credit).
More: Usage events: late usage.
Statuses
Section titled “Statuses”| Status | What it means |
|---|---|
draft |
Not issued. Nothing is charged or emailed. You can add lines to a one-off draft. A subscription’s draft keeps the lines and the tax that the billing run gave it. |
finalized |
Issued and owed. The dashboard shows it as Open while money is due. |
paid |
Settled, by card, by credit, by a credit note (a document that lowers what the customer owes), or by a payment you recorded. |
voided |
Canceled, as if it never existed. |
uncollectible |
Written off: Hardcount stops collecting it, but keeps it in your records. |
A period’s invoice is made already finalized. It stays a draft only
while its tax cannot be worked out yet. A one-off invoice starts as a
draft. A top-up stays a draft, with no number, until it is paid.
Beside its status, an invoice has a payment_: where its card
payment stands. See Payments.
How an invoice changes
Section titled “How an invoice changes”Each route is under /.
| From | Route | To | Webhook |
|---|---|---|---|
draft |
POST …/ |
finalized |
invoice. |
draft, a top-up |
Its payment: POST …/, the customer paying on its page, or POST …/ |
paid |
invoice. when the payment settles |
finalized |
Hardcount collects it: credit, then the card | paid |
invoice.; payment. for a card payment |
finalized, uncollectible |
POST …/, for a payment made outside Hardcount |
paid |
invoice. and invoice. |
draft, finalized, uncollectible |
POST …/ |
voided |
invoice. |
finalized |
POST …/ |
uncollectible |
invoice. |
- A
paidinvoice cannot be voided. Issue a credit note instead. - While a card payment may still go through, a void, a write-off or a
recorded payment is refused with a
409, usuallypayment_. Wait for the payment to settle (Payments). An invoice whose payment isin_ flight unknowncan still be written off a few minutes after the charge. - A void gives back any credit the invoice used, to the credit grants it came from (Credits).
- A draft sends no webhook. A period’s invoice that is made already
finalized sends
invoice.once, like a draft you finalize.finalized
How the total is worked out
Section titled “How the total is worked out”Hardcount works out an invoice in this order:
- Usage. Each meter adds up the period’s events. Each price takes its events (Meters and prices).
- Lines. Each price with usage becomes a line, and the base fee is a line of its own. Each line is rounded to whole cents once, half to the even cent. A price with no usage makes no line.
- Subtotal. The lines added together, in
subtotal_.cents - Tax. Worked out on the subtotal by your tax setup, in
tax_(Tax).amount_ cents - Total. Subtotal plus tax, in
total_. At first,amount_ cents amount_is the same.due_ cents
With tax-inclusive pricing (Settings → Tax), your prices already hold the tax. Hardcount then takes the tax out of each line instead of adding it on top. So the subtotal is lower than the sum of the line prices, and the total equals that sum.
Then, right after the invoice is finalized, Hardcount collects it:
- Credit. Any credit the customer holds in the invoice’s currency
lowers
amount_, anddue_ cents credits_shows by how much. The total does not change, and credit pays the tax too.applied_ cents - Card. What is still due is charged to the customer’s saved card (Payments).
Because credit comes after finalizing, the invoice. webhook
shows the amount due before credit. invoice. shows the final split.
Worked example
Section titled “Worked example”A June invoice has a $20.00 base fee and three usage lines of $3.00, $2.62 and $0.60. The account uses a fixed 10% tax rate. The customer holds $10.00 of prepaid credit in USD.
| Field | Sum | Value |
|---|---|---|
subtotal_ |
2,000 + 300 + 262 + 60 | 2,622 |
tax_ |
10% of 2,622 = 262.2, rounded | 262 |
total_ |
2,622 + 262 | 2,884 |
credits_ |
the $10.00 of credit | 1,000 |
amount_ |
2,884 − 1,000 | 1,884 |
The card is charged $18.84. When it succeeds, amount_ is 1,884
and amount_ is 0. The total stays $28.84.
Due date and number
Section titled “Due date and number”- Due date.
due_atis the issue date plus your payment terms: 30 days unless you change the setting, from 0 (due on receipt) to 365. New invoice in the dashboard starts at the setting, and you can pick other terms for that one invoice. - Number. Each invoice gets the next number in its mode, such as
HC-000001. Test and live mode count apart. The prefix is a setting. The number is taken in the same write that saves the invoice, so a create that fails uses no number and leaves no gap.
PDF and the hosted invoice page
Section titled “PDF and the hosted invoice page”- PDF:
GET /, or ⋯ then Download PDF on the invoice page in the dashboard.v1/ invoices/ {id}/ pdf - Hosted invoice page: a public page for one issued invoice, which the
customer opens without signing in. Its address is
HOSTED_+INVOICE_ BASE_ URL /+ the invoice’sinvoice/ public_. A draft has no page, except a top-up: its page is where the customer pays it. Invoice emails link to the page. The page has a Pay button, which opens Stripe Checkout, when all of these hold:token - the invoice is
finalized, so not paid, voided or written off; - money is due;
- no payment is in flight;
- Stripe is connected in the invoice’s mode;
- the server has
HOSTED_, the page’s own address, for Stripe to send the customer back to;INVOICE_ BASE_ URL - Stripe has not refused the amount as below its minimum charge (what to do).
- the invoice is
Credit notes
Section titled “Credit notes”A credit note lowers what a customer owes on an invoice. Create one with
POST / on a finalized or paid invoice. It is a draft
until you issue it with POST /, or at once with
"auto_. Only a draft credit note can be voided.
- On an unpaid invoice, it lowers
amount_. If nothing is left due, the invoice is markeddue_ cents paid. If the credit note is for more than what is still due, the extra part gives back credit that the invoice used. That credit returns to the credit grants it came from (Credits). - On a paid invoice, its total is split between a refund to the card, credit to the customer’s balance, and money you returned outside Hardcount. With no split given, all of it goes to the credit balance.
Webhooks
Section titled “Webhooks”| Event | When |
|---|---|
invoice. |
The invoice is issued. It shows the amount before credit. |
invoice. |
Nothing is left due, whatever paid it. |
invoice. |
You recorded a payment made outside Hardcount. |
invoice. |
The invoice is voided. |
invoice. |
The invoice is written off. |
payment., payment. |
A card charge succeeded or failed (Payments). |
More: every event, with an example message: Webhook events.
Next: how prepaid credit lowers an invoice: Credits.
Stuck, or found a bug? Ask in Discussions · Open an issue