Skip to content

Place an order (checkout)​

POST
/checkout

Creates an order from supplied line items and addresses for the resolved tenant. Guest-friendly: a customer token is decoded if present so the order links to that customer, otherwise it is a guest COD order. The order's customer is always the authenticated customer, never a body field. Supports an optional Idempotency-Key header that replays an existing order (returns 200) instead of creating a duplicate. Validates stock with a race-safe decrement and emits an order.created analytics event.

Every line must be a product ACTIVELY listed on this marketplace (the rule the storefront applies before showing it): a product whose listing is paused, rejected or retired, or whose vendor is suspended or terminated, is refused with 422 Product <id> not available — no longer sold on this marketplace and no order is created, even from a saved cart or a direct call.

Shipping is computed server-side per vendor (each vendor's flat fee, waived above their free-shipping threshold); a client-supplied shippingAmount is ignored. paymentMethod is cod (default) or clictopay (case-insensitive). Use POST /shipping-quote to preview the shipping total before checkout.

When on, the order is placed as usual (stock reserved, status: pending, paymentStatus: pending), registered at ClicToPay (amount in millimes, orderNumber = our orderId UUID without its hyphens, 32 hex characters — the gateway caps that field at 32) and returned with payment: { provider: clictopay, status: pending, formUrl } — send the buyer to formUrl. Card orders are charged in TND only (another currency → 422 PAYMENT_CURRENCY_UNSUPPORTED) and must have something to pay (a zero total → 422 PAYMENT_AMOUNT_INVALID). Vendor fulfilment tasks, vendor e-mails and the customer confirmation wait for the payment to be proven (GET /payments/clictopay/status). A replay with the same Idempotency-Key reuses the registration (never registers twice); 409 PAYMENT_REGISTRATION_IN_PROGRESS = a concurrent request is registering, retry; 409 PAYMENT_NOT_RESUMABLE = the gateway holds the order but its payment page was lost (the gateway answer never reached us) — place a new order; 502 PAYMENT_GATEWAY_UNAVAILABLE = the order is placed but the gateway did not answer — retry with the same Idempotency-Key.

Multi-vendor packs: lines carrying a bundleId must form that pack exactly — every pack item covered once (an item with a variant by that variant, an "any variant" item by any variant of its product), no extra line carrying the id, quantities = pack quantities × the same whole number k. The pack total (price × k) is split across its lines in proportion to their catalogue totals (millime-rounded, remainder on the last line); each line keeps its vendor, so commission, the vendor's free-shipping threshold and payouts use that share. The line discountAmount records catalogue − share; the order discountAmount stays 0 (the subtotal is already the sum of the shares). An unknown / inactive / out-of-dates pack, a currency mismatch or lines that do not form the pack → 422 Bundle … not available — <reason>. POST /shipping-quote applies the same pack pricing.

Auth: Bearer JWT optional (guest-friendly).

Authorizations​

bearerAuth

Jeton client obtenu par POST /auth/login (ou /auth/register), renouvelé par POST /auth/refresh.

Type
HTTP (bearer)
or

Parameters​

Header Parameters

Idempotency-Key

Replays an already-created order for the same account/key instead of placing a duplicate

Type
string

Request Body​

application/json
JSON
{
  
"items": [
  
],
  
"shippingAddress": {
  
  
"firstName": "string",
  
  
"lastName": "string",
  
  
"address1": "string",
  
  
"address2": "string",
  
  
"city": "string",
  
  
"state": "string",
  
  
"postcode": "string",
  
  
"countryCode": "TN",
  
  
"email": "user@example.com",
  
  
"phone": "string"
  
},
  
"billingAddress": {
  
  
"firstName": "string",
  
  
"lastName": "string",
  
  
"address1": "string",
  
  
"address2": "string",
  
  
"city": "string",
  
  
"state": "string",
  
  
"postcode": "string",
  
  
"countryCode": "TN",
  
  
"email": "user@example.com",
  
  
"phone": "string"
  
},
  
"paymentMethod": "cod",
  
"customerNote": "string",
  
"customerId": "string",
  
"shippingAmount": 0,
  
"currency": "TND",
  
"couponCode": "string",
  
"loyaltyPoints": 0
}

Responses​

Idempotent replay — the order already existed for this Idempotency-Key

application/json
JSON
{
  
"ok": true,
  
"data": {
  
  
"orderId": "123e4567-e89b-12d3-a456-426614174000",
  
  
"orderNumber": "string",
  
  
"status": "string",
  
  
"currency": "string",
  
  
"subtotal": 0,
  
  
"discountAmount": 0,
  
  
"couponCode": "string",
  
  
"loyaltyPoints": 0,
  
  
"loyaltyDiscount": 0,
  
  
"shippingAmount": 0,
  
  
"total": 0,
  
  
"paymentMethod": "string",
  
  
"paymentStatus": "string",
  
  
"placedAt": "2024-01-01T00:00:00Z",
  
  
"payment": {
  
  
  
"provider": "clictopay",
  
  
  
"status": "pending",
  
  
  
"formUrl": "https://example.com"
  
  
},
  
  
"items": [
  
  
  
{
  
  
  
  
"itemId": "string",
  
  
  
  
"productId": "string",
  
  
  
  
"title": "string",
  
  
  
  
"quantity": 0,
  
  
  
  
"unitPrice": 0,
  
  
  
  
"lineTotal": 0,
  
  
  
  
"discountAmount": 0,
  
  
  
  
"vendorId": "string",
  
  
  
  
"vendorName": "string",
  
  
  
  
"vendorPhone": "string",
  
  
  
  
"vendorWhatsapp": "string"
  
  
  
}
  
  
],
  
  
"vendors": [
  
  
  
{
  
  
  
  
"vendorId": "string",
  
  
  
  
"name": "string",
  
  
  
  
"phone": "string",
  
  
  
  
"email": "string",
  
  
  
  
"whatsapp": "string",
  
  
  
  
"whatsappSource": "vendor",
  
  
  
  
"waLink": "string",
  
  
  
  
"store": {
  
  
  
  
  
"storeId": "string",
  
  
  
  
  
"name": "string",
  
  
  
  
  
"address": "string",
  
  
  
  
  
"city": "string",
  
  
  
  
  
"phone": "string"
  
  
  
  
},
  
  
  
  
"address": "string"
  
  
  
}
  
  
]
  
}
}

Playground​

Authorization
Headers
Body

Samples​

Powered by VitePress OpenAPI

Tarifs : contactez-nous — contact@marketkit.ai