Create a ledger via POST /api/ledgers, then define ledger accounts for each actor: platform_cash (asset), buyer_payable (liability), seller_receivable (asset), and platform_fee (revenue), following double-entry principles.
When a buyer pays, record a ledger transaction with two entries: debit platform_cash and credit buyer_payable in equal amounts; link this ledger transaction to the Modern Treasury PaymentOrder representing the incoming ACH or wire.
On delivery confirmation, transition the buyer_payable to the seller: record a ledger transaction debiting buyer_payable and crediting seller_receivable; simultaneously debit seller_receivable and credit platform_fee for your commission amount.
Trigger the actual payout via POST /api/payment_orders with payment_type=ach, direction=credit, originating_account_id (your bank account), counterparty_id (the seller's bank counterparty), and amount; link the payment order to the ledger transaction via metadata.
Subscribe to payment_order.status_changed webhooks to detect COMPLETED or FAILED states; on FAILED, reverse the ledger entries to restore seller_receivable balance and flag for retry.
Use GET /api/ledger_accounts/{id} with balance_types[]=available to retrieve real-time available balance per ledger account; use this to prevent over-disbursement when multiple concurrent payouts draw from the same pool.
Known gotchas
Modern Treasury ledger entries are immutable once posted — to correct an error, you must create a reversing ledger transaction with opposite entries rather than editing the original; build reversal workflows from day one.
Ledger account balances in Modern Treasury are calculated from posted transactions; pending transactions do not reduce available balance by default unless you configure pending balance tracking — failing to account for pending outflows can cause over-disbursement.
Linking a PaymentOrder to a ledger transaction is a metadata convention, not an enforced constraint — if the payment fails after ledger entries are posted, your ledger and bank balance will diverge; always handle payment_order.failed by reversing the corresponding ledger entries.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp