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

# Ordering Module

> Learn how to use the Roblox ReAdmin Ordering Module

## Overview

The Ordering Module allows you to manage [orders](/features/orders) efficiently within your game. This documentation will guide you through authenticating your module and using its various methods for order management.

## Getting Started

First, require the module and authenticate using your unique [ReAdmin Loader ID](/api-reference/api-keys).

```lua theme={null}
local orderSystem = require(16692333866)

orderSystem.authenticate('Your ReAdmin Loader Id');
```

## Managing Orders

Once authenticated, you can manage orders using the following methods:

### Creating an Order

To create an order, call `createOrder` with the player object and order details.

```lua theme={null}
local order = orderSystem.createOrder(player, recipient, {{name = "ItemName", quantity = ItemQuantity}})
```

* `player`: The player object initiating the order.
* `recipient`: The player object who will receive the order. This can be the same as `player`.
* `{{name = "ItemName", quantity = ItemQuantity}}`: A table containing order item details.

### Claiming an Order

To claim an order for processing, use the `claimOrder` method.

```lua theme={null}
orderSystem.claimOrder(orderId, player)
```

* `orderId`: The ID of the order to claim.
* `player`: The player object claiming the order.

### Releasing an Order

If needed, an order can be released using the `releaseOrder` method.

```lua theme={null}
orderSystem.releaseOrder(orderId, player)
```

### Completing an Order

Mark an order as completed with the `completeOrder` method.

```lua theme={null}
orderSystem.completeOrder(orderId, player)
```

### Canceling an Order

Orders can be canceled using the `cancelOrder` method.

```lua theme={null}
orderSystem.cancelOrder(orderId, player)
```

### Setting Order Status

Additionally, you can update the status of an order to indicate it has been handed to the customer or is awaiting pickup. *It is suggested to update the order to handed to customer once finished*

* **Handed to Customer:**

  ```lua theme={null}
  orderSystem.setHandedToCustomer(orderId, player)
  ```

* **Awaiting Pickup:**

  ```lua theme={null}
  orderSystem.setAwaitingPickup(orderId, player)
  ```

## Order Life Cycle

The life cycle of an order follows a comprehensive and straightforward process, designed to streamline order management within games. This life cycle begins when an order is created and ends either when it is completed or canceled, depending on the game's needs and player actions. Here's a breakdown of the typical stages an order goes through:

1. **Creation**: The process starts when a player (or the game itself) creates an order using the `createOrder` method. This step involves specifying the order's recipient and the details of the items being ordered, such as name and quantity.

2. **Claiming**: Once an order is created, it needs to be processed. A player, usually a chief, claims the order using the `claimOrder` method. Claiming an order signifies that it is currently being handled and is in the process of fulfillment.

3. **Released**: Once an order is claimed, the user who claimed it may leave before finishing the order. You can remove the player from the order by using the `releaseOrder` method.

4. **Completion**: Once the order is finished being prepared, the order is completed using the `completeOrder` method.

5. **Status Update**: Depending on the game's mechanics, the order may need to be marked as "Awaiting Pickup" or "Handed to Customer" using the respective methods. This step is crucial for games where physical (in-game) item transfer or pickup is a part of the gameplay.

6. **Cancellation**: At any point before completion, an order can be canceled using the `cancelOrder` method. Cancellation might occur for various reasons, such as the player canceling their request or due to issues in fulfilling the order. Canceling an order removes it from the processing queue and marks it as closed without fulfillment.

The flexibility of the Ordering Module allows for efficient management of these stages, ensuring a smooth and streamlined experience for both players and administrators. By facilitating easy creation, claiming, processing, and finalization of orders, the module supports dynamic in-game economies and interactions, enhancing the overall gameplay experience.

## What if I don't have the Player instance?

If you wish to spoof a player instead of passing a Player instance, you can pass their user ID like this.

```lua theme={null}
orderSystem.setAwaitingPickup(orderId, {UserId: 1})
```

## Conclusion

With the Ordering Module, managing orders within your game is streamlined and efficient. Authenticate the module and use the provided methods to create, claim, release, complete, cancel orders, and update their status as needed.
