Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Jason-AML/MonzaSport-Nextjs/llms.txt

Use this file to discover all available pages before exploring further.

The POST /api/checkout route handles the first step of the Monza Motors purchase flow. It verifies that the requesting user is authenticated via a Supabase server-side session, fetches the target vehicle’s details from the vehiculos table using getCollectionById(), and then creates a Stripe Checkout session pre-configured with the vehicle’s name and price. The full Stripe session object — including the hosted checkout url — is returned to the client, which immediately redirects the user to complete payment on Stripe’s platform.

Endpoint

PropertyValue
MethodPOST
Path/api/checkout
AuthRequired — returns 401 if the user is not signed in
Content-Typeapplication/json

Request Body

id
string
required
The vehicle UUID from the vehiculos Supabase table. Used to look up the vehicle’s name and price before creating the Stripe session.

Response

200 OK — Returns the full Stripe Checkout session object. The two most important fields for the client are:
url
string
The Stripe-hosted checkout URL. Redirect the user to this address to complete payment. The URL is valid for 24 hours.
id
string
The Stripe session ID (prefixed cs_). Can be stored client-side for reconciliation or status polling.
401 Unauthorized
{ "error": "Unauthorized" }
Returned immediately when getUser() resolves to null — i.e., no valid Supabase session cookie is present. 500 Internal Server Error
{ "error": "Failed to create checkout session" }
Returned when any step after authentication fails — for example a Supabase read error or a Stripe API rejection.

Example Request

curl -X POST https://your-app.vercel.app/api/checkout \
  -H 'Content-Type: application/json' \
  -H 'Cookie: your-supabase-session-cookie' \
  -d '{"id": "vehicle-uuid-here"}'

Session Parameters

The Stripe Checkout session is created with the following configuration:
ParameterValueNotes
payment_method_types['card']Credit and debit cards only
mode'payment'One-time payment, not a subscription
currency'usd'All Monza Motors prices are denominated in US dollars
unit_amountvehicle.precio * 100Prices are stored in dollars; Stripe requires cents
product_data.namevehicle.nombre_vehiculoDisplayed on the Stripe-hosted checkout page
quantity1Fixed at one vehicle per session
metadata.vehicleIdvehicle.idAttached to the session for post-payment webhook handling
metadata.userIduser.idEnables order attribution after payment confirmation
success_url/successWhere Stripe redirects after successful payment
cancel_url/cancelWhere Stripe redirects if the user abandons checkout
The success_url and cancel_url are resolved against the app’s base URL: https://<VERCEL_URL> in production and NEXT_PUBLIC_BASE_URL in development.
This route uses the server-side Supabase client which reads the user session from the request cookie. The session cookie must be present for getUser() to return a valid user — this works automatically when the request originates from a browser fetch() call on the same domain. It will not work in server-to-server requests (e.g. direct curl calls or webhook triggers) unless the correct sb-* session cookies are explicitly supplied.

Build docs developers (and LLMs) love