TrackMe API Docs
Flow guides

Cart & Checkout

Build a single-truck cart, place a cash-on-pickup order, and track it through the fulfilment state machine.

This guide is for Flutter mobile engineers building the customer ordering flow. It covers the server-side cart, the single POST /api/v1/orders checkout, and the fulfilment state machine the truck owner drives (because owner transitions are what update the customer's order-tracking screen).

All endpoints below require the Bearer token guard: send Authorization: Bearer <oat_...> on every call. Cart and customer-order endpoints are scoped purely by the caller's user id and order ownership — you never send a truckId on cart calls; the truck is derived from the items you add. Send Accept-Language: ar for Arabic copy.

A placed order's status is new, not pending. The wire value, the model enum, the state machine, and the order-placed notification all use new. Filtering ?status=pending returns nothing. Branch and filter on new.

There is no draft, no confirm step, and no online payment. POST /api/v1/orders is a single atomic action: it snapshots the cart into a live order in state new, mints the order number, deletes the cart, and notifies the owner — all in one transaction. The order is live the instant you get 201. Payment is cash, in person (paymentMethod = "in_person") — do not expect a two-phase create-then-pay flow or a payment webhook in this domain. Online card payment exists only for owner Subscriptions, never for customer orders.

The flow at a glance

Step 1 — Add the first item (cart is created lazily)

POST /api/v1/cart/items. The server creates the cart on the first add and pins it to that item's truckId and currencyCode. The unit price (item + selected additions) and name are snapshotted at this moment.

Step 2 — Keep building the cart

More POST /api/v1/cart/items (same item + same additions bumps the existing line's quantity), PATCH /api/v1/cart/items/:itemId to set a quantity absolutely, DELETE /api/v1/cart/items/:itemId to drop a line. All items must be from the same truck.

Step 3 — (Optional) Render the cart

GET /api/v1/cart returns { cart } (or { cart: null } if the user never started one). totalMinor equals subtotalMinor — there is no tax or fee in MVP.

Step 4 — Checkout

POST /api/v1/orders. The server re-validates the truck (active + open) and every line (item/addition still live), then atomically snapshots the order, mints TM-YYYYMMDD-XXXXXX, sets status = "new" + paymentMethod = "in_person", writes the first status event, deletes the cart, and pushes FCM data.type = "order_new" to the owner and active truck staff. Returns 201 with a live order.

Step 5 — Track the order as the owner works it forward

The owner drives PATCH /api/v1/owner/orders/:id/status: new → accepted → preparing → ready_for_pickup → completed. Every successful transition pushes FCM data.type = "order_status" to the customer, including the new status and optional eta, and broadcasts order.status, so your tracking screen updates live. Poll GET /api/v1/orders/:id or subscribe to the realtime channel (Chat & Realtime).

Step 6 — Pay on pickup, then (optionally) review

The customer pays cash in person; the owner marks the order completed. After completion the customer may POST /api/v1/orders/:id/review.

Per-step detail

Add an item

:menuItemId is 5–30 chars; quantity is 1–99; additionIds is optional (max 25); notes is optional (≤500). Adding the same menuItemId with the same addition set bumps the existing line instead of creating a duplicate.

POST /api/v1/cart/items
Authorization: Bearer oat_xxx
Content-Type: application/json

{
  "menuItemId": "mi_01H9xKpC",
  "quantity": 2,
  "additionIds": ["adn_extracheese"],
  "notes": "no onions"
}
{
  "data": {
    "cart": {
      "id": "crt_01H9...",
      "truckId": "trk_01H9...",
      "currencyCode": "SAR",
      "subtotalMinor": 3600,
      "totalMinor": 3600,
      "items": [
        {
          "id": "cli_01H9...",
          "menuItemId": "mi_01H9xKpC",
          "nameSnapshot": "Double Cheeseburger",
          "unitPriceMinor": 1800,
          "quantity": 2,
          "lineTotalMinor": 3600,
          "selectedAdditions": [
            { "id": "adn_extracheese", "name": "Extra cheese", "priceMinor": 300 }
          ],
          "notes": "no onions"
        }
      ]
    }
  },
  "meta": { "requestId": "req_01H9..." }
}

Failure modes on add:

ConditionResponse
Menu item missing / soft-deleted404 NOT_FOUND
Menu item is unavailable (isAvailable = false)409 CONFLICT
An additionId is unavailable, does not belong to the item, or does not exist404 NOT_FOUND
Item is from a different truck than the current cart409 CONFLICT (see below)

The cross-truck conflict carries the data you need to prompt the user:

{
  "error": {
    "code": "CONFLICT",
    "message": "...",
    "currentTruckId": "trk_aaa",
    "attemptedTruckId": "trk_bbb",
    "requiresClear": true
  },
  "meta": { "requestId": "req_01H9..." }
}

When requiresClear: true, call DELETE /api/v1/cart before adding the new truck's item.

Change a line quantity

:itemId is the cart-line id (cli_...), not the menuItemId. quantity is set absolutely (not added).

PATCH /api/v1/cart/items/cli_01H9...
Authorization: Bearer oat_xxx
Content-Type: application/json

{ "quantity": 1 }

Returns 200 with the recomputed cart. 404 if that line is not in the caller's cart.

Remove a line / clear the cart

DELETE /api/v1/cart/items/:itemId removes one line and returns 200 { data: { cart } }. Removing the last line leaves an empty cart row that still holds the single-truck pin — it is not auto-deleted.

DELETE /api/v1/cart deletes the whole cart row, releasing the pin so the user can start fresh at another truck. Note the different envelope — no cart object:

{ "data": { "success": true }, "meta": { "requestId": "req_01H9..." } }

Place the order

customerNotes (≤1000) and scheduledFor (UTC ISO) are both optional.

POST /api/v1/orders
Authorization: Bearer oat_xxx
Content-Type: application/json

{ "customerNotes": "Call when ready", "scheduledFor": "2026-06-21T18:30:00Z" }
{
  "data": {
    "order": {
      "id": "ord_01H9...",
      "orderNumber": "TM-20260621-A1B2C3",
      "status": "new",
      "paymentMethod": "in_person",
      "subtotalMinor": 3600,
      "totalMinor": 3600,
      "currencyCode": "SAR",
      "truck": { "id": "trk_01H9...", "name": "Burger Truck", "langActual": "en" },
      "items": [
        {
          "menuItemId": "mi_01H9xKpC",
          "name": "Double Cheeseburger",
          "quantity": 2,
          "lineTotalMinor": 3600
        }
      ],
      "statusHistory": [
        { "status": "new", "actorType": "customer", "at": "2026-06-21T17:00:00.000Z" }
      ],
      "review": null
    }
  },
  "meta": { "requestId": "req_01H9..." }
}

Checkout can fail late with a 409, even if the cart was valid when you built it. POST /orders re-checks at submit time:

  • Empty cart (no cart, or zero items) → 409 CONFLICT "Cart is empty."
  • Truck deleted → 404 NOT_FOUND
  • truck.status != active → 409 CONFLICT "not currently accepting orders"
  • truck.isOpen is false → 409 CONFLICT "currently closed"
  • Any line item or addition now soft-deleted / unavailable → 409 (E_RESOURCE_DELETED, CONFLICT-family)

Handle all of these on the checkout button, not just on add.

List and read orders

GET /api/v1/orders — filters ?status=, ?truckId=, ?limit= (default 50, max 100), newest-first. Each item embeds the localized truck, items[], statusHistory[], and review. Remember: filter on status=new, not pending.

GET /api/v1/orders/:id — 403 if the order is not the caller's, 404 if not found. Returns the full order with statusHistory (one row per transition: status, actorType, actorId, at).

Cancel an order

reason is required (2–500 chars). Allowed from any non-terminal state.

POST /api/v1/orders/ord_01H9.../cancel
Authorization: Bearer oat_xxx
Content-Type: application/json

{ "reason": "Changed my mind" }
  • 422 VALIDATION_ERROR if reason is missing.
  • 403 if not the caller's order; 404 if not found.
  • 409 CONFLICT "Order cannot be cancelled in its current state." if the order is terminal (completed / cancelled / rejected).

Cancelling sets status = cancelled, records the reason, and notifies both the customer and the owner.

Review after completion

orderId in the body must equal the URL :id. rating is 1–5; comment and fileIds optional.

POST /api/v1/orders/ord_01H9.../review
Authorization: Bearer oat_xxx
Content-Type: application/json

{ "orderId": "ord_01H9...", "rating": 5, "comment": "Great burger" }

403 if not the caller's order; 409 if orderId mismatches the URL or if the review rules reject (e.g. order not eligible, or already reviewed). Returns 201 with the created review.

Order lifecycle

Owner transitions go through PATCH /api/v1/owner/orders/:id/status (Bearer + active owner membership, must own the truck). Body: { status, estimatedReadyAt?, reason? }. estimatedReadyAt is only applied when status = accepted; sending it on other transitions is ignored.

StateMeaningHow you got hereWhat's allowed next
newOrder placed, awaiting ownerPOST /orders (entry state)owner → accepted / rejected; customer → cancelled
acceptedOwner accepted, may have an ETAowner accepts a new orderowner → preparing; customer/owner → cancelled
preparingFood is being madeowner moves accepted forwardowner → ready_for_pickup; customer/owner → cancelled
ready_for_pickupReady; customer pays cash on pickupowner moves preparing forward (stamps readyAt)owner → completed; customer → cancelled (owner cannot cancel here)
completedPicked up & paidowner completes a ready_for_pickup orderterminal — nothing; customer may review
rejectedOwner declined the orderowner rejects a new orderterminal
cancelledCancelled by customer or ownercustomer/owner cancel before terminalterminal

Transitions

  • (none) → new — customer, via POST /api/v1/orders. Initial event, actorType = customer.
  • new → accepted — owner, { status: "accepted", estimatedReadyAt? }.
  • new → rejected — owner, { status: "rejected" }. Terminal.
  • accepted → preparing — owner, { status: "preparing" }.
  • preparing → ready_for_pickup — owner, { status: "ready_for_pickup" }. Stamps readyAt.
  • ready_for_pickup → completed — owner, { status: "completed" }. Terminal.
  • new | accepted | preparing | ready_for_pickup → cancelled — customer, via POST /api/v1/orders/:id/cancel { reason }. Allowed from any non-terminal state. Terminal.
  • new | accepted | preparing → cancelled — owner, via PATCH .../status { status: "cancelled", reason? }. The owner is blocked from cancelling once an order reaches ready_for_pickup (409 "Mark it complete instead."). Terminal.

The state machine is strictly forward-only. Any illegal edge, or any transition out of a terminal state, returns 409 E_INVALID_STATE_TRANSITION. There is no "reopen".

Implementation Notes

Integration issueCorrect handling
Filtering ?status=pending and getting an empty list.The entry state is new. Filter and branch on new.
Expecting a draft / confirm / pay step after creating an order.POST /orders returns a live order in one atomic call and clears the cart. There is no second step.
Building an online-payment screen for checkout.Payment is cash, paymentMethod = "in_person". Online card payments belong to paid owner services, not customer checkout.
Adding an item from a second truck and getting 409.The cart is single-truck (pinned on first add). Call DELETE /api/v1/cart to switch trucks (look for requiresClear: true).
Expecting checkout to re-price after the owner changes a price.Prices are snapshotted at add-time (unitPriceSnapshotMinor). Checkout only re-validates availability; it never re-prices. The order inherits the cart snapshot.
Treating the cart as still valid at checkout because adds succeeded.Re-check failures (409 truck closed/inactive/deleted, E_RESOURCE_DELETED, empty cart) on the checkout button.
Passing a menuItemId to PATCH/DELETE /cart/items/:itemId.Use the cart-line id (cli_...) from the cart's items[].id. The menuItemId yields 404.
Treating GET /cart returning { cart: null } as an error.That's a normal 200 for "no cart yet". Render an empty state.
Assuming removing the last line clears the cart.It leaves an empty cart row that still holds the truck pin. Only DELETE /cart removes it and releases the pin.
Parsing DELETE /cart like the other cart endpoints.It returns { data: { success: true } } with no cart object — a different envelope.
Calling cancel without a reason.reason (2–500 chars) is required; missing it is 422. A terminal order returns 409.
Sending estimatedReadyAt on a non-accept transition (owner).It is only applied when status = accepted; otherwise it is silently ignored.
  • Order Lifecycle — the owner-side fulfilment surface that drives every post-checkout transition.
  • Chat & Realtime — subscribe to order.status so the tracking screen updates live.
  • Subscriptions — the only surface with online card payment (owner-side, not customer orders).
  • API reference — full endpoint and schema reference.

On this page