This product, Klarna Checkout (v2) is deprecated. Go to the current version

Cancel order

This tutorial will show you how to cancel an order you have created with Klarna.

Note: This flow is is an order cancellation, and not an order refund. This functionality can only be used for orders which have not been activated yet.

Use case

A consumer contacts your customer care and asks to cancel an order, or you realized that the item that was orderered went out of stock and cannot be shipped.

Prerequisites

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
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()
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);

2. Make the API call

The cancelOrder call requires you to include the reservation number. Once the data is set, initiate the API call to Klarna:

1
k.cancelReservation("123456789");
1
$k->cancelReservation('2347667190');
1
k.cancel_reservation("123456789")
1
Call kAPI.CancelReservation("123456")
1
2
string reservationNumber = "123456";
Boolean canceled = api.CancelReservation(reservationNumber);

The XML-RPC will respond with “ok” as a string, however our libraries will translate this into a boolean return value. In case of an error, an exception containing an error code and message will be thrown.

3. Cancel the order in your system

After receiving the response from Klarna, cancel the order in your system.