Inspiration
Money moves fast, and AI now moves it too. Three problems kept showing up:
- People get tricked before they pay. Fake invoices, urgent "pay now" messages, and invoices with hidden instructions aimed at AI assistants.
- Merchants silently lose revenue. Cards fail, subscriptions lapse, and refund disputes drag on, even though most of it is recoverable.
- Freelancers chase payment. Lump-sum billing, scope fights, and cents lost in splits.
Most AI finance demos let the model decide and hope for the best. We asked a different question: what if AI could only propose, and plain deterministic code, which can be tested to death, made every money decision?
Agentic AI proposes. Deterministic code decides. PayPal moves the money.
What it does
AegisPay is a zero-trust agentic commerce and financial-safety workspace built on PayPal. You open it with one click, with no signup: aegispay-orpin.vercel.app
Universal 1-Click Device Agent
- One command bar takes typed text, voice, clipboard contents, or a dropped file from your device.
- The agent picks the right workflow and shows it, for example
ROUTED: CASHFLOW_CHECKfor "Can I afford a $420 chair this month?"
Pillar 1: Pay Safely
- ScamShield invoice firewall: returns ALLOW / HOLD / BLOCK. Prompt-injection text can raise the verdict to BLOCK but can never lower it.
- Single-use review tokens: each payment is bound to amount, currency, payee and tenant before a PayPal order is created, so checkout tampering is rejected.
- Subscription cleanup: finds and cancels forgotten subscriptions in one click.
- Agent spending permits: limits for AI agents that spend on your behalf.
- Natural-language cashflow checks: ask "can I afford this?" against your balance, buffer and commitments.
Pillar 2: Recover & Retain
- PayRevive: failed-payment recovery using a trained 16-tree gradient-boosted model, exact TreeSHAP explanations, a LinUCB contextual bandit, and a compliance gate.
- About +51% net recovery over hand-written static rules in a reproducible 500-batch benchmark on synthetic payments.
- 0 compliance violations.
- ClipRefund: instant partial refunds where a damage photo is compulsory.
- No photo means no refund, enforced in the UI and on the server.
- The same photo cannot be reused (SHA-256 anti-replay).
- ChurnRescue: retention offers behind a legal circuit breaker.
Pillar 3: Get Paid
- Milestone billing: penny-exact splits in integer cents that always sum to the total, issued as live PayPal invoices with deliverable proof.
- DealForge: agent-assisted negotiation inside a human-set mandate, ending in a SHA-256 contract fingerprint.
Open platform
- 13-tool MCP server (HTTP, stdio, WebMCP) so any AI agent can use these safeguards.
- Manifest V3 Chrome extension with a side-panel companion, downloadable from the app.
- Verification Lab: 1,000-case safety fuzzer, checkout-tamper lab, PayRevive model card, and a Gemini-to-Groq failover tester.
How we built it
- Front end: React, TypeScript and Vite, with AG Grid for the cryptographic audit ledger (CSV and Elastic NDJSON export).
- Back end: a TypeScript Node.js server with signed sessions, per-tenant isolated storage, rate limiting and OWASP-style hardening. Google OAuth and email/password accounts unify in both directions.
- Deterministic kernel: a shared TypeScript package that owns all money logic: permits, discount ladders, recipient binding, penny-exact allocation, token signing, and the PayRevive model. The AI layer cannot bypass it.
- AI layer: Google Gemini 2.5 Flash (multimodal) with automatic failover to Groq-hosted Llama 3.3 70B. AI output is treated as untrusted input and re-validated by the kernel.
- PayPal APIs: Orders v2, Invoicing v2, Billing Subscriptions, Captures and Refunds v2, Vault v3, Transaction Search, and Webhooks (sandbox).
- Quality and delivery:
- 359 Vitest tests (265 unit, 87 integration, 7 API end-to-end) plus 6 real-browser Playwright tests.
- About 81% statement and 95% function coverage, with regression thresholds.
- GitHub Actions CI (typecheck, coverage, build, browser E2E, dependency audit), a post-deploy smoke test, and Vercel auto-deploy.
Core idea in code:
// The AI proposes; the kernel decides. The model can never approve a payment on its own.
const proposal = await agent.propose(invoice);
const verdict = kernel.decide(proposal, permit); // ALLOW | HOLD | BLOCK
if (verdict !== "ALLOW") throw new PaymentBlocked(verdict);
Challenges we ran into
- Making "AI proposes, code decides" real. Every flow had to treat model output as a suggestion that the kernel re-validates, proven by a property-based fuzzer instead of trust.
- Prompt injection. Invoices can contain instructions aimed at the AI, so injected text may only escalate a verdict, never relax it.
- Honest money math. Splitting amounts without losing or inventing cents needed integer-cent allocation and tests over thousands of random cases.
- A session bug found in real use. Users saw "Your session expired" on every login. We fixed it, restored the earlier sign-in flow, and added a real-browser regression test.
- Testing what we claimed. An audit showed our early "end-to-end" tests only called the API. We added real-browser tests and a contract test, and corrected our own README test count to the true number.
- Serverless packaging. One push now deploys the extension, API bundle and front end on Vercel, and we state plainly that the demo store is not a durable production database.
- Flaky heavy tests. The 500-batch simulations timed out under coverage, so we found and fixed it before it broke CI.
Accomplishments that we're proud of
- A working end-to-end product, live and usable in one click.
- An explainable recovery model with about +51% net recovery and 0 compliance violations in a reproducible benchmark.
- Compulsory photo evidence for refunds, enforced on UI and server with anti-replay, and checked by a test that fails if the gate is removed.
- A 13-tool MCP server and a Chrome extension, so the safeguards work for other agents and on any web page.
- 365 automated tests across unit, integration, API and real-browser tiers, with GitHub Actions CI passing.
- Radical honesty: sandbox scope, synthetic benchmark data and storage limits are stated plainly in the README.
What we learned
- Trust is an architecture decision. The safest place for AI in a payment flow is upstream of the decision, never inside it.
- Explainability is a feature users feel. Showing why a payment was held builds more confidence than a higher accuracy number.
- A claim without a test is a liability. Auditing our own project found real gaps, and fixing them improved it more than a new feature would have.
- Real-browser tests catch what API tests miss, such as session loops and gated forms.
- Constraints simplify design. Making evidence mandatory removed a whole class of refund fraud.
What's next for AegisPay
- Durable storage: move from the demo JSON store to PostgreSQL and Redis.
- Live-money readiness: PayPal production onboarding, end-to-end webhook settlement verification, and a formal security review.
- Chrome Web Store release with in-page protection on checkout and invoice pages.
- Real merchant data: retrain PayRevive on anonymised payment telemetry and add drift monitoring.
- More agent ecosystems: require an AegisPay permit before any AI shopping or finance agent can spend.
- Broader coverage: Firefox and Safari testing, multi-currency and multi-language support, and accessibility audits.
Built With
- ag-grid
- chrome-extension-manifest-v3
- css3
- docker
- github-actions
- google-gemini-api
- google-oauth
- groq
- html5
- javascript
- llama-3
- model-context-protocol
- node.js
- paypal
- paypal-orders-v2
- paypal-rest-api
- paypal-subscriptions
- playwright
- postman
- react
- typescript
- vercel
- vite
- vitest
- web-speech-api