Double-Entry Ledger — $100 Sale Example

Every money movement produces a balanced journal entry. No funds change hands without a matching set of postings that sum to zero per currency.

Buyer pays $100.00 for Server Premium subscription JOURNAL ENTRY — SALE Dr. Cash / Processor Clearing $100.00 Cr. Deferred Revenue (seller) $85.00 Cr. Platform Revenue $15.00 Settlement PAYOUT Dr. Deferred Revenue $85.00 Cr. Seller Payable $85.00 PIPELINE payment_intents billing_events ✓ journal_entries subscription projection entitlement grants → Zero Zero

Billing Event Flow

NMI / value.io callback or billing source event
  → signature/authenticity verification
  → idempotent billing_events insert (source event id)
  → payment/commercial state + balanced ledger posting
  → subscription projection + transactional outbox
  → entitlement grants/revocations
  → PostgreSQL commit
  → Zero updates affected clients

Four Separate Records

Billing concerns are split into four tables with distinct responsibilities. Mixing these would create audit risk and make state debugging impossible.

RecordTablesPurpose
Immutable money ledger journal_entries, postings, ledger_accounts Every money movement, balanced, append-only
Payment execution payment_intents, provider_transactions Command execution, provider state tracking
Lifecycle state billing_subscriptions, dunning_attempts, refunds, disputes Commercial state machines for each subscription lifecycle
Entitlement projection entitlements, entitlement_grants Access rights derived from billing facts; safe for Zero to read

Dunning Policy

The hu2-baseline versioned dunning policy defines retry cadence and terminal conditions. Dunning policies are versioned — active subscriptions reference the policy version at time of enrollment.

AttemptTimingAction
1 Payment fails Retry immediately — transient network/processor failure
2 +24 hours Retry with account updater check
3 +72 hours Customer reminder email dispatched
4–6 Bounded cadence Retries with decline code classification
Terminal After policy window Grace period → access revocation

Key Invariants

No Billing Calls on Hot Paths

No NMI/value.io calls on login, sync-read, or mutation authorization paths. Billing state is a projection, not a real-time check gate.


V1 Scope & Exclusions

V1 Includes

NMI + value.io processors, subscriptions, seller payouts, affiliate commissions/reserves, 27-day account updater window, hu2-baseline dunning policy.

V1 Excludes

Trials, coupons, proration, subscription pauses, escrow/wallet, Ethoca dispute automation, crypto payments, gift card balances, non-NMI payment processors.


Research Links

Billing Service Spec (doc 11) → Final Recommendation (doc 00) →