Purchasing a vehicle on Monza Motors is handled entirely through Stripe’s hosted Checkout page. When an authenticated user clicks “Buy Now” on a vehicle detail page, the client sends a request to the Next.js API route atDocumentation 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.
POST /api/checkout, which creates a Stripe Checkout session and returns the session URL. The browser then redirects the user to Stripe’s secure, PCI-compliant payment page. After the transaction the user is returned to either /success (payment completed) or /cancel (payment abandoned).
Purchase Flow
User clicks Buy Now
On the
/collection/[carId] detail page, the user clicks the “Buy Now” button inside the sticky pricing card. This calls handleStripe(vehicle) with the current vehicle object.POST to /api/checkout
handleStripe sends a POST request to /api/checkout with the vehicle’s id in the JSON body:Auth check — 401 redirects to /error
The API route calls
getUser() first. If the user is not signed in, it returns HTTP 401. The client checks for this status code and calls router.push('/error') instead of proceeding to Stripe.Redirect to Stripe Checkout
For an authenticated request, the API route creates a Stripe session and returns it as JSON. The client reads
session.url and sets window.location.href to navigate the browser to Stripe’s hosted payment page.Client-side Trigger
ThehandleStripe function lives in src/app/collection/[carId]/Detail.jsx. It uses the native fetch API and the Next.js useRouter hook for navigation.
window.location.href is used for the final Stripe redirect (rather than router.push) because the destination is an external Stripe domain — Next.js client-side routing only handles same-origin navigation.
Stripe Session Configuration
The API route atsrc/app/api/checkout/route.js builds the Stripe session with the following parameters:
| Parameter | Value |
|---|---|
payment_method_types | ['card'] |
currency | usd |
mode | 'payment' (one-time charge) |
metadata.vehicleId | The vehicle’s UUID from the vehiculos table |
metadata.userId | The authenticated user’s Supabase UUID |
line_items[0].price_data.product_data.name | vehicle.nombre_vehiculo |
line_items[0].price_data.unit_amount | vehicle.precio * 100 |
line_items[0].quantity | 1 |
getCollectionById(id), which also benefits from React’s cache() deduplication if the same ID was already loaded during the render.
Redirect URLs
After the payment flow, Stripe redirects the user back to the application using the URLs configured on the session:- Success —
{baseUrl}/successwhen payment is completed. - Cancel —
{baseUrl}/cancelwhen the user abandons Stripe Checkout.
baseUrl is resolved at runtime from environment variables:
VERCEL_URL with the deployment’s canonical hostname. For local development, set NEXT_PUBLIC_BASE_URL=http://localhost:3000 in your .env.local file.
Vehicle prices in the
vehiculos table are stored as integers in USD (e.g., 250000 represents 250,000.00 — on the Stripe session.