Unhappy Path

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 /checkout creates a PayPal order the way your shop normally does and returns { order_id }.
  • POST /approve runs your normal “buyer came back” capture code. Forward the X-Unhappy-Mock header as PayPal-Mock-Response so the agent can make PayPal decline.
  • GET /probe?order_id= reports what your database believes: status and how many times you fulfilled it.

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
  });
}