{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/layout-link/json-schema/layout-link-order-schema.json",
  "title": "Order",
  "x-generated": "2026-11-15",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/layout-link-openapi.json#/components/schemas/Order",
  "type": "object",
  "properties": {
    "id": {
      "$ref": "#/$defs/OrderId"
    },
    "state": {
      "$ref": "#/$defs/OrderState"
    },
    "store": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "store_address": {
      "description": "The address of that store, when Layout knows it.",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "items": {
      "type": "integer",
      "minimum": -9007199254740991,
      "maximum": 9007199254740991
    },
    "total_minor": {
      "description": "Minor units. 2140 is $21.40.",
      "anyOf": [
        {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        {
          "type": "null"
        }
      ]
    },
    "currency": {
      "type": "string"
    },
    "created_at": {
      "type": "string"
    },
    "placed_at": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "ready_eta": {
      "description": "The pickup time as the store stated it, word for word, when the store states one. Layout reads it from the store's confirmation screen and its email, so it can arrive after `placed`, with an `order.updated` event. Null until then, and null for good when the store never states a time; the person then goes by the store's own confirmation. Show it as written; it is not a timestamp.",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "ready_at": {
      "description": "The same pickup time as an instant, ISO 8601, only when Layout could place `ready_eta` on the store's clock. Null when the store's words are not a time Layout can pin down. Show `ready_eta`; use this to schedule or sort.",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "refunded_minor": {
      "description": "Minor units refunded on this order so far, across every refund. 0 when none. `state` does not change when an order is refunded; `order.refunded` comes with each refund.",
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "failure_code": {
      "description": "A stable machine code, never prose. Read it only when `state` is `failed` or `unconfirmed`: an order still `placing` can carry one before it settles, so switch on `state` first. One of `LOGIN_REQUIRED`, `SITE_BLOCKED`, `RATE_LIMITED`, `ITEM_UNAVAILABLE`, `SITE_ERROR`, `STORE_CLOSED`, `PICKUP_TIME_EXPIRED`, `CHECKOUT_NOT_FOUND`, `ORDERING_PAGE_NOT_FOUND`, `CLOSED_NEXT_DAY`, `MARKETPLACE_ONLY`, `APP_ONLY_ORDERING`, `ACCOUNT_VERIFICATION_REQUIRED`, `CART_DRIFTED`, `CARD_DECLINED`, `CARD_REMOVED`, `PAYMENT_REJECTED`, `OUR_TIMEOUT`, `OUR_ERROR`, `UNCONFIRMED`, `UNKNOWN`, `USER_CANCELED`, `STAFF_STOPPED`, `SESSION_EXPIRED`, `SUPERSEDED_BY_CHANGE`, `CART_EXPIRED`. Treat any value you do not recognise as `UNKNOWN`.",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "simulated": {
      "description": "Present and true on a sandbox order that was simulated. Absent on every real order.",
      "type": "boolean",
      "const": true
    },
    "challenge": {
      "description": "Present while `state` is `placing` and the payment waits on the person approving it: tell them to open the link Layout texted them. Absent otherwise. `order.challenge` says the same as a webhook.",
      "type": "object",
      "properties": {
        "sms_sent": {
          "description": "True when Layout texted the person the approval link. False at the sandbox `test_place_challenge`, which texts nobody.",
          "type": "boolean"
        }
      },
      "required": [
        "sms_sent"
      ]
    },
    "fulfillment": {
      "$ref": "#/$defs/Fulfillment"
    },
    "lines": {
      "description": "What was ordered, as the cart was built. Layout's derived tax-and-fees line is not a line.",
      "type": "array",
      "items": {
        "$ref": "#/$defs/OrderLine"
      }
    },
    "amounts": {
      "$ref": "#/$defs/OrderAmounts"
    }
  },
  "required": [
    "id",
    "state",
    "store",
    "store_address",
    "items",
    "total_minor",
    "currency",
    "created_at",
    "placed_at",
    "ready_eta",
    "ready_at",
    "refunded_minor",
    "failure_code",
    "fulfillment",
    "lines",
    "amounts"
  ],
  "$defs": {
    "DeliveryStatus": {
      "type": "string",
      "enum": [
        "finding_courier",
        "heading_to_store",
        "at_store",
        "on_the_way",
        "arriving",
        "delivered",
        "failed"
      ]
    },
    "Fulfillment": {
      "type": "object",
      "properties": {
        "type": {
          "description": "How the person gets the order. A delivery that never got a driver becomes `pickup`, with `changed_from` set; tell the person to collect it.",
          "type": "string",
          "enum": [
            "pickup",
            "delivery"
          ]
        },
        "name": {
          "description": "The name the store has the order under, as its own confirmation stated it. What the person says at the counter.",
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "address": {
          "description": "Where the person collects it. For pickup, the same as `store_address`. For delivery, the street line it is going to.",
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "ready_text": {
          "description": "The pickup time word for word, the same as `ready_eta`. Show it as written; it is not a timestamp.",
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "merchant_order_number": {
          "description": "The store's own number for the order, not Layout's id.",
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "instructions": {
          "description": "The store's own pickup instructions, word for word.",
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "status": {
          "description": "Delivery only: where the driver is. Absent for pickup.",
          "anyOf": [
            {
              "$ref": "#/$defs/DeliveryStatus"
            },
            {
              "type": "null"
            }
          ]
        },
        "eta": {
          "description": "Delivery only: when it should arrive, ISO 8601, once known.",
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "courier": {
          "description": "Delivery only: the driver, while one is assigned. Cleared once the delivery ends.",
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "first_name": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "vehicle": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              },
              "required": [
                "first_name",
                "vehicle"
              ]
            },
            {
              "type": "null"
            }
          ]
        },
        "proof_photo_url": {
          "description": "Delivery only: the driver's photo of the order at the door, once delivered and left there. Show it as proof of delivery.",
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "failure_reason": {
          "description": "Delivery only: why the delivery could not be completed, in words you can show the person. Set when `status` is `failed`.",
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "changed_from": {
          "description": "Set when a delivery became a pickup because no driver could be booked.",
          "anyOf": [
            {
              "type": "string",
              "const": "delivery"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "type",
        "name",
        "address",
        "ready_text",
        "merchant_order_number",
        "instructions"
      ]
    },
    "OrderAmounts": {
      "type": "object",
      "properties": {
        "subtotal_minor": {
          "description": "The store's own subtotal, when it stated one.",
          "anyOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "null"
            }
          ]
        },
        "tax_minor": {
          "description": "The store's own tax, when it stated it.",
          "anyOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "null"
            }
          ]
        },
        "merchant_total_minor": {
          "description": "The store's total, the same as `total_minor`.",
          "anyOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "null"
            }
          ]
        },
        "service_fee_minor": {
          "description": "Layout's service fee.",
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        "service_fee_waived": {
          "description": "True when the person's plan waives the fee: it is shown but not charged.",
          "type": "boolean"
        },
        "credit_minor": {
          "description": "Layout credit taken off the charge.",
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        "courier_fee_minor": {
          "description": "The delivery fee charged, at cost. 0 for pickup, when no driver delivered, and while `charged_minor` is null.",
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        "tip_minor": {
          "description": "The driver's tip charged, all of it to the driver. 0 for pickup, when no driver delivered, and while `charged_minor` is null.",
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        "charged_minor": {
          "description": "What the person's card was charged for the placed order: the store's total, plus the fee unless waived, plus any delivery fee and tip, less credit. Until the delivery ends it is the delivery as approved. Once the delivery ends it is what was captured, which is less when no driver delivered, and null while Layout decides how a failed delivery ended. Also null until `state` is `placed`, and on a simulated order. A later refund is not netted here.",
          "anyOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "subtotal_minor",
        "tax_minor",
        "merchant_total_minor",
        "service_fee_minor",
        "service_fee_waived",
        "credit_minor",
        "courier_fee_minor",
        "tip_minor",
        "charged_minor"
      ]
    },
    "OrderId": {
      "type": "string",
      "pattern": "^ord_[A-Za-z0-9]{1,64}$"
    },
    "OrderLine": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "quantity": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991
        },
        "unit_price_minor": {
          "description": "Per item, when the store's cart priced it.",
          "anyOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "null"
            }
          ]
        },
        "modifiers": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "name",
        "quantity",
        "unit_price_minor",
        "modifiers"
      ]
    },
    "OrderState": {
      "type": "string",
      "enum": [
        "building",
        "carted",
        "placing",
        "placed",
        "failed",
        "unconfirmed",
        "refunded"
      ]
    }
  }
}