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

# Update an order with reversed items

> Modify a Dintero order by reversing existing items and adding new ones using the draft order endpoints to keep the captured amount and refunds aligned.

Update an order where existing items are reversed and new items are added.

<Steps>
  <Step title="Create the original order">
    Create a draft order with line items.

    [POST /accounts/\{aid}/shopping/draft\_orders](/api-reference/draft/aid_draft_orders_post)

    Example request body:

    ```json theme={null}
    {
      "options": {
        "generate_order_id": "ALPHANUMERIC_9"
      },
      "order": {
        "currency": "NOK",
        "items": [
          {
            "id": "175938",
            "line_id": 1,
            "quantity": 2,
            "gross_amount": 39800,
            "tax_lines": [{ "amount": 7960, "percentage": 25 }],
            "description": "Stablestol for utendørsbruk",
            "description_alias": "Stablestol"
          }
        ]
      }
    }
    ```

    Then complete it to make it active.

    [PUT /accounts/\{aid}/shopping/draft\_orders/\{id}/complete](/api-reference/draft/aid_draft_orders_id_complete_put)
  </Step>

  <Step title="Authorize and capture the original order">
    Record the authorization and capture on the order to mark funds as reserved and collected.

    [POST /accounts/\{aid}/shopping/orders/\{order\_id}/authorizations](/api-reference/orderauthorizations/aid_orders_id_authorization_post)

    [POST /accounts/\{aid}/shopping/orders/\{order\_id}/captures](/api-reference/ordercaptures/aid_orders_id_capture_post)

    ```json theme={null}
    {
      "items": [{ "amount": 39800, "line_id": 1 }],
      "payment_details": { "payment_id": "PID_123" },
      "success": true
    }
    ```
  </Step>

  <Step title="Reverse the existing item and add a new one">
    Create a new draft linked to the original `order_id`. Include a reversal of the existing item (negative amounts) and a new replacement item. Use `related_item` to link the item being reversed.

    [POST /accounts/\{aid}/shopping/draft\_orders](/api-reference/draft/aid_draft_orders_post)

    ```json theme={null}
    {
      "options": {
        "order_id": "{order_id}"
      },
      "order": {
        "currency": "NOK",
        "items": [
          {
            "id": "175938",
            "line_id": 2,
            "quantity": 2,
            "gross_amount": -39800,
            "tax_lines": [{ "amount": -7960, "percentage": 25 }],
            "description": "Stablestol for utendørsbruk",
            "description_alias": "Stablestol",
            "reversed_reason": "Replace item",
            "related_item": { "line_id": 1, "type": "reversed" }
          },
          {
            "id": "003929",
            "line_id": 3,
            "quantity": 1,
            "gross_amount": 39800,
            "tax_lines": [{ "amount": 7960, "percentage": 25 }],
            "description": "Stablestol for innendørsbruk",
            "description_alias": "Stablestol Lux"
          }
        ]
      }
    }
    ```

    Then complete the draft to apply the update to the order.

    [PUT /accounts/\{aid}/shopping/draft\_orders/\{id}/complete](/api-reference/draft/aid_draft_orders_id_complete_put)
  </Step>

  <Step title="Authorize and capture the reversed and new items">
    Record the authorization and capture for both the reversed item (negative) and the new item.

    [POST /accounts/\{aid}/shopping/orders/\{order\_id}/authorizations](/api-reference/orderauthorizations/aid_orders_id_authorization_post)

    [POST /accounts/\{aid}/shopping/orders/\{order\_id}/captures](/api-reference/ordercaptures/aid_orders_id_capture_post)

    Reversed item:

    ```json theme={null}
    {
      "items": [{ "amount": -39800, "line_id": 2 }],
      "payment_details": { "payment_id": "PID_123" },
      "success": true
    }
    ```

    New item:

    ```json theme={null}
    {
      "items": [{ "amount": 39800, "line_id": 3 }],
      "payment_details": { "payment_id": "PID_123" },
      "success": true
    }
    ```
  </Step>

  <Step title="Refund remaining amount (if applicable)">
    If the original authorization is higher than the new items, include a refund line item in the draft update. Then authorize, capture, and refund that line.

    [POST /accounts/\{aid}/shopping/orders/\{order\_id}/authorizations](/api-reference/orderauthorizations/aid_orders_id_authorization_post)

    [POST /accounts/\{aid}/shopping/orders/\{order\_id}/captures](/api-reference/ordercaptures/aid_orders_id_capture_post)

    Authorize and capture the new item with the refund line:

    ```json theme={null}
    {
      "items": [
        { "amount": 39800, "line_id": 3 },
        { "amount": 1000, "line_id": 4 }
      ],
      "payment_details": { "payment_id": "PID_123" },
      "success": true
    }
    ```

    [POST /accounts/\{aid}/shopping/orders/\{order\_id}/refunds](/api-reference/orderrefunds/aid_orders_id_refunds_post)

    Refund the remaining amount:

    ```json theme={null}
    {
      "items": [{ "amount": 1000, "line_id": 4 }],
      "payment_details": { "payment_id": "PID_123" },
      "success": true
    }
    ```
  </Step>

  <Step title="Additional captures for partial authorization (if applicable)">
    If the original authorization is lower than the new item amount, add additional authorization and capture calls for the new item.

    [POST /accounts/\{aid}/shopping/orders/\{order\_id}/authorizations](/api-reference/orderauthorizations/aid_orders_id_authorization_post)

    [POST /accounts/\{aid}/shopping/orders/\{order\_id}/captures](/api-reference/ordercaptures/aid_orders_id_capture_post)

    ```json theme={null}
    {
      "items": [{ "amount": 1000, "line_id": 3 }],
      "payment_details": { "payment_id": "PID_321" },
      "success": true
    }
    ```
  </Step>
</Steps>
