04 — Payments Engine

backend/payments/ — engine, providers, ledger

CEO Summary

The payments engine orchestrates all payment flows — card (Stripe, Square Terminal), crypto (Dogecoin Core, CoinRemitter), and cash. It selects providers by tenant config, posts to the ledger, and enforces idempotency. Business value: Revenue flows through here. Key metrics: Transaction volume, success rate, reconciliation status. If this breaks: POS cannot accept card/crypto; refunds fail.

Architecture

flowchart TB subgraph api [API v1] Payments[payments.routes] Invoices[invoices.routes] Transactions[transactions.routes] Webhooks[webhooks.routes] end subgraph core [Core] Engine[engine.js] Gateway[gateway.js] Registry[registry.js] Ledger[ledger.js] Idempotency[idempotency.js] end subgraph drivers [Drivers] Stripe[Stripe] StripeTerminal[Stripe Terminal] SquareTerminal[Square Terminal] DogeCore[Dogecoin Core] CoinRemitter[CoinRemitter] end Payments --> Engine Engine --> Gateway Gateway --> Registry Registry --> drivers Engine --> Ledger Engine --> Idempotency

Overview

Path: backend/payments/

Orchestrates payment flow: provider selection, charge/refund, ledger posting, idempotency.

Core Components

FilePurpose
engine.jsCharge, refund orchestration (simulation + real)
core/registry.jsProvider registry — lists available drivers
core/gateway.jsgetRuntimeConfig, getRuntimeDriver — selects provider by tenant
core/ledger.jsLedger posting
core/idempotency.jsIdempotent request handling

Providers (Drivers)

ProviderPathPurpose
Stripe Terminalproviders/stripeTerminal.jsCard via Stripe Terminal
Coinbase Commerceproviders/coinbaseCommerce.jsCrypto payments
Dogecoin Coreproviders/dogecoinCore.jsDOGE via Core node
CoinRemitter Dogeproviders/coinremitterDoge.jsDOGE via CoinRemitter
GigaWalletproviders/gigawallet.jsLightning/crypto
Internal Cardproviders/internalCard.jsInternal card processing
Crypto Simproviders/cryptoSim.jsSimulated crypto (testing)
Mock Acquirerproviders/mockAcquirer.jsMock card (testing)
Crypto (DOGE/BTC)providers/crypto/index, rates, address, rpc per coin

API v1 Routes (Full)

Path: backend/payments/api/v1/

FilePurpose
payments.routes.jsPayment intents, capture
invoices.routes.jsInvoice CRUD
transactions.routes.jsTransaction list
webhooks.routes.jsWebhook handling
ledger.routes.jsLedger entries
recon.routes.jsReconciliation
utxo.routes.jsUTXO management (crypto)
disputes.routes.jsDisputes
intents.routes.jsPayment intents
merchants.routes.jsMerchant config
locations.routes.jsLocation config
keys.routes.jsKey management
apikeys.routes.jsAPI keys
org.rules.routes.jsOrg-level rules

Validators

Path: backend/payments/validators/

webhooks.schemas.js, invoices.schemas.js — Request validation

Provider Selection

gateway.getRuntimeConfig({ id, provider, type }) — Selects from PaymentProvider model. Priority: by id → by provider slug → by type → any enabled.