feat(stripe): Stripe-first checkout via optional-auth POST /sessions + claim (app#2044)

Merged
SW
3mo ago
+950-281

Implements Stripe-first paid funnel for recoupable/app#2044. Contract: recoupable/docs#325 (merge first). Depends on #876 (merged).

What ships

PieceBehaviour
POST /api/subscriptions/sessionsAuth 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/claimAuth required, { session_id }. Re-stamps when sign-in email ≠ billing email.

No separate /api/subscriptions/checkout — folded into /sessions.

Test plan

  • Anonymous POST /sessions with { successUrl, cancelUrl } returns { id, url } and Stripe session has no customer / accountId
  • Authenticated POST /sessions attaches customer + accountId
  • Starter without STRIPE_STARTER_PRICE_ID → 400 starter_unavailable
  • Invalid auth header → 401
  • Claim still works for email-mismatch after webhook link