Payment Data Modeling
Last Updated: 2026-12-01 Status: Complete
Payment data modeling is the work of deciding which records a platform keeps, how they link, and which states they are allowed to move through. Get it wrong and every later feature (reporting, settlement, disputes, payouts) needs a workaround; get it right and the ledger, the API and the risk rules sit on stable ground. In this category you will build the entity model for a PayFac (platform, sub-merchant, location, terminal, principals, bank accounts, payments and disputes) and four explicit lifecycles with transition tables and enforcement code.
The two pages are meant to be read in order. The entity model defines what exists; the state machines define how it changes.
Quick Reference
| Topic | Decision |
|---|---|
| Hierarchy | Platform, sub-merchant (legal entity), location, terminal |
| Money | bigint minor units plus ISO 4217 code |
| Facts vs status | Immutable financial rows; mutable status with append-only history |
| Tenancy | Tenant id on every row; row-level security as a backstop |
| Lifecycles | Onboarding application, account status, payment, dispute, payout |
| Enforcement | Transition map, conditional update, history row and outbox event in one transaction |
| Late events | Deduplicate, compare with current state, ask the source of truth |
How the Pieces Fit
Learning Objectives
After this category you should be able to:
- Draw the tenant hierarchy and say what attaches at each level (pricing, settlement, risk, reporting).
- Model principals, bank accounts and fee-schedule assignment with effective dating.
- Separate payment intent from attempts, and model partial captures and refunds so totals are derived.
- Store money, currency, FX rate and identifiers so settlement files can be matched later.
- Write transition tables with guards and side effects for onboarding, payment, dispute and payout.
- Apply a transition atomically in NestJS and handle out-of-order events.
Topics
- Payment Platform Data Model — tenant hierarchy, principals, bank accounts, payment-side records, DDL and a NestJS DTO.
- Payment State Machines — four lifecycles, transition tables, enforcement code, late events and testing.
- Data Modeling Quiz — ten scenario questions on entity design and state machines.
Related Topics
- Platform Architecture Overview — the full module map
- Double-Entry Ledger — where these records become balanced journal entries
- Sub-Merchant Management — MIDs and sub-merchant identification
- Authorization Types — the authorization-level state machine
- Idempotency in Payments — the Unknown state and why keys stop at the API boundary