# Order states

> The states an order moves through from creation to shipment, and which of them are final.

Once an order has been created, API clients and RPI Print API Dashboard users can follow its progress through the order status.

| Order status           | Final state | Description                                                                                                                                                                                                                                                                                                         |
| ---------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| RECEIVED               | no          | Initial state. The order passed initial validation, and RPI Print API is processing its files. If a temporary problem at RPI stops the processing, RPI Print API keeps the order in RECEIVED and tries again for about 30 minutes.                                                                                  |
| QUEUED                 | no          | Initial state. RPI Print API accepted the order, but the customer has exceeded its order limit for the rolling 24 hours. The order moves to RECEIVED when the limit allows. See [Limits and quotas](orders.md#limits-and-quotas).                                                                                   |
| VALIDATING             | no          | RPI Print API is calculating shipping, pricing and tax. The order cannot be cancelled in this status.                                                                                                                                                                                                               |
| VALID_AWAITING_PAYMENT | no          | The order has been validated and is waiting for the daily charge (02:00 UTC) to the default payment method set in the dashboard. It stays here until a charge succeeds; see `PaymentFailure` in [Webhooks](webhooks.md).                                                                                            |
| VALID_HOLDING_BIN      | no          | The order is in the holding bin and is waiting to be sent to the printer. While the order is in the holding bin, it can be cancelled.                                                                                                                                                                               |
| PRINTING               | no          | The order has been submitted to the printer. Cancellation requests are forwarded to the printer, which may still reject them.                                                                                                                                                                                       |
| RECEIVED_BY_PRINTER    | no          | The printer has accepted the order. Cancellation requests are forwarded to the printer, which may still reject them.                                                                                                                                                                                                |
| IN_PRODUCTION          | no          | The printer has begun producing the order. Cancellation requests are forwarded to the printer, which may still reject them.                                                                                                                                                                                         |
| READY_TO_SHIP          | no          | The order has been produced and is ready to ship. Cancellation requests are forwarded to the printer, which may still reject them.                                                                                                                                                                                  |
| SHIPPED                | yes         | The order has been shipped, and its tracking details are in `shipmentTracking`; see [Tracking numbers](orders.md#tracking-numbers). Cancellation is no longer possible.                                                                                                                                             |
| FAILED                 | yes         | The order failed validation or the processing of its files. The order's validations explain why it failed. An order also fails if a temporary problem at RPI lasts longer than about 30 minutes; its status message then says so, and the order can be submitted again as a new order with a new `customerOrderId`. |
| CANCELLATION_REQUESTED | no          | Cancellation has been requested for this order. The printer answers the request asynchronously, which can take a while.                                                                                                                                                                                             |
| CANCELLED              | yes         | The order has been cancelled. If the order was already paid, a full or partial refund has been queued, depending on how far the order had progressed. If the refund fails, the order moves to EXCEPTION.                                                                                                            |
| EXCEPTION              | no          | The order typically needs manual action, because the printer rejected a cancellation or because of another internal error. After that action, the order can resume production or ship. Contact customer support about it.                                                                                           |
| REJECTED               | yes         | The order was rejected because the order-limit queue was full. A sandbox order is rejected as soon as it exceeds the order limit, because sandbox has no queue.                                                                                                                                                     |

:::info

Orders in final states cannot be cancelled. A cancel request is also refused while the order is `VALIDATING`, `CANCELLATION_REQUESTED` or `EXCEPTION`.

:::

:::note

`PRINTING` is the API and webhook status value for an order that has been submitted to the printer. The dashboard displays this same status as "Submitted to Printer". The status value on the API and webhook contract remains `PRINTING`.

The printer then reports progress through `RECEIVED_BY_PRINTER`, `IN_PRODUCTION`, and `READY_TO_SHIP` before `SHIPPED`.

:::

## Success flow

```mermaid
flowchart TD
    SHIPPED(((SHIPPED)))
    START{POST /orders/create}

        START==>RECEIVED
        RECEIVED==>VALIDATING
        VALIDATING==>VALID_AWAITING_PAYMENT
        VALID_AWAITING_PAYMENT==>|Scheduled automatic payment| VALID_HOLDING_BIN
        VALID_HOLDING_BIN==> |Submitted for printing| PRINTING
        PRINTING==> |Accepted by printer| RECEIVED_BY_PRINTER
        RECEIVED_BY_PRINTER==> |Production started| IN_PRODUCTION
        IN_PRODUCTION==> |Production complete| READY_TO_SHIP
        READY_TO_SHIP===> |Order shipped|SHIPPED
```

## Before the order reaches the printer

An order waits here for validation, payment and the holding bin. A cancel request succeeds at any of these statuses
except `VALIDATING`.

```mermaid
flowchart TB
    START{POST /orders/create}
    START==>RECEIVED
    START-->|Over 24h limit| QUEUED
    QUEUED-->|Released| RECEIVED
    START-->|Over queue limit| REJECTED(((REJECTED)))
    START-->|Validation failed| FAILED(((FAILED)))
    RECEIVED-->|Validation failed| FAILED
    RECEIVED==>VALIDATING
    VALIDATING==>VALID_AWAITING_PAYMENT
    VALID_AWAITING_PAYMENT==>|Payment processed| VALID_HOLDING_BIN
    VALID_HOLDING_BIN==>|Submitted for printing| PRINTING
    QUEUED-.->|Cancelled| CANCELLED(((CANCELLED)))
    RECEIVED-.->|Cancelled| CANCELLED
    VALID_AWAITING_PAYMENT-.->|Cancelled| CANCELLED
    VALID_HOLDING_BIN-.->|Cancelled| CANCELLED
```

## At the printer

An order is at the printer while its status is `PRINTING`, `RECEIVED_BY_PRINTER`, `IN_PRODUCTION` or `READY_TO_SHIP`.
A cancel request for such an order is sent to the printer, which decides the outcome. The printer can also cancel an
order on its own. If RPI Print API cannot submit an order to the printer, the order returns to `VALID_HOLDING_BIN` and
RPI Print API submits it again, so a status you poll can move from `PRINTING` back to `VALID_HOLDING_BIN`.

```mermaid
%%{init: {"flowchart": {"nodeSpacing": 60, "rankSpacing": 70}}}%%
flowchart LR
    AT_PRINTER[Any status at the printer]
    AT_PRINTER==>|Order shipped| SHIPPED(((SHIPPED)))
    AT_PRINTER-->|Cancel request sent to printer| CANCELLATION_REQUESTED
    CANCELLATION_REQUESTED-->|Printer confirmed| CANCELLED(((CANCELLED)))
    CANCELLATION_REQUESTED-->|Printer declined and shipped| SHIPPED
    CANCELLATION_REQUESTED-.->|Printer refused, order already shipping| EXCEPTION["EXCEPTION (usually clears when the order ships)"]
    AT_PRINTER-->|Cancelled by printer| CANCELLED
```

The statuses an order passes through at the printer, in order:

```mermaid
flowchart LR
    subgraph AT_PRINTER_VIEW[Any status at the printer]
        direction LR
        PRINTING==>|Accepted by printer| RECEIVED_BY_PRINTER
        RECEIVED_BY_PRINTER==>|Production started| IN_PRODUCTION
        IN_PRODUCTION==>|Production complete| READY_TO_SHIP
    end
```

## Exceptions

An order in `EXCEPTION` typically needs manual action from RPI customer support. Where support can resolve it, the order resumes at the printer or ships.

```mermaid
flowchart LR
    VALIDATING-.->|Shipping or tax calculation failed| EXCEPTION
    AT_PRINTER[Any status at the printer]-.->|Printer or submission error| EXCEPTION
    CANCELLATION_REQUESTED-.->|Printer refused cancellation, order already shipping| EXCEPTION
    CANCELLED-.->|Refund failed| EXCEPTION
    EXCEPTION-.->|Resolved by support, where possible| RESUMED[Resumes at the printer]
    EXCEPTION-.->|Resolved| SHIPPED(((SHIPPED)))
```
