Migrate stripe subscription checkout sessions
Merged
AH
6mo ago+767+767+012345678901234567890123456789-1-1-0123456789
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
OPTIONSandPOST; dynamic and no-cache. - Validates JSON body (
successUrlURL only) and auth;accountIdcomes 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.
- Next.js route with
-
Refactors
- Added
lib/stripe/clientandSTRIPE_SKenv; throws if missing; updated.env.example. - Hardened errors: mask 5xx as "Internal server error" and return 500 for Stripe failures.
- Renamed
mapToSubscriptionSessionErrorResponsetomapToSubscriptionSessionError; enforce LF line endings via Prettier and.gitattributes.
- Added
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.