feat(stripe): Stripe-first checkout via optional-auth POST /sessions + claim (app#2044)
Merged
SW
3mo ago+950+950+012345678901234567890123456789-281-281-012345678901234567890123456789
Implements Stripe-first paid funnel for recoupable/app#2044. Contract: recoupable/docs#325 (merge first). Depends on #876 (merged).
What ships
| Piece | Behaviour |
|---|---|
POST /api/subscriptions/sessions | Auth optional. Body { plan?: "starter" | "pro", successUrl, cancelUrl? } (plan defaults to pro). No auth header → anonymous session (metadata { plan, source: "checkout_unauth" }); Stripe creates the customer from the typed email. Valid Bearer / x-api-key → account customer + accountId metadata. Invalid auth header → 401. Starter while STRIPE_STARTER_PRICE_ID unset → 400 starter_unavailable. Response { id, url }. |
checkout.session.completed (subscription mode, no metadata.accountId) | processCheckoutSubscriptionCompleted: find-or-create account from billing email, stamp accountId on subscription + customer. |
POST /api/subscriptions/claim | Auth required, { session_id }. Re-stamps when sign-in email ≠ billing email. |
No separate /api/subscriptions/checkout — folded into /sessions.
Test plan
- Anonymous
POST /sessionswith{ successUrl, cancelUrl }returns{ id, url }and Stripe session has nocustomer/accountId - Authenticated
POST /sessionsattaches customer +accountId - Starter without
STRIPE_STARTER_PRICE_ID→ 400starter_unavailable - Invalid auth header → 401
- Claim still works for email-mismatch after webhook link