> The index of all pages is at [llms.txt](https://developers.qliro.com/llms.txt). Add `.md` to any page URL for its Markdown.

# First order in the test environment (/qliro-checkout/get-started/first-order)

This page takes you from a test API key to a loaded checkout in the test environment. Each step links to the page with the details.

## Before you start

You need:

* A test API key and API secret. To get them, contact your integration manager or email [integration@qliro.com](mailto:integration@qliro.com).
* `curl`, `openssl` and `base64` in a bash or zsh shell.
* `jq`, to read the snippet in step 5.

| Environment | Host |
| :- | :- |
| Test | `https://pago.qit.nu` |
| Production | `https://payments.qliro.com` |

## 1. Write the order

Save this body as `order.json`. Replace `YOUR_TEST_API_KEY` with your test API key. Replace `your-domain.example` with a domain that you control.

```json
{
  "MerchantApiKey": "YOUR_TEST_API_KEY",
  "MerchantReference": "Order-1001",
  "Country": "SE",
  "Currency": "SEK",
  "Language": "sv-se",
  "MerchantConfirmationUrl": "https://your-domain.example/confirmation/",
  "MerchantTermsUrl": "https://your-domain.example/terms/",
  "MerchantCheckoutStatusPushUrl": "https://your-domain.example/qliro/checkout-status?token=order-1001-token",
  "MerchantOrderManagementStatusPushUrl": "https://your-domain.example/qliro/order-management-status?token=order-1001-token",
  "OrderItems": [
    {
      "MerchantReference": "RedHat",
      "Description": "Red hat original product",
      "Type": "Product",
      "Quantity": 1,
      "PricePerItemIncVat": 375.55,
      "PricePerItemExVat": 300.35
    }
  ]
}
```

* `MerchantReference` is your ID for the order. It has at most 25 characters: the letters A to Z and a to z, digits, `_`, `|` and `-`. Use a new value for each order.
* Qliro posts status changes to the two push URLs. For this first order, use addresses on a domain you control. [Notifications](https://developers.qliro.com/qliro-checkout/get-started/notifications-checkout) describes the requests and the response that Qliro expects.

## 2. Build the authorization token

The token is the SHA-256 hash of the request body followed by your API secret, encoded in base64.

```bash
export QLIRO_API_SECRET='YOUR_TEST_API_SECRET'
BODY=$(cat order.json)
TOKEN=$(printf '%s%s' "$BODY" "$QLIRO_API_SECRET" | openssl dgst -sha256 -binary | base64)
```

<Callout type="warn">
Hash the exact text that you send. If the body you send differs from the body you hashed, even by one space or line break, Qliro answers with status code 401.
</Callout>

For the same steps in other languages, see [Authorization](https://developers.qliro.com/qliro-checkout/get-started/authorization).

## 3. Create the order

```bash
curl -i -X POST "https://pago.qit.nu/checkout/merchantapi/orders" \
  -H "Content-Type: application/json" \
  -H "Authorization: Qliro $TOKEN" \
  --data-binary "$BODY"
```

Qliro answers with status code 201 and the order ID. If payment links are enabled for your account, the answer also has `PaymentLink`.

```json
{
  "OrderId": 5624967
}
```

If the request fails, the answer tells you why.

| Status code | ErrorCode | What to do |
| :- | :- | :- |
| 401 | None. The body is empty. | Build the token again from the exact body and your API secret. Make sure that the API key and the API secret belong together. Make sure that you send the request to the test host. |
| 400 | MERCHANT\_URL\_NOT\_SET | Add `MerchantCheckoutStatusPushUrl` and `MerchantOrderManagementStatusPushUrl` to the body. |
| 400 | ORDER\_ALREADY\_EXISTS | Change `MerchantReference`. You have used this value before. |
| 400 | INVALID\_INPUT | Read `ErrorMessage`. It names the field and the rule that the field breaks. |

For all parameters, see [Create order](https://developers.qliro.com/api-reference/merchant/orders/create-order) in the API Reference.

## 4. Get the order

A GET request has no body. The token is then the hash of your API secret alone. In the command, replace `5624967` with your `OrderId`.

```bash
TOKEN=$(printf '%s' "$QLIRO_API_SECRET" | openssl dgst -sha256 -binary | base64)
curl -s "https://pago.qit.nu/checkout/merchantapi/orders/5624967" \
  -H "Authorization: Qliro $TOKEN"
```

The answer contains the order and the HTML snippet that loads the checkout. The example shows some of the properties.

```json
{
  "OrderHtmlSnippet": "<script type=\"text/javascript\">...</script>",
  "OrderId": 5624967,
  "MerchantReference": "Order-1001",
  "TotalPrice": 375.55,
  "Currency": "SEK",
  "Country": "SE",
  "Language": "sv-se",
  "CustomerCheckoutStatus": "InProcess"
}
```

## 5. Load the checkout

`OrderHtmlSnippet` is a JSON string. To decode it, add `| jq -r '.OrderHtmlSnippet'` to the end of the curl command in step 4. Put the decoded snippet in the HTML of a page on your web server. Open the page in a browser. The snippet renders the checkout in an iframe.

For the iframe sizes and the `onCheckoutLoaded` listener, see [Load checkout](https://developers.qliro.com/qliro-checkout/get-started/load-checkout).

## 6. Complete a test purchase

In the checkout, use a [test customer](https://developers.qliro.com/onboard-with-partners/test-and-go-live#test-customer-data) and a [test card](https://developers.qliro.com/onboard-with-partners/test-and-go-live#test-payment-data).

When the purchase completes, Qliro does two things:

* It redirects the customer to your `MerchantConfirmationUrl`.
* It posts a `CustomerCheckoutStatus` notification to your `MerchantCheckoutStatusPushUrl`.

<Cards>
<Card title="Notifications" href="/qliro-checkout/get-started/notifications-checkout">
Receive the notifications and send the response that Qliro expects
</Card>

<Card title="Render thank you page" href="/qliro-checkout/get-started/render-thank-you-page">
Show the thank you page after the purchase
</Card>

<Card title="Order management" href="/qliro-checkout/order-management">
Capture, cancel and return the order
</Card>
</Cards>