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

Update order

This functionality allows you to update an existing order in Klarna’s system, before it has been activated. If this update increases the total amount of the order, we will run a credit check. An increase in the total amount of the order is not possible for purchases made with credit card and direct banking in Klarna Checkout.

Note: If the order has been activated, you will need to process a refund .

Use case

A consumer has placed an order. Before the order has been shipped, the consumer contacts your customer care center to add another item to the order, or change a mistake in the contact information.

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
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

The update call allows you to change different aspects of an order, such as consumer contact information, your internal order ID and cart content.

Note: If you change the cart content, the new cart content provided will replace the existing cart content for this order on Klarna’s system.

This is an example of how to update the cart content:

[example:_code/xmlrpc_addArticle]

1
2
3
4
5
6
7
8
9
10
11
12
Dim flags
flags = INC_VAT + IS_HANDLING ' Handling fee, price including VAT.

' Here we add a normal product to our goods list.
' -Quantity
' -Article number
' -Article name/title
' -Price
' -VAT, 25% VAT
' -Discount
' -Flags, price including VAT
Call kAPI.AddArticle(4, "MG200MMS", "Matrox G200 MMS", 299.99, 25, 0, flags)
1
2
3
4
5
6
7
8
9
api.AddArticle(
    1,                                      // Quantity
    string.Empty,                           // Article Number
    "Handling fee",                         // Product Name
    10.0,                                   // Price
    25.0,                                   // VAT
    0.0,                                    // Discount
    GoodsFlags.Handling | GoodsFlags.IncVAT // Flags (Bitwise OR:ed)
);
1
2
3
4
5
6
7
8
9
10
int flags = Goods.IS_HANDLING.toInt() | Goods.INC_VAT.toInt();
k.addArticle(
        1,              // Quantity
        "HANDLING",     // SKU / Article Number
        "Invoice Fee",  // Title
        15d,            // Price
        25d,            // VAT
        0d,             // Discount
        flags           // Flags
);
1
2
3
4
5
6
7
8
9
10
$flags = Flags::INC_VAT | Flags::IS_HANDLING;
$k->addArticle(
    4,              // Quantity
    "HANDLING",     // Article number
    "Handling fee", // Article name/title
    50.99,          // Price
    25,             // 25% VAT
    0,              // Discount
    $flags          // Flags
);
1
2
3
4
5
6
7
8
k.add_article(
    qty=1,
    title="Handling fee",
    price=1.5,
    vat=19,
    discount=0,
    flags=GoodsIs.INC_VAT | GoodsIs.HANDLING
)

This is an example of how to update consumer contact information:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Dim address
Set address = new KlarnaAddr

address.setEmail("always_accepted@klarna.se")
address.setTelno("")
address.setCellno("0765260000")
address.setFirstName("Testperson-se")
address.setLastName("Approved")
address.setCompanyName("")
address.setCareof("")
address.setStreet("Stårgatan 1")
address.setZipCode("12345")
address.setCountry(COUNTRY_SE)
address.setCity("Ankeborg")
address.setHouseNumber("") ' House number (AT/DE/NL only)
address.setHouseExt("")    ' House extension (NL only)

Call kAPI.SetAddress(IS_BILLING, address)
Call kAPI.SetAddress(IS_SHIPPING, address)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Address address = new Address()
{
  Email = "pending_approved@klarna.se",
  PhoneNumber = string.Empty,
  CellPhoneNumber = "0765260000",
  FirstName = "Testperson-se",
  LastName = "Approved",
  Street = "Stårgatan 1",
  CareOf = string.Empty,
  ZipCode = "12345",
  City = "Ankeborg",
  Country = Country.Code.SE,
  HouseNumber = string.Empty,     // Needed for AT, DE and NL
  HouseExtension = string.Empty,  // Needed for NL
  CompanyName = string.Empty
};

api.ShippingAddress = address;
api.BillingAddress = address;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
KlarnaAddr address = new KlarnaAddr(
      "always_accepted@klarna.com",   // Email address
      "",                             // Landline phone
      "4676520000",                   // Mobile number
      "Testperson-se",                // First (given) name
      "Approved",                     // Last (family) name
      "",                             // Care of ( c/o )
      "Stårgatan 1",                  // Street
      "12345",                        // Zip code
      "Ankeborg",                     // City
      KlarnaCountry.SE,               // KlarnaCountry constant
      null,                           // House Number (DE/AT/NL only)
      null                            // House Extension (NL only)
);

k.setAddress(Address.IS_BILLING, address);
k.setAddress(Address.IS_SHIPPING, address);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use Klarna\XMLRPC\Address;
use Klarna\XMLRPC\Country;
use Klarna\XMLRPC\Flags;

$addr = new Address(
    'always_approved@klarna.com', // Email address
    '',                           // Telephone number, only one phone number is needed
    '0762560000',                 // Cell phone number
    'Testperson-se',              // First name (given name)
    'Approved',                   // Last name (family name)
    '',                           // No care of, C/O
    'Stårgatan 1',                // Street address
    '12345',                      // Zip code
    'Ankeborg',                   // City
    Country::SE,                  // Country
    null,                         // House number (AT/DE/NL only)
    null                          // House extension (NL only)
);

$k->setAddress(Flags::IS_BILLING, $addr);
$k->setAddress(Flags::IS_SHIPPING, $addr);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
addr = klarna.Address(
    email='always_accepted@klarna.com',
    telno='',
    cellno='015 2211 3356',
    fname='Testperson-de',
    lname='Approved',
    careof='',
    street='Hellersbergstraße',
    zip='14601',
    city='Neuss',
    country='DE',
    house_number='14',     # For DE, AT and NL we need to specify house_number.
    house_extension=None)  # Only required for NL.

k.shipping = addr
k.billing = addr

and here you can see how to attach your internal order ID to this order:

1
2
3
4
5
' Set store specific information so you can e.g. search and associate invoices with order numbers.
' -Order id 1, maybe the estore's order number/id?
' -Order id 2, could be an order number from another system?
' -User, Username, email or identifier for the user?
Call kAPI.SetEstoreInfo("175012", "1999110234", "")
1
2
api.OrderId1 = "order_id";
// Use api.OrderId2 to set order id 2
1
2
3
4
5
//Set store specific information so you can e.g. search and associate invoices with order numbers.
  k.setEstoreInfo(
      "134567", // Order ID to attach to the order.
      "" // Second Order ID to attach.
  ); 
1
2
3
4
5
6
7
// Set store specific information so you can e.g. search and associate invoices
// with order numbers.
$k->setEstoreInfo(
    '175012',       // Order ID 1
    '1999110234',   // Order ID 2
    ''              // Optional username, email or identifier
);
1
2
3
4
5
6
# Set store specific information so you can e.g. search and associate invoices
# with order numbers.
k.set_estore_info(
    orderid1="1011001",
    orderid2="0100110"
)

All that is left to do is call Klarna with the requested updates.

1
2
3
4
' Transmit all the specified data.
' -reservationNumber, Reservation number.
' -clear, Clears set data after the call has been successfully made.
Call kAPI.Update("123456", True)
1
api.Update("987654321");
1
k.update("123456");
1
$k->update('123456');
1
k.update("123456789")

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

3. Update the order in your system

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