Pay an Invoice Safely
Propose a payment, route to approval if needed, execute, get a receipt.
The Simplest Case
const action = await brain.pay("acme", { invoiceId: "inv_8231" });
console.log(action.status);
// "auto" → already executed
// "needs_approval" → waiting for a human
// "rejected" → policy said noHandling All Three Outcomes
const action = await brain.pay("acme", { invoiceId: "inv_8231" });
switch (action.status) {
case "auto":
// Already done. Brain executed and recorded the receipt.
console.log("paid:", action.receipt.txHash ?? action.receipt.railReceipt);
break;
case "needs_approval":
// Surface to your approval UI. Approvers receive the action.
console.log("waiting on:", action.approvers);
break;
case "rejected":
console.log("blocked:", action.reason);
break;
}Approving from Your App
Rejecting from Your App
Getting the Receipt
Paying Without an Invoice
Idempotency
Webhooks for Long-Running Flows
What if My Action Fails?
What's Next
Last updated
