-
-
A needle stitches a broken yarn road while a cashback coin rolls toward a customer's PayPal wallet.
-
Mend's forecast splits the steady, the slipping and the long gone.
-
Step 01. The quiet regulars worth a nudge, biggest spenders first.
-
Step 02. Claude reads the owner's goal into a plan, and code clamps every number to the shop's caps.
-
Step 03. Every reward and every Claude-written note is on screen before the owner approves that exact plan.
-
Step 04. One PayPal Payouts batch, each line confirmed by a signed PayPal webhook.
-
Step 05. The paid group against the held-back group. A simulated return is kept apart, and five people are too few for a verdict.
-
Step 07. The owner's dashboard on AG Studio, with our own "Did it work?" and "Every customer's thread" widgets beside live PayPal totals.
-
The Mend analyst, our own agent inside AG Studio, explains the verdict from real rows. It has no tool that sends money.
-
The shop page: quiet regulars by forecast group, who can be paid, and how long each has been silent.
-
Step 06. Real attacks against the live app, each refused, with what stopped it.
-
Why the middle group: tested on two years of a real shop's orders.
-
How the web app, the private engine, Postgres, PayPal and Claude fit together.
Why PayPal is the heart of it
The cashback lands in the PayPal wallet the customer already pays with, one tap from their next order at the same shop. Customers opt in with Log in with PayPal, each campaign goes out as one PayPal Payouts batch carrying the shop's own note, and cashback nobody claims comes back to the shop through the Payouts cancel call. Take PayPal out and there is nothing left to send.
The problem
Regular customers rarely leave with a complaint. They just stop ordering, and a small shop notices months later, if at all. The usual fixes are a discount code sent to everyone or a points app. Neither tells the owner whether the money changed anything.
What it does
The owner works through five steps in one console.
- See who went quiet. Mend's forecast reads the shop's own order history. In the demo shop, 1,357 regulars went quiet. Mend skips the 77 it calls likely gone and the 170 likely to come back anyway, and lists the 1,110 worth a nudge, biggest spenders first.
- Ask Claude for a plan. The owner types a goal in one sentence, like "bring back my quiet regulars, 50 dollars". Claude reads it into a budget, a reward size and how many customers to consider. Code clamps every number to the shop's caps, picks the customers and draws a random held-back group before Claude sees anyone.
- Approve the exact plan. Every reward and every note is on screen. Claude can write a short personal note for each customer from their own past items. The owner approves that exact plan by its fingerprint, and nothing else can be sent.
- Watch PayPal pay it. One Payouts batch goes out. Each customer's line is stitched as PayPal confirms their payment through a signed webhook.
- See if it worked. Returns are counted for 30 days, paid group against held-back group. Mend says "too early to tell" until there is enough data, then gives a verdict from Fisher's exact test.
Step 07 is the owner's dashboard, built on AG Studio: three pages of live numbers the owner can rearrange, two widgets we built ourselves ("Did it work?" and "Every customer's thread"), and a Mend analyst agent that works with Studio's built-in agents. It explains results from real rows, and it has no tool that sends money.
Step 06, Break it, lets anyone attack Mend from their own browser: eleven real requests against the live app, such as talking Claude into paying 500 dollars a customer, approving a plan with a changed fingerprint, sending a plan nobody approved or forging a PayPal webhook. Each card shows the real answer and what stopped it.
There is also Ask Mend, a chat where the owner asks Claude about the shop, a campaign or a PayPal order. Claude reads through Mend's own read-only tools and PayPal's MCP server, with a fallback to PayPal's REST API when that server fails. It has no tool that sends money.
Why these customers, and not the most at risk
We tested this on a real shop's history, two years of a UK gift wholesaler's orders. At five past dates, quiet regulars the forecast called likely gone came back on their own 10 percent of the time (9 of 92). Those likely to come back anyway did 60 percent of the time (653 of 1,088) with no cashback at all. The middle group came back 38 percent of the time (1,371 of 3,595). That middle group is where a nudge has room to change something, so that is who Mend pays. The held-back group in every campaign then measures whether it did.
How we built it
- Web app: Next.js and TypeScript on Render. The landing page, the demo console, the docs, the API, the PayPal webhook receiver and Join with PayPal.
- Dashboard: AG Studio 3.0.0 with our own theme, two custom widgets, a custom Mend analyst agent, and our own lead agent, so the analyst can hand chart work to Studio's built-in agents. Claude runs behind our own route. No key reaches the browser.
- Art: the clay town, the film and every icon are built from Python scripts in Blender and rendered on one laptop. No stock art. The scripts are in the repo.
- Engine: Python on a Render private service with no public URL. It is the only code that moves money: it scores customers, builds drafts, sends Payouts batches and cancels unclaimed rewards.
- Forecast: a BG/NBD model we wrote ourselves. It reproduces the published CDNOW parameters from Fader, Hardie and Lee (r 0.243, alpha 4.414, a 0.793, b 2.426).
- Database: Postgres with an append-only audit log. Each service connects as its own database role.
- PayPal: Payouts (send, read, cancel unclaimed), Log in with PayPal, Orders with the sandbox test card for simulated return purchases, and signed webhooks. Mend checks every signature itself against PayPal's certificate. The assistant reads orders and disputes through PayPal's MCP server, using a second PayPal app whose keys cannot send payouts. When that server fails, the same reads go straight to PayPal's REST API with the same keys.
Tools used
- Claude Haiku 5.5 (
claude-haiku-5-5) on the Anthropic API does three jobs:- it reads the owner's goal into capped plan settings;
- it writes each customer's thank-you note from their past items;
- it answers the owner's questions in Ask Mend.
- Claude never sets an amount, never chooses who is paid, and never approves or sends. Code does all money math in whole cents and checks it twice.
- PayPal's MCP server gives the assistant its order and dispute reads, with PayPal's REST API as the fallback.
- AG Studio runs the owner's dashboard, its custom widgets and its agent team.
Challenges we ran into
- Honest numbers. Our forecast beats "sort by last order" across all customers, at 5 of 5 test dates. Among quiet regulars it only ties. We show both on the landing page instead of hiding the tie, and we used the forecast for what it is good at: splitting customers into groups.
- Webhooks we can trust. Mend refuses forged and replayed PayPal webhooks, and it re-reads every payout from PayPal before recording anything.
- Prompt injection. Customer item names and PayPal answers go to Claude as data. Our evaluation plants instructions in notes, goals, chat and PayPal answers, and Claude does not follow them.
- A tool that went down mid-build. PayPal's hosted sandbox MCP server started failing every tool call on 28 Oct, and PayPal confirmed the fault. We kept it as the first path and added a direct REST fallback with the same read-only keys, so Ask Mend kept answering. Our check on 3 Nov still found the server down and the fallback carrying the reads.
Accomplishments we're proud of
- A live proof on the deployed site that passes 19 of 19 checks. It runs a demo plan written by Claude and a real sandbox Payouts batch. It verifies the webhook delivery and refuses a forged one. It cancels the unclaimed cashback and counts a simulated return purchase.
- 980 engine tests and 1,535 web tests passing.
- The agent evaluation passes 16 of 16.
What we learned
The most at risk customers are mostly a waste of a nudge, and the safest ones mostly come back without one. We only saw that because we measured it.
What's next
- Real shops trying it on their own PayPal history.
- Offering Mend's guarded payouts tool to PayPal's Agent Toolkit, which has no payouts tool today.
Built With
- ag-grid
- ag-studio
- anthropic
- claude
- log-in-with-paypal
- next.js
- paypal
- paypal-mcp
- paypal-orders
- paypal-payouts
- paypal-webhooks
- postgresql
- python
- react
- render
- tailwindcss
- typescript