# Ordering modes: orders through Tamr or your app's cart

> How ordering works with Tamr's AI waiter SDK: dine-in and pickup orders through Tamr with Tamr Pay, or the waiter's dishes proposed into your app's own cart and checkout.

Source: https://tamr.link/docs/guides/ordering

Where orders go is the restaurant's choice, in its dashboard: **Settings > Waiter in your app > Ordering**. It can be one place for every order, or different for each way of ordering (dine-in, pickup, delivery). A client can also read it from [Get the waiter](https://tamr.link/docs/api/get-waiter): `ordersGoTo` (`tamr` or `app_cart`), and `ordersGoToByMode` when the ways differ. Your code is mostly the same in both modes.

## Different for each way of ordering

Turn on **Different for each way of ordering** under "Orders go to" and pick where dine-in, pickup and delivery orders go. A way left as it is follows "Orders go to". The `mode` your app passes decides which one applies (with no `mode`, dine-in), for the waiter's turns and for every ordering call: seating at a table and sending an order check dine-in, pickup checks pickup.

A chain that serves at the table and delivers through its own app sets "Orders go to" to **Your app's cart** and dine-in to **Tamr**:

- In the restaurant, the diner scans the table's code with your app. Pass it as `tableScan` (no `mode`, or `mode: "dine_in"`): the waiter offers dishes to add to Your order and the diner sends it to the kitchen, as on Tamr's QR menu. Your app hears `order.placed`.
- At home, pass `mode: "delivery"` (or `mode: "pickup"`): the waiter proposes dishes to your cart, and your checkout takes the order.

Implement both sets of handlers below. [Get the waiter](https://tamr.link/docs/api/get-waiter) then answers, for example:

```json
{
  "ordersGoTo": "app_cart",
  "ordersGoToByMode": { "dine_in": "tamr", "pickup": "app_cart", "delivery": "app_cart" }
}
```

`ordersGoToByMode` has every way filled in, and is left out when the restaurant doesn't use it: read `ordersGoToByMode?.[mode] ?? ordersGoTo`. A change reaches your app's next message, with no app update.

## When orders go to Tamr

The diner adds dishes from the waiter's cards to "Your order" inside the page and sends it there, as on Tamr's QR menu. Your app does three things:

1. **Dine-in.** When the diner scans the table's printed QR code with your app, pass what they scanned as `tableScan` (the full `tamr.link` address the code opens, or the table's code) in the controller's options or with `setContext`. Tamr checks it against the restaurant's floor plan before an order can be sent. `table` alone is only a hint.
2. **Pickup.** Pass `mode: "pickup"`. The page asks where and when to collect, and the diner's name and phone, which go to the restaurant only.
3. **Listen.** `order.placed` when an order reaches the restaurant's team, `order.cancelled` if it then ends unserved, and `payment.completed` when Tamr Pay took a payment. When the diner taps Pay, the SDK opens the payment provider's page in the platform's in-app browser (a new tab on the web), never inside the webview, and only for an `https` link.

Delivery doesn't go through Tamr: a chain that delivers through its app sends delivery to the app's cart, on its own or with [each way of ordering its own](#different-for-each-way-of-ordering). Your backend hears the same orders as [webhooks](https://tamr.link/docs/webhooks/order-placed).

## When orders go to the app's cart

The waiter proposes dishes, your cart accepts or refuses each line, and the chat card shows what really landed.

- **Answer each proposal** with `onCartAdd`, `onCartUpdate` and `onCartRemove`, within 15 seconds.
- **Tell the page what your cart holds** with `sendCart`: when the chat opens, and after every change in your app.
- **Listen** for `checkout` (the diner asked to check out: open your checkout) and `open_dish` (the diner tapped a dish: show your page for it).

Each SDK's page shows the handler in its language. A proposal, as the page sends it:

cart.add:

```json
{
  "v": 1,
  "id": "add_0001",
  "type": "cart.add",
  "ts": 1792310437000,
  "data": {
    "lines": [
      {
        "lineId": "ln_0001",
        "dishId": "dish_kafta",
        "variantId": null,
        "optionIds": [],
        "externalId": "SKU-1042",
        "variantExternalId": null,
        "optionExternalIds": [],
        "title": "Kafta plate",
        "variantLabel": null,
        "choices": [],
        "unitPrice": "145000",
        "currency": "LBP",
        "imageUrl": "https://tamr.link/image-proxy/menu/kafta.webp",
        "quantity": 2,
        "note": null
      },
      {
        "lineId": "ln_0002",
        "dishId": "dish_fattoush",
        "variantId": null,
        "optionIds": [],
        "externalId": null,
        "variantExternalId": null,
        "optionExternalIds": [],
        "title": "Fattoush",
        "variantLabel": null,
        "choices": [],
        "unitPrice": "65000",
        "currency": "LBP",
        "imageUrl": null,
        "quantity": 1,
        "note": "no radish"
      },
      {
        "lineId": "ln_0003",
        "dishId": "dish_bowl",
        "variantId": "var_large",
        "optionIds": [
          "opt_chicken",
          "opt_rice",
          "opt_hummus"
        ],
        "externalId": "BOWL",
        "variantExternalId": "BOWL-L",
        "optionExternalIds": [
          "CHK",
          null,
          "HUM"
        ],
        "title": "Build your bowl",
        "variantLabel": "Large",
        "choices": [
          "Grilled chicken",
          "Rice",
          "Hummus"
        ],
        "unitPrice": "320000",
        "currency": "LBP",
        "imageUrl": "https://tamr.link/image-proxy/menu/kafta.webp",
        "quantity": 1,
        "note": null
      }
    ],
    "origin": "waiter",
    "conversationId": "cm1conv0001"
  }
}
```

### Each proposed line

- **Tamr's ids, always:** `dishId`, `variantId` (the size, or null), `optionIds`.
- **Your ids, when the restaurant mapped them:** `externalId`, `variantExternalId`, `optionExternalIds`, null where not mapped. See [Product ids](https://tamr.link/docs/guides/product-ids-and-nutrition).
- **Enough to rebuild the line with no mapping:** `title`, `variantLabel`, `choices` (option names), `unitPrice` and `currency` (minor units), `imageUrl`, `quantity`, `note` (the diner's request, such as "no onions").
- `lineId`, unique per proposed line: answer and de-duplicate by it.
- `picks`, only on a set the diner built from other dishes ("pick any 3"): each pick with Tamr's ids, yours when mapped, its title and `count` per one set. `quantity` multiplies the whole set.
- `treat`, only on a [treat on the house](https://tamr.link/docs/guides/treats): price that line at zero.

### Your answer

Answer each line with `{ lineId, ok: true }`, or `{ lineId, ok: false, reason, message }` with `reason` one of `sold_out`, `not_found`, `limit` or `other`; `message`, up to 200 characters, is shown to the diner. To refuse the whole proposal, answer `{ ok: false, error: { code: "failed", message } }`. With no answer in 15 seconds, the card says the app didn't answer.

reply:

```json
{
  "v": 1,
  "id": "msg_0043",
  "type": "reply",
  "ts": 1792310443000,
  "data": {
    "ok": true,
    "lines": [
      {
        "lineId": "ln_0001",
        "ok": true
      },
      {
        "lineId": "ln_0002",
        "ok": false,
        "reason": "not_found"
      },
      {
        "lineId": "ln_0003",
        "ok": false,
        "reason": "sold_out"
      }
    ]
  },
  "replyTo": "add_0001"
}
```

### Your cart, for the page

`sendCart` lines name each dish by exactly one id, Tamr's `dishId` or your `externalId` (which can be a product Tamr has never seen, such as drinks from another system), with optional size and option ids, `quantity`, and `picks` for a set. Up to 50 lines. Lines Tamr can't place come back as `unmapped`.

cart.snapshot:

```json
{
  "v": 1,
  "id": "snap_0001",
  "type": "cart.snapshot",
  "ts": 1792310445000,
  "data": {
    "lines": [
      {
        "externalId": "SKU-1042",
        "quantity": 2
      },
      {
        "dishId": "dish_bowl",
        "variantId": "var_large",
        "optionIds": [
          "opt_chicken"
        ],
        "quantity": 1
      },
      {
        "externalId": "DRK-99",
        "variantExternalId": "DRK-99-L",
        "quantity": 1
      }
    ]
  }
}
```

Your checkout is the price of record: Tamr's prices on the card are its menu's prices. After your checkout places the order, your backend [sends it to Tamr](https://tamr.link/docs/guides/sending-orders).
