Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/aluxey/E-Commerce/llms.txt

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

Endpoint

POST /api/checkout
Creates a new order and initiates a Stripe payment intent for the items in the user’s cart. This endpoint validates cart items, checks stock availability, and returns a Stripe client secret for completing the payment.

Authentication

This endpoint requires authentication. Include a valid Supabase access token in the Authorization header.
Authorization: Bearer YOUR_ACCESS_TOKEN

Request Body

cartItems
array
required
Array of cart items to purchase. Each item must include a variant ID.
currency
string
default:"eur"
Payment currency. Defaults to eur (Euro).

Response

clientSecret
string
Stripe payment intent client secret. Use this with Stripe.js to complete the payment on the frontend.
orderId
string
The created order ID. Use this to track the order status.

Error Codes

Status CodeError MessageDescription
401UnauthorizedMissing or invalid authentication token
400Cart is emptyThe cartItems array is empty or invalid
400Chaque article doit inclure un variant_id.One or more items missing variant_id
400Variant {id} introuvableSpecified variant not found in database
400Variant et produit incompatiblesVariant doesn’t belong to the specified item
400Stock insuffisant pour un des variantsInsufficient stock for requested quantity
400Invalid amountCalculated total is zero or negative
500Checkout failedInternal server error during checkout

Workflow

  1. Authentication: Validates user token
  2. Normalization: Normalizes cart item format
  3. Validation: Ensures all items have variants and cart is not empty
  4. Pricing: Fetches current prices from database
  5. Stock Check: Verifies sufficient stock for each variant
  6. Order Creation: Creates order record with pending status
  7. Order Items: Inserts individual order items
  8. Payment Intent: Creates Stripe payment intent
  9. Update Order: Stores payment intent ID on order
  10. Response: Returns client secret for frontend payment completion

Example Request

curl -X POST https://your-api-domain.com/api/checkout \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -d '{
    "currency": "eur",
    "cartItems": [
      {
        "item_id": 1,
        "variant_id": 5,
        "quantity": 2,
        "customization": {}
      },
      {
        "item_id": 3,
        "variant_id": 12,
        "quantity": 1,
        "customization": {
          "note": "Gift wrap please"
        }
      }
    ]
  }'

Example Response

{
  "clientSecret": "pi_3AbcDefGhiJkLmNo_secret_xYzAbCdEfGhIjKlMnOpQrStUvWxYz",
  "orderId": "550e8400-e29b-41d4-a716-446655440000"
}

Using the Client Secret

After receiving the clientSecret, use it with Stripe.js to complete the payment:
import { loadStripe } from '@stripe/stripe-js';

const stripe = await loadStripe('your_publishable_key');

const { error } = await stripe.confirmPayment({
  clientSecret: data.clientSecret,
  confirmParams: {
    return_url: 'https://yoursite.com/order-complete',
  },
});

Order Status Updates

Once the payment is processed, Stripe will send webhook events to update the order status:
  • payment_intent.succeeded → Order status updated to paid
  • payment_intent.payment_failed → Order status updated to failed
  • payment_intent.canceled → Order status updated to canceled
See the Webhooks documentation for more details.

Notes

  • All prices are calculated server-side from the database to prevent tampering
  • Stock levels are validated before order creation
  • Orders are created with pending status and updated via webhooks
  • The payment intent ID is stored on the order for tracking
  • Failed order creation will not create a Stripe payment intent

Build docs developers (and LLMs) love