Backend Development › Product Building Blocks
Invoices and Receipts
Generating immutable, numbered billing documents.
Also known as: invoices and receipts, invoices, receipts
Invoices and receipts are the documents that record what a customer was charged and why. A receipt confirms a payment happened; an invoice itemises what was billed (line items, tax, total) and is often required before payment or for business accounting. They’re generated by billing and must be accurate, consistent and retained.
billing event → invoice (line items, tax, total) → PDF → stored and sent
The important properties:
- Immutable once issued. An invoice is a financial record; it shouldn’t be regenerated differently each time it’s viewed. Generate it, store it (as a PDF and structured data), and serve that copy.
- Sequential numbering. Invoices typically need a gapless, sequential number per legal requirements in many jurisdictions — which is not what an auto-increment sequence with rollbacks gives you. Generate numbers deliberately.
- Line items and tax. An invoice itemises services, discounts and taxes so it’s auditable (see sales tax/VAT and coupons).
- Retention. Financial records must be kept for statutory periods; don’t delete them.
The classic mistakes:
- Regenerating invoices on view. Rendering the invoice fresh each time (from possibly-changed data) produces inconsistencies. Generate once, store, serve the stored version (see PDF generation).
- Non-sequential or reusable numbers. Using a database sequence that skips numbers, or reusing numbers, can violate invoicing rules in some jurisdictions. Implement numbering deliberately.
- Missing tax details. An invoice without the required tax breakdown (and tax ID) isn’t valid in many places; tax computation is part of invoicing.
- Invoice not matching the charge. If the invoice total and the actual payment differ (mis-applied discount, proration error), it’s an accounting problem. Keep them consistent (see ledger and proration).
- No immutability. Editing or overwriting an issued invoice destroys the record’s integrity; corrections should be new documents (credit notes), not edits.
- Deleting on account deletion. Financial records often must be retained despite an account deletion; don’t purge them.
- Not delivering them. Customers expect invoices/receipts by email or download; failing to send them causes support load (see sending email).
How to build it: on each billing event, generate an invoice with line items and tax, assign a proper sequence number, render and store an immutable PDF, deliver it, and retain it. It’s a subscription billing output with legal and accounting weight — treat the record as authoritative, not a view.