Skip to main content

POST /api/stripe/create-checkout

Create a Stripe Checkout session for one-time payments or subscriptions. This endpoint is triggered by the ButtonCheckout component.

Request

string
required
Stripe Price ID for the product or subscription plan.
string
required
URL to redirect to after successful payment. Must be a valid URI.
string
required
URL to redirect to if user cancels the checkout. Must be a valid URI.
string
required
Checkout mode. Either payment for one-time payments or subscription for recurring subscriptions.

Response

string
The Stripe Checkout session URL to redirect the user to.
string
Error message returned when request fails.

Code Examples

Request Validation

packages/landing/app/api/stripe/create-checkout/route.ts

Error Handling

error
Validation ErrorReturned when:
  • priceId is missing: "Price ID is required"
  • successUrl or cancelUrl is missing: "Success and cancel URLs are required"
  • mode is missing: "Mode is required (either 'payment' for one-time payments or 'subscription' for recurring subscription)"
error
Internal Server ErrorReturned when Stripe API call fails or unexpected server error occurs.

Success Response

Status Code: 200 OK

POST /api/stripe/create-portal

Create a Stripe Customer Portal session for managing billing and subscriptions. This endpoint is triggered by the ButtonAccount component and requires an authenticated user.

Authentication

This endpoint requires a valid Supabase user session. Users must be signed in with a session cookie.

Request

string
required
URL to return to after the user completes their session in the billing portal. Must be a valid URI.

Response

string
The Stripe Customer Portal URL to redirect the user to.
string
Error message returned when request fails.

Code Examples

Request Validation

packages/landing/app/api/stripe/create-portal/route.ts

Error Handling

error
Validation ErrorReturned when:
  • returnUrl is missing: "Return URL is required"
  • User has no Stripe customer account: "You don't have a billing account yet. Make a purchase first."
error
UnauthorizedReturned when user is not authenticated.
error
Internal Server ErrorReturned when Stripe API call fails or unexpected server error occurs.

Success Response

Status Code: 200 OK

Implementation Notes

  • The endpoint includes a TODO for looking up the Stripe customer ID from the database
  • Currently uses a placeholder customerId that is always null
  • Users must make a purchase first to create a Stripe customer account before accessing the portal
  • All authentication is handled via Supabase session cookies