Inspiration
AI agents can search and compare faster than any person, but handing an agent your card is not delegation, it is a blank check. PayPal's own agentic commerce work draws the same line: agents are good at discovery, selection, and cart preparation, while approval and authentication belong to the buyer. We wanted to build the missing middle: a permission record the buyer writes before the agent acts, plus a payment boundary the agent cannot cross on its own.
What it does
The buyer writes a mandate first: category, approved merchants, maximum budget, minimum rating, and an expiry. Only then does the agent search. It ranks a curated catalog and shows every product fact with its catalog timestamp, so recommendation and evidence stay separate.
Before checkout, the server recomputes eligibility from catalog facts. The AI can propose products, but it cannot widen a budget, add a merchant, change a category, or supply evidence. The checkout quote is calculated server-side in integer cents, discounts are re-verified, and the resulting review is immutable and expires after five minutes.
The buyer approves that exact total, a one-time nonce is issued, and only then is a PayPal Sandbox order created and captured. Creation and capture are idempotent, so retries never double-charge. If a payment state is unknown, the app reconciles with PayPal instead of guessing. Every step lands in a replay timeline that shows the actor, the timestamp, and the reason an action was blocked, with sensitive values redacted. Reset hard-deletes the session and all of its data.
How we built it
Next.js 15 with the App Router, React 19, TypeScript, Zod, Tailwind CSS 4, and the built-in node:sqlite module. The code is split into pure domain rules (money, pricing, validation, redaction), application use cases (session, mandate, search, checkout, replay), infrastructure adapters (SQLite, catalog, PayPal, AI), and the client UI.
PayPal: the official JavaScript SDK opens the Sandbox sign-in and approval, while order creation and capture happen on the server through the REST Orders v2 API with OAuth 2.0 client credentials, idempotency keys, and reconciliation for unknown states.
AI: an OpenAI-compatible chat-completions client receives only the buyer request, the active mandate limits, and a bounded candidate list. It returns structured JSON with product IDs, reasons, trade-offs, unknowns, and confidence. Unknown product IDs are discarded, eligibility is recomputed deterministically, and invalid JSON, timeouts, or provider errors fall back to deterministic ranking. The provider chain supports up to five fallbacks.
Tests cover domain validation, pricing, mandate lifecycle, checkout, the PayPal clients with injected fakes, redaction, replay, and a real headless-browser run through the hydrated UI.
Challenges we ran into
Making the agent untrusted by construction. The model had to be useful without ever becoming the authority, so its output is treated as a proposal and every limit is re-derived on the server from catalog facts.
Keeping the total authoritative. Money is integer cents, the quote is recalculated immediately before approval, and the review expires, so a stale or edited browser value cannot become the charged amount.
Handling payment uncertainty. A timeout after capture is not a failure. We reconcile against PayPal rather than retrying blindly, which is what makes an AI-driven checkout demo believable.
Separating evidence from prose. Product facts carry timestamps and are shown as facts; model confidence is shown as model confidence. The UI never promotes AI text into evidence.
Accomplishments that we're proud of
A verified end-to-end PayPal Sandbox capture of $78.32, with the order created and captured server-side. The demo video shows the real Sandbox sign-in, the real approval screen, and the resulting capture ID 273975687J3744118.
A blocked path that is genuinely blocked and explained: an unverified discount is disclosed in the ledger, then rejected at checkout because the cart minimum is not met, and no order is created.
No duplicate captures under retries, because create and capture are idempotent and unknown states are reconciled.
A replay timeline that explains every blocked action, and a hard reset that removes the session, mandate, checkout data, and replay events.
The app still works with no AI configured: it falls back to deterministic ranking and says so, instead of failing.
What we learned
Trust in agentic commerce is mostly about refusal. The product only feels safe when it says no and explains why, which is why the blocked path got as much attention as the happy path.
Prompt-injection resistance is a product requirement, not a model setting. Catalog text and buyer requests cannot override the mandate because the mandate is enforced outside the model.
Server authority plus idempotency is what makes an AI-driven payment demo credible. The interesting engineering is not the prompt, it is the boundary around it.
What's next for Mandate
A hosted demo with a durable database instead of local SQLite, so judges and buyers can try it without a setup step.
Verifiable mandate evidence: signed mandates and merchant-side verification, closer to the Agent Payments Protocol direction, without claiming compatibility we have not implemented.
A larger catalog with real merchant feeds and checkable evidence, plus multi-item carts, subscriptions, and recurring mandates.
Mobile approval and notifications, so the buyer can approve or revoke from anywhere.
Built With
- aiagent
- llm
- next.js
- node.js
- openai
- paypal-javascript-sdk
- paypal-orders-api
- paypal-sandbox
- react
- sqlite
- tailwind-css
- typescript
- zod