Headless Checkout & Orders

Submit shipping details and finalize customer transactions. The server validates pricing, checks stock thresholds, updates stock counts, and generates an order record.


1. Placing Storefront Orders

  • Method: POST
  • Route: /api/v1/stores/:storeId/checkout
  • Headers (One of):
    • Authorization: Bearer <accessToken> (Customer Account Checkout)
    • X-Guest-Token: <guestToken> (Guest checkout)
curl -X POST https://api.bazaara.store/api/v1/stores/YOUR_STORE_ID/checkout \
  -H "Content-Type: application/json" \
  -H "X-Guest-Token: GUEST_TOKEN_UUID" \
  -d '{
    "shippingAddress": {
      "name": "Jane Doe",
      "line1": "456 Silicon Valley Blvd",
      "line2": "Suite 101",
      "city": "San Jose",
      "state": "CA",
      "postalCode": "95112",
      "country": "United States",
      "phone": "+14085550183"
    },
    "paymentMethod": "stripe",
    "couponCode": "WELCOME10",
    "notes": "Please leave at the front desk."
  }'
interface Address {
  name: string;
  line1: string;
  city: string;
  state: string;
  postalCode: string;
  country: string;
  phone: string;
}

interface CheckoutPayload {
  shippingAddress: Address;
  paymentMethod: string;
  couponCode?: string;
  notes?: string;
}

async function placeOrder(storeId: string, guestToken: string, payload: CheckoutPayload) {
  const response = await fetch(`https://api.bazaara.store/api/v1/stores/${storeId}/checkout`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-Guest-Token': guestToken
    },
    body: JSON.stringify(payload)
  });
  return response.json();
}
import requests

def place_order(store_id, guest_token, address, payment_method):
    url = f"https://api.bazaara.store/api/v1/stores/{store_id}/checkout"
    headers = { "X-Guest-Token": guest_token }
    payload = {
        "shippingAddress": address,
        "paymentMethod": payment_method,
        "couponCode": None
    }
    response = requests.post(url, json=payload, headers=headers)
    return response.json()
async fn checkout(store_id: &str, guest_token: &str, address: serde_json::Value) -> Result<serde_json::Value, reqwest::Error> {
    let client = reqwest::Client::new();
    let res = client.post(&format!("https://api.bazaara.store/api/v1/stores/{}/checkout", store_id))
        .header("X-Guest-Token", guest_token)
        .json(&serde_json::json!({
            "shippingAddress": address,
            "paymentMethod": "cod",
            "notes": ""
        }))
        .send()
        .await?
        .json::<serde_json::Value>()
        .await?;
    Ok(res)
}

2. Fulfillment Calculations

  • Shipping Fees: Shipping fee is dynamically calculated on the server (Free for subtotals exceeding $150.00, otherwise defaults to a flat fee of $15.00).
  • Sales Tax: Set at a flat 10% of the subtotal amount.
  • Stock Updates: Placing an order automatically deducts quantities from active product inventories where trackInventory is enabled.
  • Auto-Clear: Once checkout completes successfully, the shopper's active cart is automatically emptied.