Migrate stripe subscription checkout sessions

Merged
AH
6mo ago
+767-1

Summary by cubic

Adds POST /api/subscriptions/sessions to create Stripe subscription checkout sessions with CORS, strict input/auth validation, and safer error handling. Sessions use a fixed price with a 30‑day trial and return { id, url }; uses stripe and uuid and requires STRIPE_SK.

  • New Features

    • Next.js route with OPTIONS and POST; dynamic and no-cache.
    • Validates JSON body (successUrl URL only) and auth; accountId comes from auth, not the body.
    • Creates a subscription Checkout session with a fixed price and 30‑day trial; returns { id, url }.
    • Adds unit tests for the handler, validation, error mapping, and session creation.
  • Refactors

    • Added lib/stripe/client and STRIPE_SK env; throws if missing; updated .env.example.
    • Hardened errors: mask 5xx as "Internal server error" and return 500 for Stripe failures.
    • Renamed mapToSubscriptionSessionErrorResponse to mapToSubscriptionSessionError; enforce LF line endings via Prettier and .gitattributes.

Summary by CodeRabbit

  • New Features
    • Launched Stripe subscription checkout flow with a 30-day trial and account linking.
    • Added a server endpoint to create subscription checkout sessions with strict request validation and standardized JSON error responses.
    • Enabled CORS preflight support for the subscription API to allow reliable cross-origin integration.