Inspiration

AI agents are starting to buy things on our behalf, and they decide what to buy by reading web pages. That makes every product page a possible attack. A merchant can hide text on a listing that tells the agent to ignore the user's budget, and an agent with direct payment access will often comply. Agents also make plain mistakes, such as choosing a refurbished item or an unknown seller. Once a payment is captured, a dispute is the only remedy. I wanted the check to happen before the money moves, and PayPal's two-step payment flow already has a natural place for it.

What it does

The user gives the agent a mandate: what to buy and a price cap. The agent browses a store and picks an item. Instead of charging the buyer, it creates a PayPal order with AUTHORIZE intent, which reserves the funds without collecting them.

A separate verifier then compares the held order against the original mandate. It applies a hard price-cap rule and asks Gemini to assess item match, seller trust, and signs of prompt injection, returning a confidence score with reasons. The score decides the outcome:

  • 85 or above: the payment is captured automatically.
  • 50 to 84: the order stays on hold and appears on a dashboard, where a person approves (capture) or rejects (void).
  • Below 50, an injection detected, or a price-cap violation: the authorization is voided and the buyer is never charged.

If the verifier fails for any reason, the system voids instead of capturing.

The demo includes three store scenarios: a clean store, an ambiguous one (a refurbished drive from an unrated seller), and a poisoned page with hidden instructions to buy a $400 bundle.

How I built it

  • PayPal Orders v2 REST API (sandbox): create an order with AUTHORIZE intent, authorize after buyer approval, then capture or void.
  • Google Gemini 2.5 Flash: used in two separate roles. One call acts as the shopping agent, and a second, independent call acts as the verifier. The verifier prompt treats scraped store text and the agent's reasoning as untrusted data and returns structured JSON.
  • Backend: Node.js and Express handle the agent run, the PayPal redirect, verification, the review endpoint, and an audit log of every decision.
  • Dashboard: Next.js 15, React 19, and MUI v6, showing each run's confidence against the decision thresholds, the verifier's reasons, and the review buttons.

The shopping agent is deliberately naive so that the injection attack is realistic. The project is about the guard around the agent.

Challenges

Getting the sandbox payment flow working took some debugging. A sandbox buyer created with an India country setting could not pay in USD, and INR is not supported for this flow, so I created a US buyer account. Designing the verifier was the other challenge. It reads the same hostile text the agent read, so its prompt has to treat that text strictly as data. I also made the gate fail closed, so an error never results in a capture.

What I learned

Authorize-then-capture is a useful control point for agentic commerce, not just a fulfilment detail. A deterministic rule next to a model check works better than either alone, because the price cap holds even if the model is fooled.

What's next

Retry-safe idempotency keys, webhook handling, seller allowlists, multiple independent verifiers, and signed mandates so an agent cannot alter the user's constraints.

Tools used

PayPal Orders v2 REST API (sandbox), Google Gemini 2.5 Flash (shopping agent and payment verifier), Next.js, React, MUI, Node.js, Express.

Built With

Share this project:

Updates