> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hyra.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Using the Order Logging Module

> Hyra provides a Roblox Lua wrapper for its Order Logging system

The Hyra Order Logging API is an advanced, real-time solution for monitoring and managing the lifecycle of an order. It offers comprehensive visibility from the moment an order is placed to when it's ready for pickup, tracking each participant involved.

## Ready made scripts

Hyra provides some out of the box solutions for order logging for popular solutions.

* [HandTo System by r\_r](https://create.roblox.com/marketplace/asset/15281167443/HandTo-System)
* [EasyPOS Cafe](https://create.roblox.com/store/asset/138387535633314/EasyPOS-Hyra-Order-Logging-Addon)

## Order Status Lifecycle

Each order must have a status associated with it. Depending on your system, you may decide to use different statuses. The following statuses are available:

* `handed_to` - The order has been handed to the customer
* `submitted` - The order has been submitted by the cashier
* `waiting_for_preparation` - The order is waiting for preparation by a chef or other staff member
* `finding_new_colleague` - The order is waiting for a new colleague to take over preparation (for example, if the previous chef left the game)
* `preparing` - The order is being prepared by a chef or other staff member
* `completed` - The order has been completed
* `waiting_for_pickup` - The order is waiting for pickup by the customer or a delivery person
* `cancelled` - The order has been cancelled

## Requiring the module

The module used for Order Logging is stateful and persists its authentication state with the Hyra API. If you use a single script order solution, you can directly require the module as follows:

```lua theme={null}
local orderLog = require(15254660066)
```

If you use multiple scripts, you can [create a module script exporter](/api-reference/players/module/creating-an-exporter). You need one of these to maintain the state of the module across several scripts.

## Authentication

To authenticate, input your unique `apiKey` and `workspaceId` at the beginning of your main script:

```lua theme={null}
orderLog.setupAPI(apiKey, workspaceId)
```

You only need to do this once per game server.

## Interacting with the module

<AccordionGroup>
  <Accordion title="Creating an order">
    To log a new order, input the customer and actor as player objects, along
    with an argument table that can include an array of `items` and the initial
    `status`.

    The `customer` and the `actor` are both [Player instances](https://create.roblox.com/docs/reference/engine/classes/Player).

    <CodeGroup>
      ```lua Using Player Instance theme={null}
      orderLog.createOrder(customer, actor, {
          items = {"item 1", "item 2"},
          status = "waiting_for_preparation",
      })
      ```

      ```lua Using User Object theme={null}
      orderLog.createOrder({ UserId = 1}, { UserId = 2}, {
          items = {"item 1", "item 2"},
          status = "waiting_for_preparation",
      })
      ```
    </CodeGroup>

    Once an order has been created, you will receive a response object that includes the unique `id` and `order_number` for the order.

    ```lua theme={null}
    {
        error = false,
        id = "653db4bb1e3727cc1851ac07",
        order_number = "1001",
    }
    ```

    If there is anything wrong with the request, you will receive an error message.

    ```lua theme={null}
    {
        error = true,
        message = "Customer is required",
    }
    ```

    When creating an order, you will need to specify a valid `actor`. In some cases, you may not have a valid player, for example if the order was submitted via a kiosk. In this case, there are a few system IDs you can use:

    * `1` - POS (Point of Sale System)
    * `2` - Kiosk
    * `3` - Mobile Ordering
    * `4` - NPC
  </Accordion>

  <Accordion title="Updating order status">
    Using the unique order `id` (not the order\_number) you can update the status of an order

    <CodeGroup>
      ```lua Waiting for Preparation theme={null}
      orderLog.setWaiting("653db4bb1e3727cc1851ac07")
      ```

      ```lua Preparing theme={null}
      orderLog.setPreparing("653db4bb1e3727cc1851ac07", game.Players.Roblox) -- Or spoof a player object (see docs - Creating an Order, Using User Object)
      ```

      ```lua Finding a new colleague theme={null}
      orderLog.setReprepare("653db4bb1e3727cc1851ac07")
      ```

      ```lua Ready for pickup theme={null}
      orderLog.setReadyForPickup("653db4bb1e3727cc1851ac07")
      ```

      ```lua Completed theme={null}
      orderLog.setComplete("653db4bb1e3727cc1851ac07")
      ```

      ```lua Cancelled theme={null}
      orderLog.setCancelled("653db4bb1e3727cc1851ac07")
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>
