Inspiration
Small sellers lose time and money to PayPal disputes. Sellers say so in their own words, for example on Hacker News: "Usually when this happens I have to spend hours on this and contact PayPal by phone to get the money back." (NorwegianDude, 2023-08-16, https://news.ycombinator.com/item?id=37144007). Each dispute has a deadline, a list of evidence PayPal wants, and three possible seller actions, and choosing among them takes judgement.
What it does
Dispute Copilot pulls every open dispute from the PayPal Disputes API (the hosted demo uses the PayPal sandbox) and orders the queue by seller deadline (soonest first); disputes with no seller deadline come last, ordered by amount at risk. For each dispute it:
- Maps the buyer's reason to the evidence types PayPal asks for and marks which ones the order, capture and tracking facts already cover.
- Computes a transparent 0-100 win score where every point is a labelled factor.
- Recommends one action: fight with evidence (score >= 60), offer a partial refund (30-59), or accept (< 30, or amount under 15).
- Has an AI model write the assessment and the draft that PayPal would receive.
- Shows the exact API request. Nothing is sent until the seller previews it and clicks Approve & send.
How we built it
TypeScript + Express server, AG Grid Community for the queue, esbuild front end, vitest tests, Docker + Render free tier. PayPal APIs: OAuth token, Disputes v1 list/get (states REQUIRED_ACTION and UNDER_PAYPAL_REVIEW), provide-evidence (multipart), make-offer, accept-claim, plus capture, order and shipping-tracker reads for order facts. AI: Gemini on the free tier through an OpenAI-compatible endpoint, with a fallback chain of models: if one model has no quota left, the next one writes the draft, and every draft in the UI is labelled with the model that wrote it. Design rule: the LLM writes, code decides. Code picks the action from the rule score; the model does not change the score or the action, so the score is the same on every reload. The recommendation is limited to the actions PayPal currently allows for that dispute. Buyer messages are fenced as untrusted data in the prompt. If every model fails, a deterministic template writes the draft and is labelled "(template)".
Safety choices
- Writes need an admin token; without it the server is read-only (403).
- Writes to PayPal are sent exactly once and never retried: on a timeout or 5xx the server reports "status unknown, verify in the Resolution Center" rather than risk a duplicate.
- Only PayPal's safe error fields (name, message, details[].issue) reach the UI.
- If order or tracking facts cannot be read, the case goes to human review, never to a silent refund.
- The client refuses any non-sandbox PayPal URL.
Challenges
Keeping the human gate honest: approve sends exactly the previewed request and never re-runs the model. Handling partial PayPal outages without a duplicated write.
Two problems appeared only when we ran against the real PayPal sandbox; the mocked responses had not shown them:
- Zero-decimal currencies. The sandbox business account is in Japan and its disputes are in JPY. PayPal expects JPY amounts without decimals, so a half-refund offer on the 2,980 yen tote bag is sent as "1490" with no decimals (on the hosted app, pick OFFER in the Action menu of the tote bag case and click Preview). The money formatting and the score thresholds (written in USD) now handle JPY, HUF and TWD.
- Case state. Most new disputes sit in UNDER_REVIEW (the value the API returns; the list filter is UNDER_PAYPAL_REVIEW), and every case the seller has already answered moves there. A queue filtered on REQUIRED_ACTION looked empty. The queue now lists both states; a case under PayPal review is shown as informational: the draft is headed "Prepared note (not sendable now)", the hours column shows a dash (no seller deadline), the page says "PayPal allows no seller action for this dispute now (status UNDER_REVIEW)" and Preview is disabled, because PayPal accepts no seller response in that state.
Honest status
- 108 automated tests pass (build 9a88ddb, 2026-11-10). They cover the PayPal client against mocked responses, the scoring rules and the safety gates.
- The hosted demo runs against the PayPal sandbox.
/api/healthshows"paypal":"sandbox". The queue holds 5 live sandbox test disputes on our test business account (JPY): a camera 36,000 (unauthorised), a keyboard 18,500, wireless earbuds 9,800, a mug 4,800 and a tote bag 2,980 (not as described). Win scores are fixed by the rules: tote bag 15 (ACCEPT, insufficient facts, human review), camera 43, keyboard 43, mug 43, wireless earbuds 57 (OFFER, informational only). The other four are claims of non-receipt or unauthorised use; all four are in PayPal's UNDER_REVIEW state, where PayPal allows no seller action, and only the tote bag still waits for a seller response (PayPal allows OFFER and ACCEPT there). Scores are rule-only. Each assessment and draft names the AI model that wrote it (for example "AI · gemini-3.5-flash-lite"; when a model is out of quota the label shows the fallback model). Evidence for the camera case was submitted earlier from a local run. - Verified against the sandbox on 2026-11-10: OAuth, dispute list and detail, capture, order and tracker reads, and one provide-evidence multipart submission (sent from a local run with an admin token; PayPal answered 200). make-offer and accept-claim were previewed against real disputes but not sent.
- The public demo is read-only so that nobody can change our sandbox cases: Preview works and shows the exact PayPal request, the page shows "Approve disabled: this demo server is read-only" and the server answers 403 because no admin token is set.
- Without PayPal keys, a local
npm startfalls back to five fixture disputes.
What's next
Webhook CUSTOMER.DISPUTE.CREATED instead of polling; evidence file generation; per-seller thresholds.
Links
Built With
- ag-grid
- docker
- esbuild
- express.js
- google-gemini
- paypal-disputes-api
- paypal-sandbox
- render
- typescript
- vitest