Break your PayPal checkout before your customers do.
Unhappy Path is an AI agent that runs your sandbox integration through the things that go wrong in real life — declined cards, forged and duplicate webhooks, refunds from the PayPal dashboard, tampered prices — then tells you whether it's safe to go live, and how to fix what isn't.
1
Choose what to test
Test your own app: the test contract
Unhappy Path drives your real checkout code, so your sandbox build exposes three small endpoints. They wrap code you already have; nothing here should ship to production.
POST /checkoutcreates a PayPal order the way your shop normally does and returns{ order_id }.POST /approveruns your normal “buyer came back” capture code. Forward theX-Unhappy-Mockheader asPayPal-Mock-Responseso the agent can make PayPal decline.GET /probe?order_id=reports what your database believes:statusand how many times youfulfilledit.
Then give the agent your webhook URL and sandbox keys. It pays as a test buyer with a sandbox card, refunds through PayPal, and asks PayPal to resend real signed webhooks.
// app/api/unhappy-path/approve/route.ts (Next.js)
export async function POST(req: Request) {
const { order_id } = await req.json();
const mock = req.headers.get("x-unhappy-mock");
// your existing capture code, plus the sandbox hook:
const r = await captureOrder(order_id, mock
? { "PayPal-Mock-Response": mock } : {});
return Response.json(r);
}
// app/api/unhappy-path/probe/route.ts
export async function GET(req: Request) {
const id = new URL(req.url).searchParams.get("order_id");
const o = await db.orders.findByPayPalId(id);
return Response.json({
status: o.status, // pending | paid | refunded | failed
fulfilled: o.shipments, // how many times you shipped it
});
}