Inspiration
An AI can recommend a purchase, but a recommendation should not automatically become permission to spend. I built PayGuard to check an agent’s request against clear spending rules before it reaches PayPal.
What it does
A user describes a purchase. OpenRouter sends the request to the configured AI model, which returns a structured proposal. PayGuard then checks the merchant, amount, currency, and budget against a policy.
If the request is allowed, PayGuard creates a signed payment intent, reserves the budget, and creates a PayPal Sandbox order. A person approves the order in PayPal Sandbox before it can be captured. Requests outside the policy are denied before a provider order is created.
The dashboard shows policies, intents, transactions, and audit events. The audit chain can be checked for changes. Five MCP tools let compatible clients use PayGuard’s policy and payment-status functions.
How I built it
PayGuard uses TypeScript, Node.js, Fastify, React, and SQLite. Payment intents are signed with Ed25519. Budget reservations use SQLite transactions. PayPal Sandbox handles checkout and capture.
For AI proposals, PayGuard uses the OpenAI-compatible SDK with OpenRouter. My demo configuration uses NVIDIA Nemotron. The model suggests purchase details; deterministic policy checks make the spending decision. The MCP server exposes five tools over stdio.
Challenges I ran into
AI models can return different formats, so I validate their output before using it and keep the payment decision in the policy engine. Free model availability and response limits also vary.
I also had to make budget changes and reservation releases preserve the remaining balance, and keep the payment state consistent through approval, checkout, and capture.
Accomplishments I’m proud of
I connected an AI-generated proposal to a real PayPal Sandbox checkout flow while keeping policy checks between the model and payment provider. The project also includes signed intents, budget reservations, replay and expiry checks, an audit-chain verifier, and MCP tools.
The automated suite has 85 tests across 12 files. It covers policy decisions, budgets, payment flows, AI output handling, and audit behavior.
What I learned
AI is useful for turning a request into structured purchase details. It should not decide whether money may be spent. Keeping those responsibilities separate makes the decision easier to inspect and test.
What’s next for PayGuard
Before using PayGuard beyond a local demo, I would add API authentication, support for safe multi-process operation, and a way to resolve payments whose provider result is uncertain.
Built With
- fastify
- mcp
- node.js
- openrouter
- paypal
- react
- sqlite
- typescript