Payment orders: instructions to move money from one of your internal
accounts. direction: "credit" sends money to the receiving account;
direction: "debit" pulls from it. type picks the rail ("ach",
"wire", "rtp", "check", "book", "sepa", "eft",
"cross_border", ...). Amounts are in the currency's smallest unit.
Creating a payment order moves money: it needs an idempotency-key
and is never retried. Agents should not approve payment orders:
configure approval rules in Modern Treasury so that orders an agent
creates wait in needs_approval for a person. Follow
payment_order.* webhooks for status changes instead of polling.
Values
REQUIRED
REQUIRED: Vec [
"type",
"direction",
"amount",
"originating_account_id"
]
Functions
approve-payment-order
fn (payment-order-id: Str): Map
fn (payment-order-id: Str, opts: Map): Map
Approve a payment order in needs_approval (PATCH {status: "approved"}), releasing it to be sent. Agents must not approve on their
own: leave it to a person, in the Modern Treasury dashboard or through
your own approval step that calls this. The API key needs approval
permission.
Example
// Call this only from a step where a person has approved the order
::modern-treasury::payment-orders/approve-payment-order("8c0f4c1e-2b6f-4d7e-9b1a-3f2e8d4c5b6a")
cancel-payment-order
fn (payment-order-id: Str): Map
fn (payment-order-id: Str, opts: Map): Map
Cancel a payment order that hasn't been sent (PATCH {status: "cancelled"}).
Example
order ::modern-treasury::payment-orders/cancel-payment-order("8c0f4c1e-2b6f-4d7e-9b1a-3f2e8d4c5b6a")
order.status
create-payment-order
fn (params: Map, opts: Map): Map
POST /api/payment_orders: create a payment order. Moves money:
opts must carry an idempotency-key (the call errs without one
and sends nothing). params needs type, direction, amount and
originating_account_id, plus receiving_account_id (or an inline
receiving_account). Optional: priority ("normal" or "high",
e.g. same-day ACH), effective_date, description,
statement_descriptor, remittance_information, purpose,
metadata, line_items: [{amount, description, metadata}],
ledger_transaction, expires_at, process_after, subtype (e.g.
"CCD", "PPD"), fallback_type, send_remittance_advice.
Example
::modern-treasury::payment-orders/create-payment-order({
type: "ach",
direction: "credit",
amount: 10000,
originating_account_id: "0f8e3719-3dfd-4613-9bbf-c0333781b59f",
receiving_account_id: "5acec2ef-987b-4260-aa97-b719eeb0a8d5",
description: "Invoice 42",
metadata: {invoice_id: "42"},
line_items: [{amount: 10000, description: "Consulting, October"}]
}, {idempotency-key: "invoice-42-payout"})
create-payment-order-async
fn (params: Map, opts: Map): Map
POST /api/payment_orders/create_async: queue a payment order for
creation (for large batches); returns {object_id, object_type, status}. Same body and idempotency requirement as
create-payment-order; follow payment_order.created webhooks for the
result.
Example
queued ::modern-treasury::payment-orders/create-payment-order-async({
type: "ach",
direction: "credit",
amount: 10000,
originating_account_id: "0f8e3719-3dfd-4613-9bbf-c0333781b59f",
receiving_account_id: "5acec2ef-987b-4260-aa97-b719eeb0a8d5"
}, {idempotency-key: "invoice-42-payout"})
queued.object_id
create-reversal
fn (payment-order-id: Str, reason: Str, params: Map, opts: Map): Map
POST /api/payment_orders/{id}/reversals: reverse a sent ACH payment
order (NACHA allows it within five banking days, for limited
reasons). reason is "duplicate", "incorrect_amount",
"incorrect_receiving_account", "date_earlier_than_intended" or
"date_later_than_intended". params: metadata,
ledger_transaction. Moves money: needs an idempotency-key.
Example
reversal ::modern-treasury::payment-orders/create-reversal("8c0f4c1e-2b6f-4d7e-9b1a-3f2e8d4c5b6a", "duplicate", {metadata: {ticket: "1042"}}, {idempotency-key: "reverse-invoice-42"})
reversal.status
get-payment-order
fn (payment-order-id: Str): Map
fn (payment-order-id: Str, opts: Map): Map
GET /api/payment_orders/{id}: retrieve a payment order, with its
status (needs_approval, approved, processing, sent,
completed, returned, reversed, cancelled, failed, denied,
...).
Example
order ::modern-treasury::payment-orders/get-payment-order("8c0f4c1e-2b6f-4d7e-9b1a-3f2e8d4c5b6a")
order.status
get-reversal
fn (payment-order-id: Str, reversal-id: Str): Map
fn (payment-order-id: Str, reversal-id: Str, opts: Map): Map
GET /api/payment_orders/{id}/reversals/{reversal_id}: retrieve a reversal.
Example
reversal ::modern-treasury::payment-orders/get-reversal("8c0f4c1e-2b6f-4d7e-9b1a-3f2e8d4c5b6a", "2c8f1b7e-d5a4-4963-b0e7-81f3c6a9d204")
reversal.status
list-payment-orders
fn (): Map
fn (params: Map): Map
fn (params: Map, opts: Map): Map
GET /api/payment_orders: one page ({items, after_cursor, per_page}). Filters: status, type, direction, priority,
counterparty_id, originating_account_id, transaction_id,
external_id, reference_number, effective_date_start,
effective_date_end, created_at_start, created_at_end,
metadata: {key: value}, per_page, after_cursor.
Example
waiting ::modern-treasury::payment-orders/list-payment-orders({status: "needs_approval"})
list-reversals
fn (payment-order-id: Str): Map
fn (payment-order-id: Str, params: Map): Map
fn (payment-order-id: Str, params: Map, opts: Map): Map
GET /api/payment_orders/{id}/reversals: one page of a payment order's reversals.
Example
page ::modern-treasury::payment-orders/list-reversals("8c0f4c1e-2b6f-4d7e-9b1a-3f2e8d4c5b6a")
map(page.items, %.id)
update-payment-order
fn (payment-order-id: Str, params: Map): Map
fn (payment-order-id: Str, params: Map, opts: Map): Map
PATCH /api/payment_orders/{id}: change a payment order that hasn't been
sent (amount, effective_date, description, metadata,
receiving_account_id, ...), or its status. Use
approve-payment-order and cancel-payment-order for status changes.
Example
::modern-treasury::payment-orders/update-payment-order("8c0f4c1e-2b6f-4d7e-9b1a-3f2e8d4c5b6a", {description: "Invoice 42, corrected"})