Inspiration
Small businesses pay bills by hand. The owner opens a PDF, types the numbers into a spreadsheet and sends the money. That routine is what invoice fraud relies on. A fake bill copies a real vendor's name and logo, changes the payment address and adds "urgent, our details have changed". Duplicates are the quieter problem: the same bill arrives twice and gets paid twice. Large companies have accounts payable teams for this. A five-person shop has one tired person at the end of the day. I wanted to give that person a clerk who reads everything, remembers everything and never pays without asking.
What it does
payD takes a bill as a PDF or a photo and does four things.
- Reads it. A vision model extracts the vendor, PayPal email, invoice number, dates, line items, tax and total, with a confidence score for each field.
- Checks it. Six risk checks run on every bill: duplicate, payee changed, unusual amount, math mismatch, lookalike vendor and pressure language. Each flag states its evidence, for example: "Past 6 payments to Asha Traders went to [email protected]. This bill asks for [email protected]."
- Asks. Bills wait in an inbox sorted by risk. A high-risk bill cannot be approved without a typed reason.
- Pays. Approved bills are paid with PayPal Payouts. A verified PayPal webhook, or a status check when webhooks are late, marks the bill paid. Everything lands in an AG Grid ledger with saved views, categories and CSV export.
The demo loads an invented jewelry studio with five vendors and 35 paid bills, then five new bills. Three are genuine and get paid in the PayPal sandbox. One is a second copy of a bill already paid. One is a fake with a changed payee, four times the usual amount and an urgent note. payD stops both and explains why.
How I built it
- Next.js and TypeScript in strict mode, with Tailwind.
- Postgres and Prisma. Money is stored as integer cents. Bills move through a small state machine and every change writes a timeline entry.
- PayPal sandbox. OAuth, Payouts (create and get batch) and webhook signature verification. Each payout uses a batch id and request id derived from the bill id, and the database allows one payout per bill, so a double click or a retry cannot pay twice.
- Risk engine. Five checks are pure functions over the bill and the vendor's history. The sixth uses the model to read the payment instructions, with a keyword scan as a fallback.
- Google Gemini through the Vercel AI SDK for reading bills and explaining flags.
- AG Grid Community for the ledger and Render for hosting.
- 75 automated tests, including double payment, payment without approval, replayed webhooks and bad signatures.
Challenges
- Making "pay once" true, not just likely. PayPal only blocks a reused batch id for 30 days, so I added a row lock, unique keys and a request id. Five parallel clicks create exactly one payout.
- Webhooks that cannot be faked. Every delivery is verified with PayPal before it is trusted.
- The sandbox is not production. Demo vendor emails are invented, but a payout needs a real sandbox account. payD keeps the email printed on the bill separate from the sandbox account that is paid, and shows both.
- Free-tier model limits. The main Gemini model was overloaded and the first fallback ran out of quota, so I added a chain of fallback models and a cache keyed by file hash.
What I learned
- Keep the model away from decisions about money. It reads and explains. Rules decide the risk level and a person decides the payment.
- An explanation with evidence is worth more than a score.
- Idempotency has to be designed at three levels: the request to PayPal, the database and the user interface.
What's next
- An "Ask payD" assistant that creates and sends PayPal invoices with the PayPal Agent Toolkit.
- Accounts, roles and two-person approval for large bills.
- Bills read straight from an email inbox.
Built With
- ag-grid
- claude-code
- gemini
- next.js
- paypal
- postgresql
- prisma
- react
- render
- tailwindcss
- typescript
- vercel-ai-sdk
- vitest
- zod