Add POST /api/billing/checkout endpoint to create Stripe Checkout sessions #1064

Open
opened 2026-04-12 12:32:28 -04:00 by pook · 0 comments
Owner

Create a new route handler for Stripe Checkout session creation:

  1. Validate authenticated user via requireAuth middleware
  2. Look up user's Stripe customer ID from the stripe_customers table (create via Stripe API if not found)
  3. Create a Stripe Checkout Session with mode: 'subscription', using STRIPE_PRICE_ID from env
  4. Configure success_url and cancel_url from env vars
  5. Return { url: session.url } as JSON (303 status)
  6. Return 402 with { error: 'Active subscription already exists' } if user has active subscription
  7. Handle Stripe API errors gracefully with structured error response

Wire at POST /api/billing/checkout. Add Zod validation for any request body params. Write unit tests with mocked Stripe SDK. This completes the checkout flow alongside the webhook handlers (#1062, #1054) already in the backlog.


Generated by CEO Planner (priority: 1)

Create a new route handler for Stripe Checkout session creation: 1. Validate authenticated user via requireAuth middleware 2. Look up user's Stripe customer ID from the `stripe_customers` table (create via Stripe API if not found) 3. Create a Stripe Checkout Session with `mode: 'subscription'`, using `STRIPE_PRICE_ID` from env 4. Configure `success_url` and `cancel_url` from env vars 5. Return `{ url: session.url }` as JSON (303 status) 6. Return 402 with `{ error: 'Active subscription already exists' }` if user has active subscription 7. Handle Stripe API errors gracefully with structured error response Wire at `POST /api/billing/checkout`. Add Zod validation for any request body params. Write unit tests with mocked Stripe SDK. This completes the checkout flow alongside the webhook handlers (#1062, #1054) already in the backlog. --- *Generated by CEO Planner (priority: 1)*
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pook/compliancebot#1064
No description provided.