Notifications and worker
Klarna's status callbacks are set up automatically for every payment. You only create one scheduled task on your hosting. This chapter gives the exact address, header and command.
Klarna callbacks are automatic
The Payment notifications tab is a step-by-step guide for the selected store; it has nothing to save. Klarna does not use a fixed webhook address for this integration:
- Each time a customer starts a payment, the extension gives Klarna a protected callback address valid only for that payment session. You do not register a webhook or paste any address in Klarna Merchant Portal.
- The address contains a secret that only that session knows. Calls without it are rejected.
- When a callback arrives, the shop only stores a note that the payment needs checking and answers Klarna at once.
- The check itself is done by the scheduled worker or by the customer's return to the shop, whichever comes first. Both ask Klarna for the authenticated result before touching the order.
Your shop must accept HTTPS requests from Klarna. Do not block them with a firewall rule, a password on the shop or maintenance mode.
Why the worker is needed
Without the worker, an order is confirmed only when the customer returns from Klarna with the same browser session. The worker covers the rest: a closed tab, a failed return page, a payment accepted after a pending risk decision, a capture made in Klarna Merchant Portal, and abandoned or expired payments whose record has to be closed.
The worker address
The worker is called with an HTTPS POST request. The exact address for the selected store is shown in the Payment notifications tab. Its form depends on your OpenCart version:
| OpenCart | Worker address |
|---|---|
| 1.5.5 to 2.2 | https://www.example.com/index.php?route=payment/klarna_payments_pro/worker&store_id=0 |
| 2.3 and 3.x | https://www.example.com/index.php?route=extension/payment/klarna_payments_pro/worker&store_id=0 |
| 4.0.2 and later | https://www.example.com/index.php?route=extension/devman_klarna_payments_pro/payment/klarna_payments_pro.worker&store_id=0 |
On OpenCart 4.0.0 and 4.0.1 the address has a vertical bar instead of the dot before worker. Always copy the address from the tab.
| Part | Value |
|---|---|
store_id | The OpenCart store to process. 0 is the default store. |
mode | test for Playground or live for production. Add it yourself, for example &mode=live. Without it the worker processes test payments. |
X-Devman-Worker-Key header | The private worker key, 64 characters. It is the same for all stores of the installation. |
The worker answers {"processed":true} when it has run. Each run checks up to five payments of that store and mode, those with a new callback first, and stops after about 25 seconds. Run it every minute.
The key is created when you install the payment method. To see it, click Show private worker key in the Payment notifications tab. Only users with modify permission can see it.
Creating the scheduled task
Create a cron job in your hosting control panel that runs every minute. Keep the key in a small file outside the public web folder.
- Create a file, for example
/home/youraccount/private/klarna-worker.conf, readable only by your hosting user, with this single line:
header = "X-Devman-Worker-Key: PASTE_YOUR_PRIVATE_WORKER_KEY_HERE"- Add the cron job with your own address. This example is for OpenCart 3, default store, production:
* * * * * curl -s -X POST -K /home/youraccount/private/klarna-worker.conf "https://www.example.com/index.php?route=extension/payment/klarna_payments_pro/worker&store_id=0&mode=live" >/dev/null 2>&1If your hosting only accepts one command, the header can go in the command itself:
* * * * * curl -s -X POST -H "X-Devman-Worker-Key: PASTE_YOUR_PRIVATE_WORKER_KEY_HERE" "https://www.example.com/index.php?route=extension/payment/klarna_payments_pro/worker&store_id=0&mode=live" >/dev/null 2>&1Keep the quotation marks around the address: it contains & characters. If your hosting has no cron jobs, ask your provider to run this HTTPS POST every minute. The worker is a task on your hosting account, not a setting in Klarna.
One task per store and mode
Create one task for each store that uses Klarna, changing store_id. Use mode=test while you test and mode=live when you go live. If you keep testing in Playground afterwards, run both.
To check the task, run the command once by hand without >/dev/null 2>&1. The answer must be {"processed":true}. Then do the "recovery without return" test from Quick start and watch the payment change in Payment activity.
Still need help?
Open a support ticket from your account and our team will look at your store with you.