Skip to content
Hardcount
Run it locally
Pre-1.0 · one maintainer · Stripe and cards only · no SDKs (client libraries) yet · no production users yet. Docs describe v0.12.0 (30 Nov 2026) · What’s new →

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.

Hardcount makes a subscription’s invoice when a billing period ends:

  1. The period ends, for example at 00:00 on July 1.
  2. Hardcount waits the invoice grace period, INVOICE_GRACE_PERIOD, so usage that arrives a little late is still billed. It is 1 hour by default.
  3. The next billing run makes the invoice. The run is hourly, or every 5 minutes when APP_ENV is local or 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 /v1/invoices, 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.

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_status: where its card payment stands. See Payments.

Each route is under /v1/invoices/{id}.

From Route To Webhook
draft POST …/finalize finalized invoice.finalized
draft, a top-up Its payment: POST …/collect, the customer paying on its page, or POST …/record-payment paid invoice.paid when the payment settles
finalized Hardcount collects it: credit, then the card paid invoice.paid; payment.succeeded for a card payment
finalized, uncollectible POST …/record-payment, for a payment made outside Hardcount paid invoice.payment_recorded and invoice.paid
draft, finalized, uncollectible POST …/void voided invoice.voided
finalized POST …/mark-uncollectible uncollectible invoice.marked_uncollectible
  • A paid invoice 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, usually payment_in_flight. Wait for the payment to settle (Payments). An invoice whose payment is unknown can 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.finalized once, like a draft you finalize.

Hardcount works out an invoice in this order:

  1. Usage. Each meter adds up the period’s events. Each price takes its events (Meters and prices).
  2. 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.
  3. Subtotal. The lines added together, in subtotal_cents.
  4. Tax. Worked out on the subtotal by your tax setup, in tax_amount_cents (Tax).
  5. Total. Subtotal plus tax, in total_amount_cents. At first, amount_due_cents is the same.

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:

  1. Credit. Any credit the customer holds in the invoice’s currency lowers amount_due_cents, and credits_applied_cents shows by how much. The total does not change, and credit pays the tax too.
  2. Card. What is still due is charged to the customer’s saved card (Payments).

Because credit comes after finalizing, the invoice.finalized webhook shows the amount due before credit. invoice.paid shows the final split.

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_cents 2,000 + 300 + 262 + 60 2,622
tax_amount_cents 10% of 2,622 = 262.2, rounded 262
total_amount_cents 2,622 + 262 2,884
credits_applied_cents the $10.00 of credit 1,000
amount_due_cents 2,884 − 1,000 1,884

The card is charged $18.84. When it succeeds, amount_paid_cents is 1,884 and amount_due_cents is 0. The total stays $28.84.

  • Due date. due_at is 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: GET /v1/invoices/{id}/pdf, or ⋯ then Download PDF on the invoice page in the dashboard.
  • Hosted invoice page: a public page for one issued invoice, which the customer opens without signing in. Its address is HOSTED_INVOICE_BASE_URL + /invoice/ + the invoice’s public_token. 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:
    • 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_INVOICE_BASE_URL, the page’s own address, for Stripe to send the customer back to;
    • Stripe has not refused the amount as below its minimum charge (what to do).

A credit note lowers what a customer owes on an invoice. Create one with POST /v1/credit-notes on a finalized or paid invoice. It is a draft until you issue it with POST /v1/credit-notes/{id}/issue, or at once with "auto_issue": true. Only a draft credit note can be voided.

  • On an unpaid invoice, it lowers amount_due_cents. If nothing is left due, the invoice is marked 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.
Event When
invoice.finalized The invoice is issued. It shows the amount before credit.
invoice.paid Nothing is left due, whatever paid it.
invoice.payment_recorded You recorded a payment made outside Hardcount.
invoice.voided The invoice is voided.
invoice.marked_uncollectible The invoice is written off.
payment.succeeded, payment.failed 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