ForhoppPay Connect - Database Schema Documentation
Overview
This document provides the complete database schema for ForhoppPay Connect, including all tables, relationships, constraints, and indexes. The schema is designed for PostgreSQL 13+ and uses the forhopppay schema namespace.
Entity Relationship Diagram
┌─────────────────────┐ ┌─────────────────────────┐
│ forhopppay_accounts│ │ merchant_profiles │
│ (existing) │◄──────│ │
│ │ 1:1 │ - business_name │
│ - id │ │ - payout_schedule │
│ - user_id │ │ - default_currency │
└─────────┬───────────┘ └─────────────────────────┘
│
│ 1:N
▼
┌─────────────────────┐ ┌─────────────────────────┐
│ merchant_api_keys │ │ merchant_webhooks │
│ │ │ │
│ - publishable_key │ │ - endpoint_url │
│ - secret_key_hash │ │ - secret │
│ - environment │ │ - events[] │
└─────────┬───────────┘ └───────────┬─────────────┘
│ │
│ 1:N │ 1:N
▼ ▼
┌─────────────────────┐ ┌─────────────────────────┐
│ merchant_charges │ │ merchant_webhook_ │
│ │ │ deliveries │
│ - charge_id │ │ │
│ - amount_cents │ │ - event_id │
│ - status │ │ - status │
│ - idempotency_key │ │ - attempt_count │
└─────────┬───────────┘ └─────────────────────────┘
│
│ 1:N
▼
┌─────────────────────┐ ┌─────────────────────────┐
│ merchant_refunds │ │ merchant_payouts │
│ │ │ │
│ - refund_id │ │ - payout_id │
│ - amount_cents │ │ - amount_cents │
│ - status │ │ - status │
└─────────────────────┘ └─────────────────────────┘
Tables
1. merchant_api_keys
Stores API key pairs for merchant authentication.
CREATE TABLE forhopppay.merchant_api_keys (
id BIGSERIAL PRIMARY KEY,
account_id BIGINT NOT NULL REFERENCES forhopppay.forhopppay_accounts(id),
name VARCHAR(100) NOT NULL,
publishable_key VARCHAR(50) NOT NULL UNIQUE,
secret_key_hash VARCHAR(255) NOT NULL,
environment VARCHAR(10) NOT NULL CHECK (environment IN ('LIVE', 'TEST')),
permissions TEXT[] DEFAULT ARRAY['charges:write', 'charges:read', 'webhooks:write', 'webhooks:read'],
rate_limit_per_second INTEGER DEFAULT 100,
last_used_at TIMESTAMP,
revoked_at TIMESTAMP,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP,
CONSTRAINT uk_merchant_api_keys_publishable UNIQUE (publishable_key)
);
-- Indexes
CREATE INDEX idx_merchant_api_keys_account ON forhopppay.merchant_api_keys(account_id);
CREATE INDEX idx_merchant_api_keys_publishable ON forhopppay.merchant_api_keys(publishable_key);
CREATE INDEX idx_merchant_api_keys_active ON forhopppay.merchant_api_keys(account_id)
WHERE revoked_at IS NULL;
Key Format:
- Publishable:
pk_live_[32 alphanumeric]orpk_test_[32 alphanumeric] - Secret:
sk_live_[32 alphanumeric]orsk_test_[32 alphanumeric]
Security:
- Secret keys stored as bcrypt hashes (never plaintext)
- Soft delete via
revoked_attimestamp - Maximum 10 active keys per merchant
2. merchant_profiles
Stores merchant business information and payout settings.
CREATE TABLE forhopppay.merchant_profiles (
id BIGSERIAL PRIMARY KEY,
account_id BIGINT NOT NULL UNIQUE REFERENCES forhopppay.forhopppay_accounts(id),
business_name VARCHAR(255) NOT NULL,
business_url VARCHAR(500),
support_email VARCHAR(255) NOT NULL,
support_phone VARCHAR(50),
logo_url VARCHAR(500),
brand_color VARCHAR(7),
payout_schedule VARCHAR(20) NOT NULL DEFAULT 'DAILY'
CHECK (payout_schedule IN ('DAILY', 'WEEKLY', 'MONTHLY')),
payout_threshold_cents BIGINT DEFAULT 0,
default_currency VARCHAR(3) DEFAULT 'USD',
statement_descriptor VARCHAR(22),
connect_enabled BOOLEAN DEFAULT FALSE,
connect_enabled_at TIMESTAMP,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP
);
-- Indexes
CREATE INDEX idx_merchant_profiles_account ON forhopppay.merchant_profiles(account_id);
Payout Schedules:
DAILY: Processed at 00:00 UTCWEEKLY: Processed Monday 00:00 UTCMONTHLY: Processed 1st of month 00:00 UTC
3. merchant_charges
Stores payment charges created through the Connect API.
CREATE TABLE forhopppay.merchant_charges (
id BIGSERIAL PRIMARY KEY,
charge_id VARCHAR(50) NOT NULL UNIQUE,
merchant_account_id BIGINT NOT NULL REFERENCES forhopppay.forhopppay_accounts(id),
api_key_id BIGINT REFERENCES forhopppay.merchant_api_keys(id),
amount_cents BIGINT NOT NULL,
currency VARCHAR(3) NOT NULL DEFAULT 'USD',
description VARCHAR(500),
metadata JSONB,
status VARCHAR(30) NOT NULL DEFAULT 'PENDING'
CHECK (status IN ('PENDING', 'AUTHORIZED', 'CAPTURED', 'FAILED',
'VOIDED', 'REFUNDED', 'PARTIALLY_REFUNDED', 'EXPIRED', 'DISPUTED')),
payment_method VARCHAR(30),
payment_method_details JSONB,
payment_id BIGINT REFERENCES forhopppay.payments(id),
external_reference VARCHAR(255),
return_url VARCHAR(500),
cancel_url VARCHAR(500),
checkout_url VARCHAR(500),
idempotency_key VARCHAR(100),
environment VARCHAR(10) NOT NULL DEFAULT 'LIVE' CHECK (environment IN ('LIVE', 'TEST')),
fee_amount_cents BIGINT DEFAULT 0,
net_amount_cents BIGINT,
captured_at TIMESTAMP,
refunded_at TIMESTAMP,
expires_at TIMESTAMP,
disputed_at TIMESTAMP,
dispute_id BIGINT,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP,
CONSTRAINT uk_merchant_charges_idempotency UNIQUE (merchant_account_id, idempotency_key)
);
-- Indexes
CREATE INDEX idx_merchant_charges_merchant ON forhopppay.merchant_charges(merchant_account_id);
CREATE INDEX idx_merchant_charges_charge_id ON forhopppay.merchant_charges(charge_id);
CREATE INDEX idx_merchant_charges_status ON forhopppay.merchant_charges(status);
CREATE INDEX idx_merchant_charges_created ON forhopppay.merchant_charges(created_at);
CREATE INDEX idx_merchant_charges_expires ON forhopppay.merchant_charges(expires_at)
WHERE status = 'PENDING';
Charge ID Format: ch_[32 alphanumeric characters]
Status Transitions:
PENDING → AUTHORIZED → CAPTURED → REFUNDED
→ FAILED → PARTIALLY_REFUNDED
→ EXPIRED
AUTHORIZED → VOIDED (7 days timeout)
4. merchant_refunds
Stores refund records for charges.
CREATE TABLE forhopppay.merchant_refunds (
id BIGSERIAL PRIMARY KEY,
refund_id VARCHAR(50) NOT NULL UNIQUE,
charge_id BIGINT NOT NULL REFERENCES forhopppay.merchant_charges(id),
amount_cents BIGINT NOT NULL,
reason VARCHAR(100),
status VARCHAR(20) NOT NULL DEFAULT 'PENDING'
CHECK (status IN ('PENDING', 'SUCCEEDED', 'FAILED')),
external_reference VARCHAR(255),
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP
);
-- Indexes
CREATE INDEX idx_merchant_refunds_charge ON forhopppay.merchant_refunds(charge_id);
CREATE INDEX idx_merchant_refunds_refund_id ON forhopppay.merchant_refunds(refund_id);
Refund ID Format: re_[32 alphanumeric characters]
5. merchant_webhooks
Stores webhook endpoint configurations.
CREATE TABLE forhopppay.merchant_webhooks (
id BIGSERIAL PRIMARY KEY,
account_id BIGINT NOT NULL REFERENCES forhopppay.forhopppay_accounts(id),
endpoint_url VARCHAR(500) NOT NULL,
secret VARCHAR(100) NOT NULL,
events TEXT[] NOT NULL DEFAULT ARRAY['*'],
description VARCHAR(255),
active BOOLEAN DEFAULT TRUE,
failing_since TIMESTAMP,
consecutive_failures INTEGER DEFAULT 0,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP,
CONSTRAINT uk_merchant_webhooks_url UNIQUE (account_id, endpoint_url)
);
-- Indexes
CREATE INDEX idx_merchant_webhooks_account ON forhopppay.merchant_webhooks(account_id);
CREATE INDEX idx_merchant_webhooks_active ON forhopppay.merchant_webhooks(active);
Secret Format: whsec_[32 alphanumeric characters]
Supported Events:
charge.created,charge.completed,charge.failedcharge.refunded,charge.disputedpayout.created,payout.completed,payout.failed*(all events)
6. merchant_webhook_deliveries
Tracks webhook delivery attempts and status.
CREATE TABLE forhopppay.merchant_webhook_deliveries (
id BIGSERIAL PRIMARY KEY,
webhook_id BIGINT NOT NULL REFERENCES forhopppay.merchant_webhooks(id),
event_id VARCHAR(50) NOT NULL,
event_type VARCHAR(50) NOT NULL,
payload JSONB NOT NULL,
status VARCHAR(20) NOT NULL DEFAULT 'PENDING'
CHECK (status IN ('PENDING', 'DELIVERED', 'FAILED')),
http_status_code INTEGER,
response_body TEXT,
attempt_count INTEGER DEFAULT 0,
next_retry_at TIMESTAMP,
delivered_at TIMESTAMP,
created_at TIMESTAMP NOT NULL DEFAULT NOW()
);
-- Indexes
CREATE INDEX idx_webhook_deliveries_webhook ON forhopppay.merchant_webhook_deliveries(webhook_id);
CREATE INDEX idx_webhook_deliveries_status ON forhopppay.merchant_webhook_deliveries(status);
CREATE INDEX idx_webhook_deliveries_retry ON forhopppay.merchant_webhook_deliveries(next_retry_at)
WHERE status = 'PENDING';
Event ID Format: evt_[24 alphanumeric characters]
Retry Schedule:
| Attempt | Delay |
|---|---|
| 1 | 1 minute |
| 2 | 5 minutes |
| 3 | 30 minutes |
| 4 | 2 hours |
| 5 | 24 hours |
7. merchant_payouts
Stores merchant payout records.
CREATE TABLE forhopppay.merchant_payouts (
id BIGSERIAL PRIMARY KEY,
payout_id VARCHAR(50) NOT NULL UNIQUE,
merchant_account_id BIGINT NOT NULL REFERENCES forhopppay.forhopppay_accounts(id),
amount_cents BIGINT NOT NULL,
fee_cents BIGINT DEFAULT 0,
net_amount_cents BIGINT NOT NULL,
currency VARCHAR(3) NOT NULL DEFAULT 'USD',
status VARCHAR(20) NOT NULL DEFAULT 'PENDING'
CHECK (status IN ('PENDING', 'IN_TRANSIT', 'PAID', 'FAILED', 'CANCELED')),
payout_method VARCHAR(30) NOT NULL,
payout_details JSONB,
external_reference VARCHAR(255),
arrival_date DATE,
failure_reason VARCHAR(500),
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP
);
-- Indexes
CREATE INDEX idx_merchant_payouts_merchant ON forhopppay.merchant_payouts(merchant_account_id);
CREATE INDEX idx_merchant_payouts_status ON forhopppay.merchant_payouts(status);
CREATE INDEX idx_merchant_payouts_created ON forhopppay.merchant_payouts(created_at);
Payout ID Format: po_[32 alphanumeric characters]
Minimum Payout Threshold: $25.00 (2500 cents)
8. merchant_disputes
Stores dispute/chargeback records.
CREATE TABLE forhopppay.merchant_disputes (
id BIGSERIAL PRIMARY KEY,
dispute_id VARCHAR(50) NOT NULL UNIQUE,
charge_id BIGINT NOT NULL REFERENCES forhopppay.merchant_charges(id),
merchant_account_id BIGINT NOT NULL REFERENCES forhopppay.forhopppay_accounts(id),
amount_cents BIGINT NOT NULL,
currency VARCHAR(3) NOT NULL DEFAULT 'USD',
reason VARCHAR(100),
status VARCHAR(30) NOT NULL DEFAULT 'OPEN'
CHECK (status IN ('OPEN', 'UNDER_REVIEW', 'WON', 'LOST')),
evidence_details JSONB,
resolution_details JSONB,
resolved_at TIMESTAMP,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP
);
-- Indexes
CREATE INDEX idx_merchant_disputes_charge ON forhopppay.merchant_disputes(charge_id);
CREATE INDEX idx_merchant_disputes_merchant ON forhopppay.merchant_disputes(merchant_account_id);
CREATE INDEX idx_merchant_disputes_status ON forhopppay.merchant_disputes(status);
Dispute ID Format: dp_[32 alphanumeric characters]
Dispute Fee: $15.00 (refunded if won)
9–18. Subscription Tables (Added June–July 2026)
The following tables support the recurring billing/subscription system. Full DDL is managed by Flyway migrations V67–V97+.
| Table | Purpose | Key Fields |
|---|---|---|
merchant_customers |
Customers created by merchants | customer_id (cus_xxx), email, name, metadata |
merchant_plans |
Subscription plan templates | plan_id, name, description, active |
merchant_prices |
Pricing terms for plans | price_id (price_xxx), amount_cents, currency, interval, interval_count |
merchant_subscriptions |
Active billing relationships | subscription_id (sub_xxx), status, current_period_start/end, cancel_at_period_end |
subscription_items |
Add-on items on subscriptions | item_id (si_xxx), price_id, quantity, is_base_item, status |
subscription_invoices |
Billing records per cycle | invoice_id (si_xxx), subtotal/tax/total_cents, status, period_start/end |
subscription_invoice_line_items |
Breakdown per invoice | type (SUBSCRIPTION/ADDON/PAST_DUE_PRORATION/CREDIT), amount_cents |
pending_prorations |
Deferred charges/credits | proration_id (pro_xxx), type, amount_cents, status (PENDING/BILLED/VOIDED) |
payment_method_tokens |
Saved payment methods (vault) | token_id (pm_xxx), type (CARD/PAYPAL), gateway_token, is_default |
subscription_tax_rates |
Tax rate configuration | percentage, jurisdiction, inclusive/exclusive |
Note: Full CREATE TABLE DDL for these tables is documented in the individual feature docs: 10-SUBSCRIPTIONS.md, 11-SUBSCRIPTION-ADDONS.md, 12-MOR-RECURRING.md.
Enumerations
ApiKeyEnvironment
public enum ApiKeyEnvironment {
LIVE, // Production environment
TEST // Sandbox environment
}
ConnectChargeStatus
public enum ConnectChargeStatus {
PENDING, // Awaiting customer payment
AUTHORIZED, // Payment authorized, ready for capture
CAPTURED, // Payment captured
FAILED, // Payment failed
VOIDED, // Cancelled before capture
REFUNDED, // Fully refunded
PARTIALLY_REFUNDED, // Partially refunded
EXPIRED, // Checkout session expired (24h)
DISPUTED // Customer disputed
}
ConnectRefundStatus
public enum ConnectRefundStatus {
PENDING, // Refund processing
SUCCEEDED, // Refund completed
FAILED // Refund failed
}
WebhookDeliveryStatus
public enum WebhookDeliveryStatus {
PENDING, // Awaiting delivery
DELIVERED, // Successfully delivered
FAILED // Delivery failed after retries
}
PayoutStatus
public enum PayoutStatus {
PENDING, // Payout scheduled
IN_TRANSIT, // Funds being transferred
PAID, // Payout completed
FAILED, // Payout failed
CANCELED // Payout cancelled
}
PayoutSchedule
public enum PayoutSchedule {
DAILY, // Daily at 00:00 UTC
WEEKLY, // Monday 00:00 UTC
MONTHLY // 1st of month 00:00 UTC
}
ConnectDisputeStatus
public enum ConnectDisputeStatus {
OPEN, // Dispute opened
UNDER_REVIEW, // Evidence submitted, under review
WON, // Merchant won dispute
LOST // Merchant lost dispute
}
ConnectSubscriptionStatus
public enum ConnectSubscriptionStatus {
TRIALING, // In trial period
ACTIVE, // Billing normally
PAST_DUE, // Payment failed, retrying
PAUSED, // Manually paused
UNPAID, // All retries exhausted
CANCELED // Subscription ended (terminal)
}
SubscriptionInvoiceStatus
public enum SubscriptionInvoiceStatus {
DRAFT, // Being built
OPEN, // Charge attempted
PAID, // Payment collected
UNCOLLECTIBLE, // All retries exhausted
VOID // Manually voided
}
ProrationStatus
public enum ProrationStatus {
PENDING, // Awaiting inclusion in next invoice
BILLED, // Included in an invoice
VOIDED // Cancelled, will not be billed
}
ProrationType
public enum ProrationType {
PAST_DUE_CHARGE, // Additional charge for mid-cycle addition
CREDIT // Credit for mid-cycle removal
}
PaymentMethodType
public enum PaymentMethodType {
CARD, // Tokenized card
PAYPAL // PayPal Billing Agreement
}
Migration Files
The schema is created through Flyway migrations:
| Migration | Description |
|---|---|
V60__create_merchant_api_keys_table.sql |
API keys table |
V61__create_merchant_profiles_table.sql |
Merchant profiles |
V62__create_merchant_charges_table.sql |
Charges table |
V63__create_merchant_refunds_table.sql |
Refunds table |
V64__create_merchant_webhooks_tables.sql |
Webhooks and deliveries |
V65__create_merchant_payouts_table.sql |
Payouts table |
V66__add_merchant_disputes_table.sql |
Disputes table |
Data Integrity Constraints
Foreign Key Relationships
- All tables reference
forhopppay_accounts(id)for merchant ownership merchant_charges.api_key_id→merchant_api_keys(id)merchant_refunds.charge_id→merchant_charges(id)merchant_webhook_deliveries.webhook_id→merchant_webhooks(id)merchant_disputes.charge_id→merchant_charges(id)
Unique Constraints
merchant_api_keys.publishable_key- Globally uniquemerchant_charges.charge_id- Globally uniquemerchant_charges(merchant_account_id, idempotency_key)- Unique per merchantmerchant_webhooks(account_id, endpoint_url)- Unique per merchantmerchant_refunds.refund_id- Globally uniquemerchant_payouts.payout_id- Globally uniquemerchant_disputes.dispute_id- Globally unique
Check Constraints
- Status enums validated via CHECK constraints
- Environment validated:
LIVEorTEST - Payout schedule validated:
DAILY,WEEKLY, orMONTHLY
Performance Considerations
Indexes
- All foreign keys are indexed
- Status columns indexed for filtering
- Timestamp columns indexed for range queries
- Partial indexes for active records (e.g., non-revoked keys)
Partitioning (Future)
For high-volume deployments, consider partitioning:
merchant_chargesbycreated_at(monthly)merchant_webhook_deliveriesbycreated_at(weekly)
Archival
- Webhook deliveries older than 30 days can be archived
- Expired charges can be archived after 90 days
Last Updated: July 2026
