> ## 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.

# Using Orders and Checkout together

> Combine the Dintero Order Management and Checkout services to create draft orders, take payment, capture, and refund transactions in one flow.

The Order Management and Checkout services are built to work together but can also be used independently.

## Authorization

Create an [API Client](/docs/checkout/checkout-client) with the following scopes:

* `admin:checkout`
* `admin:shopping`

Note down the `client_id` and `client_secret` for use in the examples below.

## Steps

<Steps>
  <Step title="Create a draft order">
    Create a draft order with line items. The order is not yet active and can be freely modified.

    <Badge color="green">Orders API</Badge> [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"
          }
        ]
      }
    }
    ```
  </Step>

  <Step title="Complete the draft order">
    Complete the draft to make the order active and assign it an `order_id`.

    <Badge color="green">Orders API</Badge> [PUT /accounts/\{aid}/shopping/draft\_orders/\{id}/complete](/api-reference/draft/aid_draft_orders_id_complete_put)
  </Step>

  <Step title="Create a checkout session">
    Create a checkout session, using the `order_id` as `merchant_reference`.

    <Badge>Checkout API</Badge> [POST /sessions-profile](/api-reference/session/checkout_session_profile_post)

    Example request body:

    ```json theme={null}
    {
      "url": {
        "return_url": "https://example.com/accept",
        "callback_url": "https://example.com/callback"
      },
      "order": {
        "amount": 39800,
        "currency": "NOK",
        "merchant_reference": "order_id",
        "items": [
          {
            "id": "175938",
            "line_id": "1",
            "description": "Stablestol for utendørsbruk",
            "quantity": 2,
            "amount": 39800,
            "vat_amount": 7960,
            "vat": 25
          }
        ]
      },
      "profile_id": "default"
    }
    ```

    <Note>`profile_id` may vary. Check Backoffice for the correct value.</Note>

    Create the session:

    <CodeGroup>
      ```bash cURL theme={null}
      # Get access token
      curl 'https://api.dintero.com/v1/accounts/P11223351/auth/token' \
        -H 'Content-Type: application/json' \
        --user client_id:client_secret \
        -d '{"audience": "https://api.dintero.com/v1/accounts/P11223351", "grant_type": "client_credentials"}'

      # Create session
      curl 'https://checkout.dintero.com/v1/sessions-profile' \
        -H 'Content-Type: application/json' \
        -H 'Authorization: Bearer token' \
        -d '<json-body-from-above>'
      ```

      ```python Python theme={null}
      from dintero import Dintero

      dintero = Dintero('T12345678', 'client_id', 'client_secret')
      checkout = dintero.checkout()
      session_info = checkout.create_session(session_body)
      ```
    </CodeGroup>

    See [Display Checkout](/docs/checkout/display-checkout) for how to present the session to the customer.

    When payment completes, poll the transaction status and confirm it is `AUTHORIZED` before proceeding.
  </Step>

  <Step title="Mark the order as authorized">
    Record the authorization on the order to mark funds as reserved.

    <Badge color="green">Orders API</Badge> [POST /accounts/\{aid}/shopping/orders/\{order\_id}/authorizations](/api-reference/orderauthorizations/aid_orders_id_authorization_post)

    Example request body:

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

  <Step title="Capture the transaction">
    Once items are ready to ship, capture the payment in the Checkout service. Then record the capture on the order to keep state in sync.

    <Badge>Checkout API</Badge> [POST /transactions/\{id}/capture](/api-reference/transactions/transactions_id_capture_post)

    <Badge color="green">Orders API</Badge> [POST /accounts/\{aid}/shopping/orders/\{order\_id}/captures](/api-reference/ordercaptures/aid_orders_id_capture_post)

    Example request body for the Orders API call:

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

  <Step title="Refund the transaction">
    If the customer requests a refund, refund the payment in the Checkout service first. Then record the refund on the order.

    <Badge>Checkout API</Badge> [POST /transactions/\{id}/refund](/api-reference/transactions/transactions_id_refund_post)

    <Badge color="green">Orders API</Badge> [POST /accounts/\{aid}/shopping/orders/\{order\_id}/refunds](/api-reference/orderrefunds/aid_orders_id_refunds_post)

    Example request body for the Orders API call:

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