Inspiration
PayPal's loudest complaints aren't about moving money; they're about trust breaking down around it.
- Buyers: purchase scams are 71% of UK authorised-push-payment fraud cases (£576M lost in 2025). If you're tricked into paying, for example "send it Friends & Family", it isn't "unauthorized", so it's rarely refunded.
- Sellers: 43.8% of chargebacks are friendly fraud, and 85% of people who file one say bad service pushed them to it. Card networks flag merchants above a 1.5% dispute ratio.
- Everyone: about 1 in 5 PayPal reviews mention sudden holds with no explanation, and forgotten free trials turn into unwanted charges and chargebacks.
Revolut cut card-scam losses about 30% with an AI "break the spell" flow; PayPal has nothing equivalent. We built it, and extended the idea across the whole life of a payment.
What it does
The live site opens on an Overview page that explains the problem, what exists today and our idea, then a guided tour (with a sandbox buyer login) of a demo marketplace where every flow runs on real PayPal sandbox calls.
- Pay-pause. Every checkout is a PayPal authorization, not a charge. Before the button appears, TrustLayer reads the listing and the buyer-seller chat. Explainable rules, an LLM and our own fine-tuned model name the scam tactic; the LLM must quote the exact chat lines, and every quote is checked against the real chat, so the AI can't invent evidence. Risky payments get a "break the spell" screen. If the buyer insists, the hold enters a cooling-off period and a trusted contact can stop it; the authorization is voided and nothing is charged.
- Pre-dispute resolution. An unhappy buyer talks to an AI assistant acting for the seller. It classifies the issue and proposes a fix; code enforces the seller's refund policy so the model can't promise unauthorized money. Accepting executes on PayPal: a reduced capture (if still on hold) or a partial refund. Anything beyond policy goes to the seller.
- Seller account health. Dispute ratio against the 1.5% line, refund rate, sales spikes, new-account velocity, scam pauses and Seller Protection coverage, explained in plain English with next steps, including "your dispute rate without early resolution".
- Subscriptions without the trap. TrustLayer Plus ($4.99/month on PayPal Subscriptions) has a real free trial. Two days before the first charge, an AI-written reminder says honestly whether you've used it (and suggests cancelling if not); the date and amount are stated by code. Cancelling takes one confirmation. Sellers get the same kit: an AI terms review that flags dark patterns (code hard-blocks call-to-cancel, cancellation fees and minimum terms), a real PayPal plan per offering, and a dashboard that flags trial subscribers about to be charged without ever using it.
- A model we fine-tuned ourselves. A public DistilBERT scam classifier (trained on phone-scam calls) fine-tuned on marketplace payment chats with two heads: scam / not scam, and which tactic. A second round added "hard" chats (honest patterns that fooled the first model, polite scams). We also distilled two MiniLM students; the teacher shipped because the students lost the tactic skill. It runs as ONNX int8 on CPU inside the API in about 80 ms. Out of the box the public model flagged 59% of honest marketplace chats; after fine-tuning, 0%. With every hosted LLM down, rules plus this model still paused 80% of held-out scams, against 35% for rules alone.
- Audit log. Every PayPal call and AI decision lives in a SHA-256 hash chain; tampering is detected and located.
Results on 80 held-out chats, scored once: all 40 scams paused, 3 of 40 honest buyers wrongly paused (each analysed in NUMBERS.md), and the right tactic shown on 62.5% of scams (LLM alone: 55%).
How we built it
- PayPal: Orders v2 (
intent: AUTHORIZE), Payments v2 (authorize, capture, partial-final capture, void, refund, reauthorize), Payouts v1 (send and reconcile), Webhooks (register, signature verification, idempotent consumption), Subscriptions v1 (product, billing plan with a TRIAL cycle, verify, cancel, suspend, activate), and the JS SDK twice (intent=authorizefor checkout, a namespacedvault=true&intent=subscriptioninstance for subscriptions). Every state change carries aPayPal-Request-Idfor idempotency. HandlesINSTRUMENT_DECLINEDand expired authorizations. - AI: Groq
openai/gpt-oss-120b(primary), Geminigemini-flash-lite-latest(automatic fallback), optional local Ollama, plus our fine-tuned DistilBERT (PyTorch on a GTX 1650 → ONNX int8 → ONNX Runtime on CPU). JSON-only outputs, a grounding check on cited evidence, and deterministic policy enforcement around every model decision. - Evaluation done properly: disjoint datasets from different generator models (train, dev, two held-out tests). Everything was tuned on dev only; once we had looked at test v1 it counted as seen, so we generated a fresh test v2 and scored it exactly once.
- Stack: FastAPI + SQLite, a no-build React frontend, deployed on Render. 65 offline tests (fake PayPal and fake LLM), a real-sandbox end-to-end test, and a headless UI test.
Challenges we ran into
- False positives. Honest sellers say "another buyer is interested" or even "please don't use Friends & Family". Rules alone flag these. We fuse rules, an LLM and the local model, require corroboration before pausing, and measured it on hard negatives.
- AI that invents evidence. We require exact quotes with line numbers and verify each one; unverifiable quotes are discarded.
- Sandbox realities. Accounts created in some countries can't send Payouts, so we documented a US-account setup. Payouts v1 and Orders v2 use different money schemas (
currencyvscurrency_code). - Free-tier AI limits. Groq's per-minute caps meant rate-aware batching and provider fallback. They also hid a bug: our first evaluation silently counted rate-limited LLM calls as rules-only answers. Fixing the harness (and one real fusion bug) is documented in NUMBERS.md.
- A public model that didn't transfer. The phone-scam classifier flagged most honest marketplace chats. Fine-tuning fixed that; int8 quantization then shifted its probabilities, so we re-calibrated the threshold on the quantized model.
Accomplishments that we're proud of
- Real money paths end to end in sandbox: hold, cooling-off, void, AI-settled partial capture, refund, payout, subscription.
- The AI never moves money on its own say-so: policy limits, grounded evidence and human confirmation sit around every decision.
- Honest, reproducible numbers, including every miss.
What we learned
Scam detection needs an intervention people trust: specific evidence, a calm explanation and a safe default. And holding money (authorize, don't capture) is a powerful safety primitive that most checkouts don't use.
What's next
Real 24-hour cooling-off with SMS/email to trusted contacts, platform onboarding for multi-seller payouts, PayPal Disputes API integration for cases that still escalate, and a small transaction-sequence model per seller.