Inspiration

When a payment service breaks, customers are charged for failures or left waiting, and compensation is usually slow, manual and inconsistent. I wanted a system that notices an outage, proves what happened, and compensates only the customers who were hurt, with a clear audit trail. The other goal was to use AI for the part it's good at (explaining incidents) and keep it away from the part where mistakes are costly (moving money).

What it does

AegisPay watches payment traffic, detects an outage, gathers evidence, explains the incident, and issues compensation through PayPal.

  • Detection: an incident opens after 3 consecutive failures, resolves after 5 successes, and is deduplicated.
  • Evidence: failed attempts are recorded with IDs, so every claim can be traced back.
  • AI explanation: an LLM writes a diagnosis from the evidence and cites attempt IDs. Its output is validated, and it falls back to rules if it's invalid. If the LLM disagrees with the rules, that is flagged.
  • Compensation: deterministic policy rules set the amount based on severity. The LLM never decides money.
  • Refund: after operator approval, AegisPay issues a PayPal partial refund on a captured payment, with an idempotency key so a retry can't double-pay.
  • Audit trail and dashboard: every step is logged, and a web dashboard shows live attempts, incidents, evidence, the AI diagnosis and the refund.

In my end-to-end run, one incident had 32 failed attempts and was rated critical. It produced a real PayPal sandbox refund of $1.00 on a real capture, plus a mock refund clearly labelled as mock. A customer who wasn't affected got nothing.

How we built it

  • Backend: FastAPI, SQLAlchemy and httpx, with Postgres 17 locally (SQLite in the hosted demo), all in Docker.
  • Payments: PayPal sandbox with OAuth, orders, captures and partial refunds.
  • AI: Groq openai/gpt-oss-20b, treated as an untrusted advisor behind schema validation and a rule-based fallback.
  • Architecture: a payment service with a fault switch, a traffic watcher, a detector, an evidence builder, a settlement module and an operator approval step.
  • Dashboard: a single /ui page with light and dark themes, a live chart, a feed and demo buttons (break, slow, recover, run AI, approve and refund).
  • Hosted demo: one Render free web service with an embedded simulator, built-in traffic, destructive writes blocked, mock refunds only and AI limited to 20 calls per hour.
  • Tests: 5 suites with 34 checks (detection, settlement, AI explanation, UI API, public demo), using a fake PayPal and SQLite.

Challenges we ran into

  • Payouts API blocked: PayPal's Payouts API was blocked for my India sender account. I switched the compensation rail to partial refunds on captured payments.
  • Sandbox checkout: the India Business sandbox with an India buyer hit a checkout error, so I used a US Business sandbox app with a US personal buyer. The PayPal checkout page also spins at times, so real payments need retries.
  • Refunds need captures: each refund requires a previously captured payment, which needs a one-time browser approval by the buyer.
  • Trusting the LLM: the LLM was right 4 of 5 times against the rules baseline's 5 of 5. That convinced me it should explain incidents but never set amounts.
  • Free hosting: the demo had to be safe on public free hosting, so I added the public-demo guard, mock refunds and an AI rate limit.

Accomplishments that we're proud of

  • A complete loop (detection, evidence, explanation, compensation, refund, audit trail) that works end to end with a real PayPal sandbox refund.
  • A design where the AI can't move money. Money decisions are deterministic, idempotent and auditable.
  • A small, clean, explainable codebase with 34 passing checks.
  • A public demo that anyone can try safely.

What we learned

  • LLMs are strong at summarising evidence but should be advisors, not decision-makers. Validation, fallbacks and disagreement flags matter more than the model choice.
  • Idempotency and reconciliation are the core of payment code. Retries and timeouts will happen.
  • Evidence first: if every claim points to attempt IDs, humans can verify an AI explanation in seconds.
  • Sandbox restrictions shape the design. Being honest about them is better than hiding them.

What's next for AegisPay

  • Kubernetes: move from plain Docker to Kubernetes with auto-remediation and verification that a fix worked.
  • Policy: configurable compensation policies per merchant, plus SLA reporting.
  • Reconciliation: automatic handling of unknown or timed-out refund states.
  • Real traffic: connect to real merchant traffic instead of the simulator.
  • Production readiness: replace the demo thresholds, and test beyond the US sandbox merchant.
Share this project:

Updates

Submission history