This product, Klarna Payments (kpm) is deprecated. Go to the current version

Check order status

As you saw in the create an order tutorial, Klarna can respond with a pending status. This functionality enables you to check the status of a pending order.

Prerequisites

  • You have created an order
  • The response from Klarna was in status pending

Note: you can simulate this status using the instructions on our testing page.

1. Initialize the Klarna object

Each Klarna library function requires a basic setup of the Klarna object. This configuration specifies how the library communicates with Klarna’s servers.

Follow the code examples below to see how to do this with our different libraries:

1
2
3
4
5
Dim kAPI
Set kAPI = GetKlarna(0, "sharedsecret", "SE", "SV", "SEK")
kAPI.SetPort(HTTPS_PORT) ' or HTTP_PORT
kAPI.SetHost(BETA_HOST) ' or LIVE_HOST
kAPI.SetPClassesStorageUri(Server.MapPath("pclasses.xml"))
1
2
3
4
5
6
7
8
9
10
Configuration configuration = new Configuration(
    Country.Code.SE, Language.Code.SV, Currency.Code.SEK,
    Encoding.Sweden)
{
    Eid = 0,
    Secret = "sharedsecret",
    IsLiveMode = false
};

Api api = new Api(configuration);
1
2
3
4
5
6
7
8
Klarna k = new Klarna(
        0,
        "sharedSecret",
        KlarnaCountry.SE,
        KlarnaCurrency.SEK,
        new JsonStorage("/srv/data/pclasses.json"),
        Klarna.BETA
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use Klarna\XMLRPC\Klarna;
use Klarna\XMLRPC\Country;
use Klarna\XMLRPC\Language;
use Klarna\XMLRPC\Currency;

$k = new Klarna();

$k->config(
    0,              // Merchant ID
    'sharedSecret', // Shared secret
    Country::SE,    // Purchase country
    Language::SV,   // Purchase language
    Currency::SEK,  // Purchase currency
    Klarna::BETA,   // Server
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
config = klarna.Config(
    eid=0,
    secret='sharedSecret',
    country='DE',
    language='DE',
    currency='EUR',
    mode='beta',
    pcstorage='json',
    pcuri='/srv/pclasses.json',
    scheme='https',
    candice=True)

k = klarna.Klarna(config)
k.init()

2. Make the API call to Klarna

You are now ready to make the checkOrderStatus API call to Klarna.

1
2
Dim result
result = kAPI.CheckOrderStatus(rno, Null)
1
2
3
OrderStatus orderStatus = api.CheckOrderStatus(
    "123456", OrderNumberType.InvoiceOrReservation
);
1
Status result = k.checkOrderStatus("123456789");
1
2
$rno = '2347666470';
$status = $k->checkOrderStatus($rno);
1
2
3
result = k.check_order_status("123456789")
# Returns a integer {1,2,3} that can be checked against the
# constants of OrderStatus

3. Process the order based on Klarna’s response

Klarna will respond to the API call using an integer, which means the following:

1 - OK. The order has been accepted and can be shipped.

2 - Pending. Please make the call again on the next interval. The order cannot be shipped.

3 - Denied. The order has been rejected. Please cancel the order in your system.

Note: the interval in which you make the CheckOrderStatus call should not be lower than 4 hours

1
2
3
4
5
6
7
8
9
10
If result = ACCEPTED Then
    ' Status changed, you can now activate your invoice/reservation.
    Response.Write("Accepted")
ElseIf result = DENIED Then
    ' Status changed, it is now denied, proceed accordingly.
    Response.Write("Denied")
Else
    ' Order is still pending, try again later.
    Response.Write("Pending")
End If
1
2
3
4
5
6
7
8
9
10
if (orderStatus == OrderStatus.Accepted)
{
    // Order was Accepted
} else if (orderStatus == OrderStatus.Denied)
{
    // Order was Denied
} else
{
    // Order is still Pending.
}
1
2
3
4
5
6
7
if (result == Status.ACCEPTED) {
    //  Status changed, you can now activate your invoice/reservation.
} else if (result == Status.DENIED) {
    // Status changed, it is now denied, proceed accordingly
} else {
    // Order is still pending. Try again later.
}
1
2
3
4
5
6
7
8
9
use Klarna\XMLRPC\Flags;

if ($result == Flags::ACCEPTED) {
    // Status changed, you can now activate your invoice/reservation.
} else if ($result == Flags::DENIED) {
    // Status changed, it is now denied, proceed accordingly.
} else {
    //Order is still pending, try again later.
}
1
2
3
4
5
6
7
if result == OrderStatus.ACCEPTED:
    print "Accepted"
elif result == OrderStatus.DENIED:
    print "Denied"
else:
    # Still pending
    pass

In case of an error, an exception containing an error code and message will be thrown.