First order in the test environment
Create a test order, get the checkout snippet and complete a test purchase.
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.
curl,opensslandbase64in 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.
{
"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
}
]
}MerchantReferenceis 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 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.
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)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.
For the same steps in other languages, see Authorization.
3. Create the order
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.
{
"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 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.
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.
{
"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.
6. Complete a test purchase
In the checkout, use a test customer and a test card.
When the purchase completes, Qliro does two things:
- It redirects the customer to your
MerchantConfirmationUrl. - It posts a
CustomerCheckoutStatusnotification to yourMerchantCheckoutStatusPushUrl.