Inspiration
Last year we bought tickets to a multi-day event, and one of the days got cancelled. The organiser said refunds were "on the way". That way took a whole month. When the money finally arrived, it was less than we were owed, so we had to email them again, wait again, and explain our own ticket back to them.
Talking to them later, the reason was obvious: they were doing it by hand. Someone was going through thousands of buyers in a spreadsheet, working out who was owed what under the ticket terms, and clicking refunds one at a time. Some people got too little, some got paid twice, and everyone had to wait.
The hard part isn't sending a refund. It's working out the right amount for every buyer and making sure each one goes out exactly once. So we built RefundsOut.
What it does
A festival day gets cancelled? RefundsOut takes care of the mass refunds:
- Import: upload the sales export, gate scans and ticket terms in any layout. Gemini maps the columns, and bad rows are set aside with a reason, never dropped silently.
- Policy: Gemini turns the ticket terms into numbered refund rules, each quoting its clause word for word, plus test cases. Code checks every quote and runs every test. A person approves the version. For example, a 3-day pass with one day cancelled gets that day's share: $$\text{refund} = \text{price} \times \frac{\text{cancelled days}}{\text{festival days}}$$
- Review in AG Grid: every buyer's refund appears in one grid, grouped by rule, before any money moves. Risky cases (possible duplicates, buyers who didn't pay with PayPal) are pinned on top for a human decision. You can ask the grid in plain English ("refunds over $100, biggest first"). Run refunds stays locked until five checks pass, including sign-off by two different people over $2,500.
- Run: in a snap after approval, refunds go out through PayPal. Each payment is re-checked with PayPal first, and each refund carries a fixed
PayPal-Request-Id, so retries and crashes can never pay twice. Disputed payments get an offer through the dispute instead. - Reconcile: every cent is accounted for, refunds are confirmed with PayPal, duplicates are counted (zero), and every buyer gets a letter with their exact amount.
AI never writes a money amount. Gemini reads, maps and explains. The amounts come from a rules engine that uses integer cents.
How we built it
- Next.js 16 (App Router, Server Actions), React 19, TypeScript, Tailwind CSS 4
- PayPal REST APIs (sandbox): Captures, Refunds (with
PayPal-Request-Id), Orders, Disputes (make-offer) and Transaction Search - Google Gemini: column mapping, policy compile with clause quotes, buyer letter wording, and "Ask the grid"
- AG Grid Enterprise + AG Charts:
- AI Toolkit for Ask the grid
- row grouping with totals, pinned rows, cell editing with a required reason
- a cross-filter chart, a custom "Policy rules" side panel
- master-detail rows for per-ticket math, a status bar, and an audit-ready Excel export
- the live run grid and the audit log grid
- PostgreSQL as a crash-safe refund queue (
FOR UPDATE SKIP LOCKED), a refund ledger, and an append-only audit log
Challenges we ran into
- PayPal's view can lag behind reality. In testing, a "stop, then start a new plan" flow built the new plan before PayPal showed the refunds we had just sent, and 5 buyers would have been refunded twice. We added our own ledger of refunds already sent, checked before every send. Our double-refund test then showed 48 of 48 payments refunded exactly once.
- Crashes mid-run. We killed the server in the middle of a real sandbox run. Because every refund resends the same request ID, PayPal returned the original refund instead of a new one: 47 of 47 refunded exactly once.
- Making AI safe around money. The AI can only change the grid's view (filters, sort, grouping), never an amount. We also clean its answers before applying them, and show what it changed as chips.
- AI outages during a live demo. Gemini returned "high demand" errors while we tested. Ask the grid now fails fast with a plain message, and the example questions fall back to a stored answer that is clearly labelled.
- Messy real data: US-style dates,
N/Aprices, duplicate ticket IDs, cash buyers and free tickets. Each one became a set-aside rule or an exception, never a silent skip.
Accomplishments that we're proud of
- Real refunds in the PayPal sandbox, end to end, with zero double payments across our crash and lag tests.
- An approval flow a finance team would actually trust: five checks, two-person sign-off, and approvals that are cancelled by any later edit.
- A grid that explains itself: each rule, its clause, and the per-ticket math behind every amount.
What we learned
- Idempotency (
PayPal-Request-Id) is the single most important line in a refund system. - AI is great at reading terms and messy files. Amounts belong in tested code.
- A human approving the plan is a feature, not a delay. It's what makes refunding in a snap safe.
What's next for RefundsOut
- PayPal webhooks for instant refund confirmations
- Ticketing-platform imports (no CSV step)
- Partial cancellations across many events at once, for promoters and venues
- Going live with real organisers, so the next person whose day gets cancelled is refunded right in days, not a month
Built With
- ag-charts
- ag-grid
- google-gemini
- next.js
- node.js
- paypal
- paypal-rest-api
- postgresql
- railway
- react
- tailwindcss
- typescript
- vitest
- zod
