Inspiration

When something arrives slightly damaged, small merchants usually refund the whole price and pay for return shipping, for an item that ends up in the bin anyway. The buyer waits a week for their money, and the merchant loses the sale, the shipping and the item. Most of the time both sides would happily settle for a fair partial refund if agreeing on "fair" weren't such a hassle.

What it does

  1. The buyer pays with PayPal as usual.
  2. If the item arrives damaged, the receipt has a "Report damage" link. The claim page shows a 4-character code that's valid for 30 minutes. The buyer writes it on paper and photographs it next to the damage, which proves the photo is fresh.
  3. AI looks at the photo and returns a strict JSON grade: what's damaged, where, how badly, whether it's a real camera photo, whether it's the right item, and whether the code matches.
  4. A deterministic rules engine, not the AI, turns that grade into an offer using the merchant's policy (for example, a minor defect gets 20% of the price, with a 60% ceiling).
  5. The buyer accepts, or counters once. A small counter is accepted automatically.
  6. ClipPay issues a partial refund on the original PayPal capture. The buyer keeps the item, and nothing gets shipped back.
  7. Anything suspicious or expensive goes to the merchant instead: a fake or reused photo, the wrong item, a missing code, low confidence, or an amount above the ceiling or the auto-approve limit. The merchant dashboard shows the photos, the grade and the reasons, and settles the claim in one click. It also shows how much the merchant saved compared with full returns.

How we built it

  • Next.js on Cloudflare Workers (via OpenNext), with D1 for orders and claims and the Cloudflare Images binding for resizing photos.
  • PayPal Orders v2 for checkout and capture, and PayPal Payments v2 refunds for partial refunds on the capture. Every refund carries a PayPal-Request-Id (refund-<claimId>), so retries can never pay twice.
  • Gemini vision model with a zod-validated JSON schema for the grade. The same code runs in Node and on Workers.
  • Rules engine in pure TypeScript: no I/O, no model calls, all money in integer cents. It's the only place a refund amount is decided, so the AI can't overspend. There are 42 unit tests across the rules and photo checks.
  • Fraud checks: the fresh-photo code, exact SHA-256 and perceptual (dHash) duplicate detection, a per-buyer claim limit, and confidence thresholds. Buyers never see these signals; a claim under review just says a person will look at it.
  • AG Grid merchant dashboard with approve, decline and retry actions.
  • Demo video: built in Remotion. AI text-to-speech narration, AI-generated music, sound effects synthesized in code, and a screen recording of the live sandbox flow.

Challenges we ran into

  • Keeping the AI out of the money. A model that prices refunds directly is hard to audit and can't be trusted with a hard ceiling. We split the work so the model only describes the damage and a deterministic engine sets the price, which keeps every amount explainable and testable.
  • Running image processing on Workers. There's no sharp at the edge, so the Workers build resizes photos with the Images binding and decodes a tiny PNG itself to compute the 64-bit perceptual hash.
  • Idempotent refunds. Making approve, counter and retry safe to repeat meant tying every refund to the claim's request ID and using compare-and-swap updates in D1.

Accomplishments that we're proud of

  • The full loop runs live in the PayPal sandbox, from checkout to the photo, the grade, the offer and the partial refund on the capture. A claim settles in seconds.
  • The AI catches fake photos. Given a drawn plate, it flags the image as "not a real photo" and sends the claim to review rather than paying it.
  • The merchant only ever sees the claims that actually need a human.

What we learned

  • Letting the vision model describe the damage and leaving the pricing to plain code makes every refund explainable. A schema plus a rules engine beats a clever prompt.
  • PayPal's partial refunds on a capture are a natural fit for settling claims without a return.

What's next for ClipPay

  • Evaluate grading on a larger set of real damaged-item photos.
  • Let merchants edit their own policy from the dashboard.
  • Package it as a plugin for shop platforms that already use PayPal checkout.
  • Add support for PayPal disputes, so a claim can be settled before it becomes a dispute.

Built With

Share this project:

Updates

Submission history