Inspiration

Checkout breaks when inventory shifts between PayPal approval and fulfillment: the merchant eats a refund and a lost sale, or silently swaps items and invites a chargeback. PayPal's intent=AUTHORIZE flow opens a consent-first window - the funds are only held - so I built SwitchCart to use that window honestly.

What it does

When an item sells out after the buyer approved a PayPal payment, SwitchCart's AI proposes 1-2 in-stock replacements from the merchant catalog with the exact price difference. The buyer explicitly accepts or declines. Only then does the server capture the open authorization (adjusted amount, reauthorizing first when the replacement costs more) or void it, so a decline always costs the buyer exactly $0.00. Every PayPal state change lands in a tamper-evident audit trail with real request/response IDs.

A merchant dashboard toggles stock and instantly flags affected open authorizations, and a deterministic rule engine guarantees a proposal even if the AI call fails.

How I built it

Node.js 20 + TypeScript on Next.js App Router route handlers, with all PayPal and AI calls server-side; PostgreSQL with Drizzle ORM; Tailwind v4 UI. Orders follow a strict state machine: CREATED -> PENDING_APPROVAL -> AUTHORIZED -> SUBSTITUTION_NEEDED -> AWAITING_CONSENT -> CAPTURED / VOIDED. An OpenAI-compatible Chat Completions call is seeded with the catalog snapshot, buyer preferences and per-product price deltas; all price math is re-derived server-side. Without PayPal keys, a deterministic simulator returns sandbox-shaped SIM- payloads so the full flow is demoable offline.

Challenges

Reauthorization rules (PayPal's honor period and amount limits) forced careful ordering: reauthorize-then-capture only when the replacement costs more, plain capture otherwise. Making decline truly free meant treating void as a first-class outcome, not an error path, and testing that path end to end.

What I learned

Agentic commerce only works when consent is explicit and auditable. The authorization window is the product.

Built With

Share this project:

Updates

Submission history