Inspiration
AI shopping agents are coming, but handing an LLM a payment button is dangerous. Language models hallucinate prices, drift past budgets, make arithmetic errors, and can be hijacked by prompt injections hidden inside untrusted product listings. We wanted an agent that is useful, fast, and creative, but physically cannot overspend.
What it does
ApprovalPay is an autonomous AI shopping agent governed by deterministic spending policy code before reaching PayPal checkout.
You type a request in plain English (e.g., "3 gifts under $50 each for my team" or "an office desk setup under $100 total"). The agent curates products from live merchant catalogs, and then compiled code—not the AI—evaluates the basket against your spending policy:
- Per-item cap: Enforces an item ceiling ($1–$500).
- Total budget: Enforces a total cart limit ($1–$500).
- Blocked categories: Word-level boundary scanning against restricted goods (e.g., alcohol, gift cards).
- Absolute ceiling: Hard mathematical $500 safety ceiling.
- Approval threshold: Automatically locks checkout for human confirmation whenever a basket exceeds a defined amount.
Every proposal receives a deterministic verdict:
- Within policy: Green light for one-click checkout.
- Needs your approval: Requires explicit human checkbox authorization before payment can be initiated.
- Blocked by policy: Immediate rejection with exact constraint violations bulleted.
- No close match: If no catalog item matches the requested brand or specifications, the system refuses to propose random substitutes, displaying a neutral notice and skipping checkout.
Every decision—including the agent's reasoning, rule checks, item totals, and PayPal order status—is recorded in a searchable audit trail.
How we built it
- AI (Google Gemini
gemini-3.5-flash): Parses untrusted user prompts into structured parameters and selects candidate products by ID. The LLM never sees numeric prices, never calculates totals, and has zero payment authority. - Product Search (Channel3 API): Queries live merchant catalogs with strict USD currency filtering and HTTPS image mapping, with an offline curated catalog fallback.
- Policy Engine: Pure TypeScript executed strictly in integer cents with 30 passing Vitest tests. Zero floating-point rounding errors.
- PayPal Integration: Orders v2 REST API in the sandbox (
/v2/checkout/ordersand/v2/checkout/orders/{id}/capture). Creates idempotent orders using proposal UUIDs asPayPal-Request-Id, captures payment server-side, and supports negative testing via mock headers. - Security & Integrity: Secrets are strictly server-side (
server-only). All API bodies and upstream responses are validated with Zod. When authorizing payment, the browser sends only a proposal ID—never prices—and the server independently re-evaluates the stored basket against policy before calling PayPal. - Design System: Next.js 16 (App Router), React, and Tailwind CSS v4, styled using GetLayers-inspired fintech control standards (hairline borders, tabular numerals, accessible WCAG contrast, and zero generic AI slop). Deployed on Render.
Challenges we ran into
- Giving the LLM Zero Financial Authority: We solved this architecturally by stripping all price fields from the candidate list sent to Gemini. The model selects items solely by ID and title; verified catalog prices and totals are attached post-selection by compiled code.
- Handling API Model Deprecations: Upstream Gemini API transitions caused 404s on retired model IDs. We re-engineered the client to target active endpoints (
gemini-3.5-flash) with automatic 15-second abort timeouts and fail-fast rate-limiting. - Redirect Flows & Idempotency: Ensuring seamless approve-and-capture redirects between PayPal Sandbox and our deployed Render host while using proposal UUIDs as request IDs to prevent duplicate charges.
Accomplishments that we're proud of
- Impenetrable Guardrails: Prompt injections inside product listings cannot change prices or bypass spending limits because policy evaluation lives in compiled code.
- Real Merchant Discovery to Live Sandbox Capture: Curating genuine merchant items via Channel3 with live images, evaluating spending limits, and executing verified captures on the PayPal Sandbox.
- Zero Financial Leaks: 30/30 unit tests covering edge cases, word-level category boundaries, proposal expiration (15-min TTL), and pre-commit secret scans.
What we learned
In agentic commerce, trust comes from system architecture, not prompt engineering. Treat the LLM as an untrusted recommender and keep all financial decisions, money arithmetic, and checkout executions in verifiable code.
What's next for ApprovalPay
- Multi-seat corporate expense policies and team manager approval hierarchies.
- Persistent database storage with PayPal webhooks for asynchronous transaction events.
- Direct merchant split-payouts using PayPal Marketplace & Platforms.
- Automated invoice and receipt OCR reconciliation against audit proposals.
Note: ApprovalPay operates strictly in the PayPal Sandbox environment. No real money is processed.