> ## 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.md) with the following scopes:

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

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

## Steps

**1. Create a draft order**

Create a draft order with line items. The order is not yet active and can be freely modified.

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

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"
      }
    ]
  }
}
```

**2. Complete the draft order**

Complete the draft to make the order active and assign it an `order_id`.

Orders API [PUT /accounts/\{aid}/shopping/draft\_orders/\{id}/complete](/api-reference/draft/aid_draft_orders_id_complete_put.md)

**3. Create a checkout session**

Create a checkout session, using the `order_id` as `merchant_reference`.

Checkout API [POST /sessions-profile](/api-reference/session/checkout_session_profile_post.md)

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.

Create the session:

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

# Create session
curl 'https://api.dintero.com/v1/accounts/P12345678/payments/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)
```

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

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

**4. Mark the order as authorized**

Record the authorization on the order to mark funds as reserved.

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

Example request body:

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

**5. 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.

Checkout API [POST /transactions/\{id}/capture](/api-reference/transactions/transactions_id_capture_post.md)

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

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
}
```

**6. Refund the transaction**

If the customer requests a refund, refund the payment in the Checkout service first. Then record the refund on the order.

Checkout API [POST /transactions/\{id}/refund](/api-reference/transactions/transactions_id_refund_post.md)

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

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
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.