What inspired us

When a payment goes wrong, you almost always find out too late. The money has left, and now you're filing a dispute and waiting. We kept asking one question: why does the check happen after the payment instead of before it?

That question matters more now. AI agents are starting to pay for things on people's behalf, and an agent can be tricked into sending money to the wrong place. So we built the thing we'd want standing in front of our own PayPal account.

What it does

Trust Layer sits between a payment request and PayPal. It looks at every payment first and gives it one of three answers:

  • Approve. A real PayPal order is created and captured.
  • Needs confirmation. The order is created, but we refuse to capture it until the payer confirms.
  • Hold. We never call PayPal. No order exists, so there's nothing to refund.

After a payment completes, we check PayPal's webhook signature and compare the amount with what we approved. Every step goes into a log where each entry carries the hash of the one before it, so nobody can quietly change history.

On the page you can watch it happen: payments fly through a 3D path, and the risky ones turn red and drop into quarantine.

Who it's for

Merchants, marketplaces and anyone building on PayPal who wants their own checkpoint: their rules, clear reasons for every decision, and a record they can prove wasn't edited. It's also a guardrail for the AI agents that are about to start spending money for us.

How we built it

PayPal is the centre of it. We use OAuth, the Orders v2 API to create and capture real sandbox orders, idempotency keys so a retry can never charge twice, and webhook signature verification.

AI does two jobs:

  • A scikit-learn Isolation Forest scores how unusual each payment is next to normal behaviour. It works alongside plain rules, and the stricter of the two wins.
  • Claude explains each decision in plain English and writes an incident note that sums up what a batch of held payments has in common. Claude only sees facts our server built. It explains decisions and can't change them, so nobody can sweet-talk a payment through with a clever prompt.

The backend is FastAPI with a WebSocket stream. The dashboard is React and TypeScript, with three.js for the live path and AG Grid for the quarantine and audit tables. Both run on Render.

We also used Claude as a coding assistant while building, to help write and review code and to understand each piece properly.

Challenges we faced

  • Never charging twice. Networks fail mid-request. Every PayPal call carries a stable idempotency key, and captures go through a small state machine, so a double click or a retry can't create a second charge.
  • Trusting the webhook. A webhook is only worth something if it really came from PayPal. We had to keep the raw request body byte for byte and verify the signature before reading anything.
  • Keeping AI out of the driver's seat. We wanted AI explanations without handing a language model the power to approve money. Drawing that line cleanly took a few tries.
  • Deploying it. Getting the dashboard and the API to trust each other on Render cost us more time than we'd like to admit.

What we learned

How PayPal's order lifecycle really works, from create to buyer approval to capture to webhook. Why idempotency is the difference between a demo and something you'd trust with money. And that a small anomaly model is most useful as a second opinion next to simple rules, not as a replacement for them.

What we're honest about

The traffic in the live view is simulated so you can see the system under load. Payments in the "Real payment" section are real PayPal sandbox orders. The model is trained on synthetic data, and it mostly misses scam payments that look like a normal payment to a new person (it catches about 10% of those). The audit log detects tampering but can't prevent it.

What's next

  • Put Trust Layer in front of a real AI shopping agent and show it stopping a hijacked payment.
  • Train on real, labelled payment data so scams stop slipping through.
  • Move orders out of memory into a database, and add a review queue for held payments.

Built With

Share this project:

Updates

Submission history