## Order Drafts Overview

This feature in Carts API enables the cart to be transformed into a schema ready for submission to the **Order Management System (OMS)**, representing the **order draft** stage before the order is officially created. At this stage, the cart contains all necessary data, including items, fulfillment details, fees, taxes, and payment information. This transformation ensures that the cart aligns with OMS requirements, allowing for final review and confirmation of the order before proceeding to fulfillment.

## Prerequisites

There are two types of prerequisites, depending on your cart configurations. One of the following prerequisites must be completed sequentially to configure an order draft.

### Prerequisites where cart configurations are set to BLOCK

```json
"configuration": {
    "order": {
        "validate": {
            "paymentsRemaining": "BLOCK",
            "taxRemaining": "BLOCK",
            "invalidItem": "BLOCK",
            "itemOutOfStock": "BLOCK"
        }
    }
}
```

**Prerequisites**

1. [Create a cart](https://developer.fabric.inc/v3/cart-and-checkout/api-reference/carts-v3/carts/carts).
2. [Add item](https://developer.fabric.inc/v3/cart-and-checkout/api-reference/carts-v3/items/items) to the cart.
3. [Add taxes](https://developer.fabric.inc/v3/cart-and-checkout/api-reference/carts-v3/validations/add-tax) to the resources in the cart.
4. [Add payments to the cart](https://developer.fabric.inc/v3/cart-and-checkout/api-reference/carts-v3/payments/create-payments), ensuring they match the cart total.
5. Ensure that the items added to the cart are valid and in stock.

### Prerequisites where cart configurations are set to NONE

**Prerequisites**

1. [Create a cart](https://developer.fabric.inc/v3/cart-and-checkout/api-reference/carts-v3/carts/carts).
2. [Add item](https://developer.fabric.inc/v3/cart-and-checkout/api-reference/carts-v3/items/items) to the cart.

## Order Drafts Initialization

The order draft captures a snapshot of the cart, which can then be converted into an order. The ability to create an order draft is controlled by [cart configurations](https://developer.fabric.inc/v3/cart-and-checkout/api-reference/carts-v3/configuration-behaviors). Cart offers users the flexibility to prevent order draft creation if:

- Payments haven’t been added to the cart.
- Taxes are missing for resources in the cart.
- Items are invalid.
- Items are out of stock.

## Cart Configuration

## Examples

### Creating an Order Draft to Send to OMS

Use the [create an order draft](https://developer.fabric.inc/v3/cart-and-checkout/api-reference/carts-v3/order-drafts/create-order-drafts) endpoint to create an order draft and send it to OMS as in the following example:

```bash
curl --location '{{orchestrator_domain}}/carts/{{cartId}}/order-draft' \
--header 'x-fabric-tenant-id: {tenantId}' \
--header 'x-fabric-request-id: {{requestId}}' \
--header 'x-fabric-channel-id: {{channelId}}' \
--header 'Authorization: {authToken}' \
--header 'Content-Type: application/json' \
--data '{
    "orderNumber": "W0013"
}'
```

**Response**

```json
{
    "order": {
        "number": "W0013",
        "currency": "USD",
        "createdAt": "2024-06-24T09:22:40.979+00:00",
        "attributes": {}
    },
    "cartId": "39ea2154-7160-4feb-ae42-1506223efd95",
    "attributes": {
        "name": "cart test",
        "description": "This cart is created by cart v2 service"
    },
    "customerContext": {
        "id": "C01",
        "segments": [
            {
                "name": "membership",
                "value": ["premium"]
            },
            {
                "name": "customer-type",
                "value": ["high"]
            }
        ],
        "attributes": {
            "returnRate": "high",
            "city": "london",
            "type": "regular"
        }
    },
    "status": "ACTIVE",
    "state": [...],
    "price": {...},
    "promotions": {...},
    "fees": {...},
    "adjustments": {...},
    "addresses": {...},
    "lineItems": {...},
    "summary": {...},
    "fulfillments": {...},
    "coupons": [...],
    "appliedCoupons": [...],
    "notAppliedCoupons": [],
    "payments": {...},
    "channelId": "12",
    "updatedAt": "2024-06-24T09:22:40.907Z",
    "createdAt": "2024-06-24T09:07:37.140Z",
    "errors": []
}
```
