Delivered remotely for a business based in Auckland, New Zealand. Names withheld by agreement.
Project Overview
Industry: SMB Billing & Receivables Automation
Solution scope: A multi-tenant online billing platform and API built with Laravel, React, TypeScript, PostgreSQL, Redis, and Stripe to streamline quote-to-invoice workflows, recurring retainers, GST/tax calculation, and automated payment collection.
Context: Agencies, consultancies, trades, and subscription-service SMBs across Auckland and the wider Asia-Pacific market spend disproportionate administrative energy creating repetitive monthly invoices, tracking part-payments, and sending polite reminders to late payers. Generic accounting suites often treat billing as a secondary form buried under complex bookkeeping menus, whereas dedicated billing software prioritizes fast invoice assembly, frictionless client payment links, and clear cash-collection visibility.
Receivables & Billing Bottleneck
Manual invoice assembly drains billable hours. Repeating retainers, milestone installments, and ad-hoc expense pass-throughs force staff to clone old documents manually, increasing the risk of forgotten line items or stale billing dates.
Tax and rounding inconsistencies erode trust. Mixing percentage discounts, tax-inclusive versus tax-exclusive pricing, and multi-line rounding across spreadsheets frequently causes one-cent discrepancies that fail reconciliation against payment processor deposits.
Delayed follow-up slows cash conversion. Without structured reminder cadences, overdue invoices sit unnoticed until cash tightens, forcing owners to chase clients awkwardly weeks past due dates.
Clunky payment experiences discourage prompt settlement. Sending static PDF attachments with bare bank-account numbers pushes clients to defer payment until their next batch banking run, whereas one-click card or direct-debit links settle immediately.
Architectural Strategy
Freeze issued invoices as legal snapshots. A draft invoice may pull live defaults from customer profiles and product catalogs, yet the moment it is finalized, all tax rates, legal entity headers, and line descriptions commit as an immutable snapshot. Adjustments occur strictly via credit notes or voided states.
Separate money movement from document presentation. Payment allocations, refunds, and Stripe settlement events live in a clean PostgreSQL allocation ledger using integer minor units, ensuring partial payments, multi-invoice settlements, and credit balances reconcile deterministically.
Deliver an instant React invoice studio. Users edit line quantities, apply per-line taxes, toggle inclusive/exclusive modes, and preview live tax breakdowns inside a responsive React TypeScript interface without full-page reloads.
Offload PDF generation and dunning emails to Redis. Compiling branded PDFs and dispatching reminder batches execute asynchronously inside Laravel queue workers so issuing a batch of monthly retainers completes in seconds.
Core Capabilities
- Interactive quote-to-invoice builder: Converts approved estimates into numbered tax invoices with inline line-item sorting, per-line tax codes, and configurable payment terms.
- Automated recurring billing engine: Generates monthly, quarterly, or custom-interval invoices automatically, optionally charging saved customer payment methods via Stripe.
- Configurable dunning & reminder sequences: Dispatches polite pre-due nudges and escalating overdue notices with one-click payment links, pausing automatically once payment clears.
- Partial payments & credit note ledger: Allocates bank transfers, card settlements, and credit notes across single or multiple open invoices while tracking remaining balances.
- Zero-friction client billing portal: Lets end-clients inspect itemized PDFs, download past receipts, update saved cards, and settle balances online via signed access links.
- Real-time receivables aging: Categorizes outstanding balances into current, 30-day, 60-day, and 90-day buckets alongside tax summary exports for bookkeepers.
Technical Architecture
Laravel billing domain core. Structured into clear domain services for Invoicing, Schedules, Taxation, and Ledger Allocations, the Laravel API enforces strict state transitions (Draft → Issued → Partially Paid → Paid / Void) via domain state guards and FormRequest validation.
PostgreSQL financial persistence. PostgreSQL guarantees transactional atomicity when issuing numbered sequences—using per-tenant sequence counters locked during finalization—and enforces unique constraints on external Stripe event IDs and recurring period keys.
Redis asynchronous pipeline. Scheduled Laravel cron commands sweep active billing profiles hourly and enqueue discrete invoice-generation jobs onto Redis, alongside headless-Chromium PDF rendering jobs and webhook retry handlers.
React & Stripe checkout frontend. The TypeScript SPA powers both the internal SMB workspace and the streamlined client payment portal, embedding Stripe PaymentIntents with client-side confirmation and instant webhook-driven status updates.
Flow: SMB billing clerk / Client (React UI) → Laravel tenant & signature gate → PostgreSQL integer-cent invoice ledger → Redis PDF & dunning workers → Stripe payment settlement & webhook reconciliation
Technology Stack
| Category | Technology |
|---|---|
| Backend language | PHP 8 implementing integer-cent monetary arithmetic and strict invoicing state machines |
| Backend framework | Laravel driving multi-tenant billing APIs, scheduled billing runs, and webhook processors |
| Frontend framework | React with TypeScript powering interactive invoice builders, customer portals, and aging dashboards |
| Primary database | PostgreSQL persisting immutable invoice snapshots, line items, tax ledgers, and payment allocations |
| Queues & scheduler | Redis managing recurring invoice generation, email delivery, and dunning escalation retries |
| Payment gateway | Stripe PaymentIntents, hosted checkout links, and signed webhook event settlement |
| PDF rendering | Headless Chromium worker pipeline producing crisp, branded tax-invoice PDFs asynchronously |
| Authentication | Token-based API auth for internal teams plus cryptographically signed magic links for client portals |
| Testing framework | PHPUnit integration suites validating rounding edge cases, credit notes, and partial payments |
| Observability | Structured billing run logs, webhook failure dead-letter alerts, and reconciliation audit trails |
Engineering Trade-offs & Solutions
| Challenge | Solution |
|---|---|
| Sequential invoice numbering risked gaps or collisions during parallel batch runs | Assigned numbers only upon transition out of Draft using row-locked per-tenant sequence counters inside PostgreSQL. |
| Rounding differences between tax-inclusive and tax-exclusive lines caused ledger mismatches | Centralized all monetary calculations in integer-cent PHP value objects using deterministic half-up rounding rules. |
| Duplicate Stripe webhooks threatened to record double payments on an invoice | Persisted processed webhook event IDs under a unique PostgreSQL index before crediting invoice allocations. |
| Synchronous PDF generation slowed down bulk monthly retainer runs | Deferred PDF rendering to Redis queue workers and cached compiled documents until an invoice voids or settles. |
| Exposing client invoice links publicly risked enumeration of customer data | Protected client portal routes with HMAC-signed tokens tied to specific tenant and invoice UUIDs. |
| Editing recurring templates risked altering already-issued historical invoices | Separated recurring template definitions from finalized invoice snapshots so past documents stay untouched. |
Security & Reliability
Strict tenant and portal scoping. Internal SMB users authenticate with scoped roles distinguishing read-only bookkeepers from billing administrators who can issue credits or refunds. Client payment URLs expose only the authorized invoice or statement using non-sequential UUIDs and cryptographic signatures.
Verified payment webhook ingestion. Incoming Stripe webhook handlers verify cryptographic signatures against rotating secrets and execute inside database transactions so payment status changes and ledger entries never diverge.
Resilient scheduled billing runs. If an email provider or PDF worker experiences temporary downtime, failed side-effect jobs re-queue automatically without rolling back finalized invoice records or triggering duplicate charges.
Performance & Scale
Batch-chunked recurring schedules. Nightly and hourly billing sweeps stream due recurring profiles in small cursor chunks rather than loading large tenant collections into memory, fanning out individual invoice compilations across parallel Redis workers.
Indexed receivables aging queries. Composite PostgreSQL indexes on (tenant_id, status, due_date) keep aged receivables summaries and overdue dunning filters responsive even as multi-year invoice archives grow.
Operational Outcomes
- Consistent on-time billing cadence: Automated retainer schedules eliminate missed billing cycles and manual month-end invoice rushes.
- Cleaner cash-flow visibility: Real-time aging views and instant payment reconciliation replace guesswork over which invoices remain unpaid.
- Faster client settlement: Embedded Stripe checkout links and automated polite reminders remove friction between invoice delivery and payment receipt.
- Bookkeeper-ready financial accuracy: Integer-cent arithmetic, locked tax snapshots, and clean credit note trails produce reconciliation-ready ledgers for accountants.