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:

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
);
Klarna k = new Klarna(
        0,
        "sharedSecret",
        KlarnaCountry.SE,
        KlarnaCurrency.SEK,
        new JsonStorage("/srv/data/pclasses.json"),
        Klarna.BETA
);
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()
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);
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"))

2. Make the API call to Klarna

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

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

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

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.
}
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.
}
if result == OrderStatus.ACCEPTED:
    print "Accepted"
elif result == OrderStatus.DENIED:
    print "Denied"
else:
    # Still pending
    pass
if (orderStatus == OrderStatus.Accepted)
{
    // Order was Accepted
} else if (orderStatus == OrderStatus.Denied)
{
    // Order was Denied
} else
{
    // Order is still Pending.
}
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

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