Inspiration
Small merchants and freelancers lose money in two quiet ways. A customer's card gets declined even though they wanted to pay, and nobody follows up. Or an invoice goes out days late because someone has to write it by hand. AI could clearly help, but we would never let an LLM near a payment API on trust alone. One bad guess and real money moves. So we asked ourselves: how do we get the AI's help without giving it any power?
What it does
Revenue Guardian recovers failed PayPal captures and turns plain English into invoices. When a payment is declined, an AI agent suggests what to do, like retrying or escalating. A policy engine then checks that suggestion, and a separate executor is the only part allowed to call PayPal. You can also type "invoice Priya for 3 hours of design at $60/hr" and get a real PayPal invoice draft.
Our rule is simple: the AI proposes, the code decides, and the executor acts.
To show it working in a real flow, we built CampusVault, a student store. It uses Revenue Guardian for invoices, failed-payment triage and refunds. Refunds up to $25 go through instantly, and anything bigger waits for a manager to approve it.
How we built it
- AI proposes: An LLM through OpenRouter returns a structured proposal. A Zod schema validates it, and a grounding check rejects any claim that isn't backed by our database.
- Code decides: A pure TypeScript policy engine returns AUTO, NEEDS_APPROVAL or BLOCKED based on confidence, amount, retry count and currency. If it sees anything unexpected, it fails closed and asks a human.
- Executor acts: Only the executor holds PayPal credentials. Every call uses an idempotency key, so a retry can never double-charge. Approvals use single-use tokens that are tied to the exact proposal, so replaying one returns a 409.
- Staying in sync: We use real PayPal webhooks plus a polling worker.
- Audit trail: Every step is saved in an append-only PostgreSQL ledger and shown in an AG Grid interface.
Built with Next.js, PostgreSQL, Drizzle ORM, Redis, BullMQ, PayPal Orders v2 and Invoicing v2 (Sandbox), and OpenRouter.
Challenges we ran into
- Stopping the AI from making things up. Early on it would give reasons that sounded right but weren't in our data, so we added the grounding check.
- Making sure a payment is never retried or refunded twice, even if a request or webhook arrives more than once.
- Keeping our records in sync with PayPal when webhooks are late or missing, which is why we added the polling worker.
Accomplishments that we're proud of
- An AI agent that is useful but can't move money on its own.
- Every decision can be traced from the AI's suggestion to the PayPal call in the audit log.
- A full working store (CampusVault) where you can break a payment on purpose and watch it get triaged live.
What we learned
Trust in AI systems comes from the code around the model, not from the model. Small things like idempotency keys, fail-closed defaults and hashed single-use tokens matter more than a clever prompt. We also learned a lot about how PayPal's payment and invoice lifecycles actually behave.
What's next for Revenue Guardian
- Recurring subscriptions and billing agreements
- Automated dunning (scheduled reminder emails)
- Full dispute evidence submission through the Disputes API
Built With
- ag-grid
- ai-agents
- azure-static-web-apps
- better-auth
- bullmq
- drizzle-orm
- fintech
- llm
- neon
- next.js
- openrouter
- paypal
- paypal-invoicing-api
- paypal-orders-api
- paypal-sandbox
- postgresql
- redis
- tailwind-css
- typescript
- zod