Skip to content

checkout ​

Turns a signed-in customer's cart into an order. Verification is required only on a store that turns on auth.customer_verification_required. A shopper who is not signed in checks out through guest.checkout() when the store has checkout.guest_enabled on.

Checkout never takes money. Even a card order is placed unpaid; the payment session starts afterwards with orders.pay.

See Checkout for the full flow, retry rules and failure handling.

ts
mawjod.checkout.place(input, options?)

checkout.place() ​

ts
place(input: CheckoutInput, options?: CheckoutOptions): Promise<CheckoutResult>

POST /api/v1/customer/checkout.

ts
const { order, idempotencyKey, operationId } = await mawjod.checkout.place({
  fulfillment_method: 'delivery',
  payment_method: 'cod',
  address_id: address.id,
  expected_items_subtotal_minor: quote.discounted_subtotal.minor,
})

CheckoutInput ​

ts
interface CheckoutInput {
  fulfillment_method: 'delivery' | 'pickup'
  payment_method: string
  address_id?: string | null
  pickup_location_id?: string | null
  guest_token?: string | null
  expected_items_subtotal_minor?: number | null
  operation_id?: string
}
FieldNotes
fulfillment_methoddelivery or pickup
payment_methodNot an enum. See below.
address_idRequired for delivery
pickup_location_idRequired for pickup
guest_token64 characters. Merges an unmerged guest cart inline.
expected_items_subtotal_minorOptimistic-concurrency guard. A mismatch is a 409.
operation_idUUIDv7 identifying this attempt; generated when omitted

payment_method is not an enum ​

cod is always offered. paymob only exists when the deployment has the gateway configured. A future method needs no SDK release, which is why the type is PaymentMethod = 'cod' | 'paymob' | (string & {}).

Read the offered set at runtime, from store.settings() → checkout.allowed_payment_methods, or from a fulfillment quote's allowed_payment_methods, which is narrowed to the chosen zone or pickup point. Prefer the quote when you have one.

Choosing paymob places the order unpaid. Read order.payment.requires_action afterwards; do not infer it from the method.

CheckoutOptions ​

ts
interface CheckoutOptions {
  idempotencyKey?: string
}

Sent as the Idempotency-Key header. 16 to 128 printable ASCII characters; a UUIDv7 is a fine choice and is what the client generates when you omit it.

Never send idempotency_key in the body

Scribe's generated docs show a body field by that name. It is not an input. The server overwrites it from the header before validating, and the client deletes it from the body if it finds one. The header is the only authority.

CheckoutResult ​

ts
interface CheckoutResult {
  order: Order
  idempotencyKey: string
  operationId: string
}

Both identifiers come back so a retry can reuse them. Keep them for as long as the attempt might be retried.

The idempotency pair ​

Two values travel together and must both be reused for a replay:

ValueWhereWhat
Idempotency-Keyheader16 to 128 printable ASCII characters
operation_idbodyUUIDv7; also the stock-reservation identity

The server hashes the key against exactly these fields:

operation_id
fulfillment_method
payment_method
address_id
pickup_location_id
expected_items_subtotal_minor

Same key, same values → replay of the original response's content (the stored body can come back with its keys in another order, so compare fields, not bytes). Same key, any one of those changed → conflict, not a replay.

Retry semantics ​

Transport failure: the request never got an answer, or the answer never got back. The order may or may not exist. Retry with the same input and the same pair; the server replays if it already placed the order.

Stale-cart failure: cart_price_changed, cart_not_purchasable or insufficient_stock. Do not retry. Refetch the cart, show what changed, ask the shopper to confirm, then call place() again with a fresh pair. Reusing the key with a corrected expected_items_subtotal_minor is answered as a conflict, not a replay, and silently retrying would charge someone a price they never agreed to.

Failure families ​

CodeStatusMeaningResponse
cart_price_changed409Prices movedRefetch, show, fresh place()
cart_not_purchasable409A line can no longer be soldRefetch, show, fresh place()
insufficient_stock409Not enough stock for one or more linesRefetch, show, fresh place()
cart_empty422Nothing to orderSend them to the catalogue
cart_not_found422No cart for this callerSend them to the catalogue
payment_method_unavailable422Method not offered hereRe-read the allowed set
order_below_minimum422Items subtotal under the shop's minimumSay the minimum, back to the cart
order_above_maximum422Items subtotal over the shop's maximumSay the maximum, back to the cart
outside_ordering_hours422The shop is closed at this hourAsk them to come back later
ordering_disabled422The owner has switched ordering offSay the shop is not taking orders
customer_not_verified403Identity not verified, where the store requires itVerification screen, not the cart

409 means refetch. 422 means rewrite the request. 403 means route to verification (or, from guest.checkout(), to sign-in).

The 403 only exists on a store that has turned on auth.customer_verification_required, which is off by default. Guest checkout adds a twelfth code, 403 guest_checkout_disabled; see guest. See store.settings() → Verification.

ts
import { isCheckoutError, isStaleCartError } from '@mawjod/api'

isStaleCartError(error)  // the three 409s
isCheckoutError(error)   // all twelve, guest_checkout_disabled included

Do not parse error.detail. Compute the diff from the refetched cart.

Short stock ​

insufficient_stock lists every short variant in variant_ids, not only the first:

ts
error.problem.variant_ids // ['01916f7a-…', '01916f7a-…']

They are the lines the cart read already marks in_stock: false, so after the refetch you can highlight each of them at once instead of discovering them one failed attempt at a time.

Ordering rules ​

Four 422s come from the shop's own rules rather than from the cart moving. Refetching does not clear them, so they are not stale-cart failures and isStaleCartError is false for each.

order_below_minimum and order_above_maximum compare the items subtotal against ordering.minimum_minor and ordering.maximum_minor, both inclusive and both in minor units. Name the bound: "The minimum order is EGP 200.00, add EGP 35.00 more to continue." Read it from store.settings() and format it with formatMoney. The problem's detail also states it in minor units, but detail is prose and is reworded without notice.

outside_ordering_hours means ordering is on and the shop is closed at this hour. Tell the shopper to come back later and keep the cart as it is. ordering_disabled is different: the owner has switched ordering off, with no hour when it comes back, so say the shop is not taking orders right now rather than promising a time.

ts
switch (error.code) {
  case 'order_below_minimum':    // "The minimum order is EGP 200.00."
  case 'order_above_maximum':    // "Orders here go up to EGP 5,000.00."
  case 'outside_ordering_hours': // "We're closed right now. Come back during opening hours."
  case 'ordering_disabled':      // "This shop isn't taking orders at the moment."
}

401 unauthenticated, 422 validation_failed, 429 rate_limited and 503 store_unavailable apply as everywhere else.

The returned order ​

place() runs the payload integrity guard: an order with lines: [] throws PayloadIntegrityError rather than resolving, because an order is created from at least one cart line and an empty one is a lost payload arriving as a valid 201. See Errors → the integrity guard.

The Order shape is documented on orders. Its fulfillment.eta and the quote snapshot's eta are null when the zone that quoted the order promises no delivery time, so the confirmation screen shows a delivery time only when there is one.

In Nuxt ​

ts
const { place, retry, order, attempt, staleCart, isStale, pending, reset } = useCheckout()

useCheckout() mints the pair before the call and keeps it on attempt, because an attempt that fails is exactly the one that needs retrying under the same key. retry() replays the stored input under the stored pair, which is the transport-failure path only. See Composables → useCheckout.