Payment Database
PostgreSQL database that is the system of record for payments and refunds.
What is this?
The Payment Database is the authoritative store for payments and refunds at Acme Inc. The Payment APIPayment APIServicev1.0.0Receives payment authorization requests from the Ordering domain and records the payment intent, kicking off the charge ...Subscribesauthorize-paymentOwnerpayments-platformMapRepoView docs and Payment WorkerPayment WorkerServicev1.0.0
Drives charges and refunds against the external payment processor and records the outcomes. It requests payments and ref...Publishespayment-requested, refund-requestedSubscribespayment-succeeded, payment-failedOwnerpayments-platformMapRepoView docs read from and write to it as payments are authorized, charged and refunded.
What does it store?
- Payments — one row per payment: id, order, amount, status and timestamps.
- Refunds — one row per refund: id, payment, amount, status and timestamps.
Schema
-- Payment Database — system of record for payments and refunds
CREATE TABLE payments ( payment_id UUID PRIMARY KEY DEFAULT gen_random_uuid(), order_id UUID NOT NULL, customer_id UUID, amount_cents INTEGER NOT NULL CHECK (amount_cents >= 0), currency CHAR(3) NOT NULL DEFAULT 'USD', status TEXT NOT NULL DEFAULT 'REQUESTED' CHECK (status IN ('REQUESTED', 'SUCCEEDED', 'FAILED')), created_at TIMESTAMPTZ NOT NULL DEFAULT now(), updated_at TIMESTAMPTZ NOT NULL DEFAULT now());
CREATE TABLE refunds ( refund_id UUID PRIMARY KEY DEFAULT gen_random_uuid(), payment_id UUID NOT NULL REFERENCES payments (payment_id), amount_cents INTEGER NOT NULL CHECK (amount_cents >= 0), status TEXT NOT NULL DEFAULT 'REQUESTED' CHECK (status IN ('REQUESTED', 'PROCESSED', 'FAILED')), created_at TIMESTAMPTZ NOT NULL DEFAULT now());
CREATE INDEX idx_payments_order ON payments (order_id);CREATE INDEX idx_payments_status ON payments (status);Retention
Payments and refunds are financial records and are retained for 7 years (see frontmatter) to meet accounting and audit requirements.