Inspiration
Cancelling a subscription is often the worst part of having one: hidden buttons, retention mazes, "call us to cancel." Merchants lose out too. Some customers would have stayed for a pause or a lower price, but a blanket "are you sure?" screen can't tell who. And a lot of churn isn't a choice at all: a card fails and the subscription quietly dies. We wanted a cancel flow that's fair to both sides. It listens, makes at most one honest offer, and never stands between a subscriber and the exit.
What it does
BeforeYouGo is a cancel agent for PayPal subscriptions, shown on a demo coffee subscription, Kettle & Crumb.
- An agent asks why the subscriber is leaving, records the reason, and offers at most one remedy that fits: a pause, a discount, a cheaper plan, or a refund of the last charge. A one-step "Cancel now" button stays visible the whole time.
- If the subscriber accepts, the app suspends, re-prices, refunds or cancels the subscription through PayPal's APIs. It then re-reads the subscription from PayPal and only reports success once PayPal agrees.
- A policy engine decides which remedies each subscriber can get, based on tenure, payments, past refunds and past offers. The model picks from that list by id. Its tools have no fields for amounts, percentages or durations, so it can't invent a deal. Each subscriber gets one offer per year, and anyone who starts and abandons cancelling twice in 90 days gets no offer, so gaming the flow doesn't pay.
- A verified PAYMENT.FAILED webhook sends an email, shows a banner on the account page, and opens a recovery chat where the subscriber can resume billing or move to a lower price.
- Subscribers who leave can opt in to a reminder that matches their reason: a discount later if price was the problem, or a "here's what shipped" note if a feature was missing.
- A merchant dashboard shows every session with its reason, remedy and net revenue saved, defined on the page as retained price × 3 billing cycles minus the cost of the offer. It also has a reasons chart, a trace of every tool call the agent made and what the code answered, webhook deliveries, an email outbox, CSV export, and policy settings the merchant can edit.
How we built it
- React Router 8 (framework mode), React 19 and TypeScript, with Tailwind, shadcn/ui and Better Auth.
- PostgreSQL on Neon with Sqitch migrations. Migrations and the app use separate database roles, so the running app can't change the schema.
- Claude Opus 5.5 through the Anthropic SDK: three tools (set_reason, present_offer, execute_remedy), streamed replies, and a policy snapshot frozen at the start of each session. - PayPal's Subscriptions, Payments (refunds) and Webhooks APwebhook signature verification.
- AG Grid Community for the dashboard and react-email for branded recovery and win-back emails.
- Google Cloud Run (scales to zero), Cloud Build, Artifact Registry and Secret Manager.
Challenges we ran into
- Switching plans needs the buyer's approval. PayPal's plan-switch call returns an approval link and leaves the plan unchanged until the buyer consents. For discounts and downgrades we lower the price on the existing subscription instead, which takes effect immediately.
- You can't make a payment fail on demand. PayPal's webhook simulator sends canned events that don't match a real subscription. To show real recovery, we gave a daily-billed subscriber an empty sandbox wallet and waited. The real failure arrived, passed signature verification, and opened the recovery flow.
- The agent took back its own offer. Presenting an offer writes it to the ledger, and a fresh policy check then said "already offered this year." Freezing the policy when each session starts fixed it.
Accomplishments that we're proud of
- No mocks: Discount, pause, refund, agent-led cancel, one-step cancel, win-back rejoin and a real failed payment all ran end to end on the PayPal sandbox.
- The model can't give away money it isn't allowed to: Every number comes from the policy engine, and the trace shows every tool call the code refused.
- Cost: The hosted demo costs close to nothing when nobody is using it.
What we learned
- Let the model handle the conversation and the code handle the money. Narrow tools that pick an id from an allowed list made the agent both safer and easier to test.
- Evals with a real model and a fake executor catch prompt regressions that unit tests miss.
- Payment APIs have rules you only find by trying them: what can be refunded and when, how webhooks arrive. Checking each one against the sandbox before building on it saved us from wrong assumptions.
What's next for BeforeYouGo
- Package it as a drop-in component any PayPal merchant can add to their account page.
- Onboard merchants through PayPal so it runs on live subscriptions, not just the sandbox.
- Track which offers actually keep people for each reason, and suggest policy changes the merchant can approve.
Built With
- ag-grid
- cloudrun
- neon
- node.js
- paypal
- postgresql
- react
- typescript