Create an order

This function will allow you to reserve funds with Klarna for a consumer. When this call is executed, Klarna will run fraud and credit check on the consumer and tell you if the purchase is approved. Once the purchase is approved, funds will be captured.

Use case

A consumer continues to the checkout, chooses Klarna as a payment method and clicks “buy”.


  • You should have already obtained your API credentials.
  • You should have initialized the Klarna object

Add call data

The reserveAmount call, which is used to create an order, requires the mandatory and optional data listed below:

1. Add cart items

Klarna requires the list of cart items that the consumer purchases in order to approve the purchase. This is facilitated by a helper function within the Klarna library.

use Klarna\XMLRPC\Flags;

$flags = Flags::INC_VAT | Flags::IS_HANDLING;
    4,              // Quantity
    "HANDLING",     // Article number
    "Handling fee", // Article name/title
    50.99,          // Price
    25,             // 25% VAT
    0,              // Discount
    $flags          // Flags
int flags = Goods.IS_HANDLING.toInt() | Goods.INC_VAT.toInt();
    1,              // Quantity
    "HANDLING",     // SKU / Article Number
    "Invoice Fee",  // Title
    15d,            // Price
    25d,            // VAT
    0d,             // Discount
    flags           // Flags
    title="Handling fee",
    flags=GoodsIs.INC_VAT | GoodsIs.HANDLING)
    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)
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)

2. Add Consumer Information

Klarna requires the consumer information in order to approve the purchase. This is done by a helper function in the library.

use Klarna\XMLRPC\Address;
use Klarna\XMLRPC\Country;
use Klarna\XMLRPC\Flags;

$addr = new Address(
    '', // 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
    'Storgatan 1',                // Street address
    '12345',                      // Zip code
    'Ankeborg',                   // City
    Country::SE,                  // Country
    null,                         // House number (DE/NL only)
    null                          // House extension (NL only)

$k->setAddress(Flags::IS_BILLING, $addr);
$k->setAddress(Flags::IS_SHIPPING, $addr);
KlarnaAddr address = new KlarnaAddr(
      "",   // 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/NL only)
      null                            // House Extension (NL only)

k.setAddress(Address.IS_BILLING, address);
k.setAddress(Address.IS_SHIPPING, address);
addr = klarna.Address(
    cellno='015 2211 3356',
    house_number='14',     # For DE and NL we need to specify house_number.
    house_extension=None)  # Only required for NL.

k.shipping = addr
k.billing = addr
Address address = new Address()
   Email = "",
   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 DE and NL
   HouseExtension = string.Empty,  // Needed for NL
   CompanyName = string.Empty

api.ShippingAddress = address;
api.BillingAddress = address;
Dim address
Set address = new KlarnaAddr

address.setStreet("Stårgatan 1")
address.setHouseNumber("") ' House number (DE/NL only)
address.setHouseExt("")    ' House extension (NL only)

Call kAPI.SetAddress(IS_BILLING, address)
Call kAPI.SetAddress(IS_SHIPPING, address)

3. Add optional data

As part of the reserveAmount call, you may provide Klarna with additional optional data such as travel purchases related information or shipment and tracking information. All libraries provide helper methods to facilitate this. Please contact us if you require this functionality. 

Make the API call

Once all the data is set, simply initiate the API call to Klarna.

use Klarna\XMLRPC\Flags;
use Klarna\XMLRPC\PClass;

$result = $k->reserveAmount(
    '4103219202', // PNO (Date of birth for AT/DE/NL)
    null, // KlarnaFlags::MALE, KlarnaFlags::FEMALE (AT/DE/NL only)
    -1,   // Automatically calculate and reserve the cart total amount
// Client IP must be set

String[] result = k.reserveAmount(
        null,   // Gender is only needed for DE, AT, and NL
        -1,     // Use cart value to calculate amount to reserve.
## Set customer IP
k.clientip = ''

(reservation_number, order_status) = k.reserve_amount(
// It's important to set the end customers IP address
api.ClientIp = "";

ReservationResponse response = api.ReserveAmount(
    "410321-9202",  // PNO or date of birth
    null,           // Gender. Not needed for SE/NO/DK/FI.
    null,           // Amount, Null to calculate from cart.
    PClass.Invoice, // PClass ID
    true            // Clear reservation data after sending the call.
' Transmit all the specified data
' -pno, Date of birth for DE.
' -gender, The customer is a male.
' -amount, -1 will calculate the amount using the internal goods list.
' -flags, No specific behaviour like RETURN_OCR or TEST_MODE.
' -pclass, -1, notes that this is an invoice purchase, for part payment purchase you will have a pclass object on which you use getId().
' -encoding, null to automatically use it for DE.
Dim result
result = kAPI.ReserveAmount("410321-9202", Null, -1, NO_FLAG, PCLASS_INVOICE, null, true)

Klarna will respond with an array, containing two variables: rno - which represents the reservation number. This number will be used to Activate the reservation. InvoiceStatus - this represents the status of the invoice and can have 2 values:

1: this response means that the order is approved and can be activated

2: this response means that the order is in pending status, and cannot be activated yet (don't worry, you’ll learn how to check the status in the order management section).

    "123456789", 2
["123456789", "2"]
['4150580', 1]
new ReservationResponse() {
    ReservationNumber = "123",
    OrderStatus = OrderStatus.Accepted
Array("123456789", 2)

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



You have placed an order with Klarna. In order to continue towards your first live purchase, here are a few sections to check out as the next step