-
-
Mandate: spending rules for AI agents that pay with PayPal.
-
Write rules in plain English. Gemini turns them into exact rules, and you confirm every change.
-
Agents propose, code decides. The model never touches the money.
-
One button stops every agent and cancels every payment on hold.
-
Real PayPal sandbox: save PayPal once with Vault, approve exceptions in PayPal. Works on a phone.
-
The agent's decisions, live, next to this month's spend.
-
Every payment explains itself: which rules passed, and which one asked for your OK.
-
Automatic payments stay on hold for 60 seconds. Undo cancels the hold, and no money moves.
-
One button stops every agent and cancels every payment on hold.
-
Gemini paid for labels automatically and sent mailer boxes for approval after a 6.9% price rise.
Inspiration
At Metis Labs we build BrandHub, a B2B platform where brands reorder branded packaging. Customers ask for one AI feature more than any other: "just reorder for me."
The hard part isn't the AI. It's trust: who lets an agent spend company money?
- Forrester (April 2026) found that about three-quarters of consumers are uncomfortable letting an AI agent pay on its own, even with preset limits.
- Checkout.com's research found that people's top worry is losing control. Easy refunds and spending limits are what would make them comfortable.
- PayPal's Agent Toolkit and MCP servers let agents create orders, refunds and invoices. They have no built-in spending limits and no human approval step, so every developer has to build their own.
Finance teams solved this long ago with budgets, approval thresholds and the ability to cancel. We wanted the same guarantees for AI agents, enforced in the payment flow, not in a prompt.
What it does
Mandate sits between AI agents and PayPal.
- You write your rules in plain English. "Up to €3,000 a month, anything under €500 can be paid without me, packaging suppliers only, ask me if a price rises more than 5%." Gemini turns this into exact rules, and you confirm every change before it applies.
- You save PayPal once with PayPal Vault. After that, agents can pay small orders that follow your rules without asking you.
- Agents propose, code decides. The purchasing agent (Gemini with tool use) reads stock levels and delivery times, then proposes orders. Plain code checks each order against 14 rules and decides: paid automatically, waiting for you, or blocked.
- Every payment can be undone. An automatic payment is a PayPal authorization on hold. Undo cancels the hold, and no money moves. After capture, Undo becomes a refund.
- Every payment explains itself. A decision receipt shows which rules passed, which rule stopped the payment, the rules version, and what the agent said. You see not just what happened, but why it was allowed.
- It closes the known loopholes. Split orders count together against the auto-pay limit. Each agent has its own budget. One button stops every agent and cancels every payment on hold.
- Any agent follows the same rules. You can connect Claude Desktop or any MCP client, or wrap PayPal's own Agent Toolkit, so refunds, invoices and orders pass the same checks.
In the live run shown in our video:
- Gemini paid for coffee bag labels automatically.
- It sent the mailer boxes for approval, because the supplier had quietly raised prices by 6.9%.
- It decided on its own not to order canvas totes from a supplier outside the rules.
How we built it
| Layer | What we used |
|---|---|
| Save PayPal for agents | PayPal Vault v3: setup token → buyer approval → payment token |
| Agent pays with no buyer present | Orders v2, intent: AUTHORIZE with payment_source.paypal.vault_id |
| Payments that need your approval | Orders v2 buyer approval → authorize |
| Undo window, Undo and refunds | Payments v2: capture, void, refund |
| Keeping in sync with PayPal | PayPal webhooks, verified by PayPal before they're applied |
| AI | Gemini with tool use (get_stock, get_mandate, submit_order, finish), plus a forced function call that reads plain-English rules |
| Other agents | An MCP server and a PayPal Agent Toolkit guard |
| UI | Vanilla JS and AG Grid: status tabs, search, a totals row, inline Approve and Undo |
| Hosting | Node.js and Express on Render, with live updates over Server-Sent Events and a private demo workspace for each visitor |
The model never touches the money. The agent only proposes items and quantities. The server prices every line from the catalogue and enforces the rules, so a hallucination or a prompt injection can't raise the spend.
The auto-pay limit counts everything paid to that supplier in the last 24 hours, so an agent can't stay under it by splitting a purchase. A new order of value \(x\) is paid without asking only if
$$ x + \sum_{o \,\in\, \text{auto-paid to the same supplier, last 24 h}} o \;<\; L_{\text{auto}} $$
Every automatic payment stays reversible during an undo window \(w\) (60 seconds by default):
$$ \text{Undo}(t) = \begin{cases} \text{void the authorization (no money moves)} & t < t_{\text{auth}} + w \ \text{refund the capture} & t \ge t_{\text{auth}} + w \end{cases} $$
Every PayPal call is idempotent, with a random key for each order.
Challenges we ran into
- Fractions of a cent. A sticker costs €0.045, but PayPal amounts have two decimal places. We send line items per supplier pack (for example, 3 × 1,000-pack at €45.00), so item totals always add up exactly.
- Real sandbox, real problems. Our first sandbox accounts were in the India region, which can't run this flow, so we moved to Netherlands accounts. When PayPal refuses to save the payment method (a common forum issue), Mandate falls back to buyer approval instead of failing.
- A bug only live testing could find. Order numbers repeat across the private demo workspaces, so PayPal's idempotency check replayed an old authorization. Each order now carries a random key, and a test guards against the bug. This is why we test against the real PayPal sandbox, not just mocks.
- Free-tier AI capacity. Gemini models sometimes hang or return 503 errors. Each model now gets 15 seconds before Mandate tries the next one. If no model answers, a deterministic planner takes over, so a buyer is never stuck.
- Explaining decisions to non-technical buyers. We rewrote every message in plain English: "On hold, can undo" instead of "authorized", item names instead of SKU codes, and a "Why your rules decided this" panel on every payment.
Accomplishments that we're proud of
- An agent that pays with no human present, safely. It's built only from standard PayPal building blocks and verified end to end on the real PayPal sandbox: Vault, authorize, void, capture and refund.
- Undo for agent payments. We think this is the feature that makes agentic payments feel safe. It relies on nothing more exotic than PayPal's authorize-then-capture flow.
- Explainable by design. Every payment answers "why was this allowed?" in plain English, with the exact rules version.
- Works with agents we didn't build. Claude Desktop over MCP, and PayPal's own Agent Toolkit, follow the same rules.
- Production quality:
- 38 automated tests
- A browser end-to-end test of the full judge journey: tour → save PayPal → rules → agent → receipt → undo → approve → stop all → phone width
- CI on every push
- Strict security headers and CSRF protection
- 0 known vulnerabilities in production dependencies
What we learned
- Agentic commerce needs the controls finance teams already rely on (budgets, thresholds, approvals and reversals), built into the payment flow itself.
- PayPal's authorize-then-capture model fits an undo window naturally. Vault makes paying with no buyer present safe once the buyer has given consent.
- Let the AI propose and let code decide. Gemini was excellent at reading context ("Black Friday is coming") and even followed the rules on its own, but the guarantee has to come from deterministic checks.
- Mocks hide real bugs. Testing end to end on the real sandbox found the idempotency bug before any judge did.
What's next for Mandate
- Ship it inside BrandHub for real brands.
- Pay suppliers with PayPal Payouts, and reconcile supplier invoices with the Invoicing API.
- Mandates for each team and cost centre, with monthly spend reports for each agent.
- Publish the MCP server and the Agent Toolkit guard as packages, so any agent can buy within a PayPal mandate.
Built With
- ag-grid
- express.js
- gemini
- google-gemini
- javascript
- mcp
- node.js
- paypal
- paypal-agent-toolkit
- paypal-orders-api
- paypal-payments-api
- paypal-vault
- playwright
- render