Skip to content

Database Schema

All tables use ULID primary keys and configurable table names.

payment_gateways

Stores gateway definitions.

ColumnTypeDescription
idULID (PK)Primary key
namestring (unique)Gateway key (e.g., stripe)
driverstringDriver class name
display_namestring (nullable)Human-readable name
supportsJSON (nullable)Supported capabilities array
is_activebooleanWhether gateway is active
created_attimestamp
updated_attimestamp

payment_gateway_credentials

Encrypted credential storage with multi-tenant support.

ColumnTypeDescription
idULID (PK)Primary key
gateway_namestringGateway key
profilestringtest or live
tenant_idstring (nullable)Tenant isolation key
labelstring (nullable)Human-readable label
credentialstext (encrypted)Encrypted JSON credentials
is_activebooleanWhether credential set is active
effective_fromtimestamp (nullable)Start of time window
effective_totimestamp (nullable)End of time window
priorityintegerResolution order (higher = preferred)
created_attimestamp
updated_attimestamp

Indexes:

  • (gateway_name, profile, is_active) — Fast credential resolution
  • (gateway_name, profile, tenant_id, is_active) — Tenant-specific resolution
  • (effective_from, effective_to) — Time window filtering
  • priority — Priority ordering

payments

Core payment records.

ColumnTypeDescription
idULID (PK)Primary key
order_idstringApplication order ID
gateway_namestringGateway used
profilestringCredential profile
tenant_idstring (nullable)Tenant ID
statusstringPayment status enum value
amountdecimal(16,2)Payment amount
currencystring(3)ISO 4217 currency code
gateway_referencestring (nullable)Gateway transaction ID
idempotency_keystring (unique, nullable)Idempotency key
customer_emailstring (nullable)Customer email
customer_phonestring (nullable)Customer phone
canonical_payloadJSON (nullable)Full canonical payload snapshot
metadataJSON (nullable)Application metadata
created_attimestamp
updated_attimestamp

Indexes:

  • idempotency_key (unique)
  • order_id, gateway_name, gateway_reference, status, tenant_id
  • (gateway_name, status), (tenant_id, gateway_name, status), customer_email

payment_attempts

Per-create attempt history.

ColumnTypeDescription
idULID (PK)Primary key
payment_idULID (FK)→ payments.id
attempt_nounsigned intSequential attempt number
statusstringAttempt status
gateway_referencestring (nullable)Gateway reference for this attempt
request_payloadJSON (nullable)Request sent to gateway
response_payloadJSON (nullable)Response from gateway
errorsJSON (nullable)Error details
duration_msdecimal(10,2) (nullable)Request duration
created_attimestamp
updated_attimestamp

payment_webhook_events

Raw webhook storage for replay and audit.

ColumnTypeDescription
idULID (PK)Primary key
gateway_namestringOriginating gateway
payment_idULID (FK, nullable)→ payments.id
event_typestring (nullable)Parsed event type
gateway_referencestring (nullable)Gateway transaction reference
headersJSON (nullable)Raw HTTP headers
payloadJSON (nullable)Raw webhook body
signature_validbooleanSignature verification result
processedbooleanWhether webhook was processed
processed_attimestamp (nullable)Processing timestamp
created_attimestamp
updated_attimestamp

Idempotency index: (gateway_name, gateway_reference, event_type) — Prevents duplicate processing.

payment_refunds

Refund lifecycle records.

ColumnTypeDescription
idULID (PK)Primary key
payment_idULID (FK)→ payments.id
amountdecimal(16,2)Refund amount
currencystring(3)Currency code
statusstringRefund status
refund_referencestring (nullable)Gateway refund reference
reasonstring (nullable)Refund reason
request_payloadJSON (nullable)Refund request
response_payloadJSON (nullable)Gateway response
metadataJSON (nullable)Additional metadata
created_attimestamp
updated_attimestamp

payment_logs

Structured log storage.

ColumnTypeDescription
idULID (PK)Primary key
levelstringLog level
categorystringDot-notation category
messagetextHuman-readable message
gateway_namestring (nullable)Gateway name
profilestring (nullable)Profile
tenant_idstring (nullable)Tenant ID
payment_idULID (nullable)Payment ID
attempt_idULID (nullable)Attempt ID
context_flatJSON (nullable)Dot-notation flattened context
context_nestedJSON (nullable)Original nested context
occurred_attimestampEvent timestamp

Indexes: level, category, gateway_name, tenant_id, payment_id, occurred_at, (gateway_name, level)

Entity Relationships

payment_gateways ──┐
                   │ (by name)
payments ◄─────────┘

├── payment_attempts (1:N)
├── payment_webhook_events (1:N)
├── payment_refunds (1:N)
└── payment_logs (1:N)

payment_gateway_credentials (standalone, resolved by name+profile+tenant)

Released under the MIT License.