Pre-delivery

The following actions can be taken before the item has been shipped from your store.

Prerequisites

  • You have already obtained your API credentials
  • A purchase has been made
  • You have retrieved and acknowledge an order as described on the Confirm purchase page
  • The order has not been captured.

Tip: Additional pre-delivery actions can be found in the Additional actions page.


Update order amount

Update the total order amount of an order, subject to a new consumer credit check.

Use case

The consumer have contacted you to add additional products and you need to update the total order amount.

 

 

1. Update the order information and make the API call

The updated amount can optionally be accompanied by a descriptive text and new order lines. Supplied order lines will replace the existing order lines. If no order lines are supplied in the call, the existing order lines will be deleted.

The updated 'order_amount' must not be negative, nor less than current 'captured_amount'.

Currency is inferred from the original order.

$merchantId = getenv('MERCHANT_ID') ?: '0';
$sharedSecret = getenv('SHARED_SECRET') ?: 'sharedSecret';
$orderId = getenv('ORDER_ID') ?: '12345';

$connector = Klarna\Rest\Transport\Connector::create(
    $merchantId,
    $sharedSecret,
    Klarna\Rest\Transport\ConnectorInterface::EU_TEST_BASE_URL
);

$order = new Klarna\Rest\OrderManagement\Order($connector, $orderId);
$order->updateAuthorization([
    "order_amount" => 6000,
    "description" => "Removed bad bananas",
    "order_lines" => [
        [
            "type" => "physical",
            "reference" => "123050",
            "name" => "Tomatoes",
            "quantity" => 10,
            "quantity_unit" => "kg",
            "unit_price" => 600,
            "tax_rate" => 2500,
            "total_amount" => 6000,
            "total_tax_amount" => 1200
        ]
    ]
]);

Order order = client.newOrder(orderId);
final List<OrderLine> lines = new ArrayList<OrderLine>()
{
    {
        add(new OrderLine()
                .setType("physical")
                .setReference("123050")
                .setName("Tomatoes")
                .setQuantity(10L)
                .setQuantityUnit("kg")
                .setUnitPrice(600L)
                .setTaxRate(2500)
                .setTotalAmount(6000L)
                .setTotalTaxAmount(1200L)
        );
    }
};

UpdateAuthorization data = new UpdateAuthorization()
{
    {
        setOrderAmount(6000L);
        setDescription("Removed bad bananas");
        setOrderLines(lines);
    }
};

order.updateAuthorization(data);
IOrder order = client.NewOrder(orderId);
List<OrderLine> lines = new List<OrderLine>();

lines.Add(new OrderLine()
{
    Type = "physical",
    Reference = "123050",
    Name = "Tomatoes",
    Quantity = 10,
    QuantityUnit = "kg",
    UnitPrice = 600,
    TaxRate = 2500,
    TotalAmount = 6000,
    TotalTaxAmount = 1200
});

UpdateAuthorization updateAuthorization = new UpdateAuthorization()
{
    OrderAmount = 6000,
    Description = "Removed bad bananas",
    OrderLines = lines
};

order.UpdateAuthorization(updateAuthorization);

2. Handle the response from Klarna

Klarna will respond with 204 - The server has fulfilled the request or an error message

HTTP/1.1 204 No Content

Cancel an authorized order

For a cancellation to be successful, there must be no captures on the order.

The authorized amount will be released and no further updates to the order will be allowed.

Use case

The consumer has decided not to proceed with the purchase and wants to cancel the order before shipping the product.

 

 

1. Use the order id and make the API call

$merchantId = getenv('MERCHANT_ID') ?: '0';
$sharedSecret = getenv('SHARED_SECRET') ?: 'sharedSecret';
$orderId = getenv('ORDER_ID') ?: '12345';

$connector = Klarna\Rest\Transport\Connector::create(
    $merchantId,
    $sharedSecret,
    Klarna\Rest\Transport\ConnectorInterface::EU_TEST_BASE_URL
);

$order = new Klarna\Rest\OrderManagement\Order($connector, $orderId);
$order->cancel();
Order order = client.newOrder(orderId);
order.cancel();
IOrder order = client.NewOrder(orderId);
order.Cancel();

2. Handle the response from Klarna

Klarna will respond with 204 - The server has fulfilled the request or an error message

HTTP/1.1 204 No Content

Retrieve an order

Get the current state of an order.

Use case

When you want to view the entire order information and its captures

 

 

1. Use the order id and make the API call

$merchantId = getenv('MERCHANT_ID') ?: '0';
$sharedSecret = getenv('SHARED_SECRET') ?: 'sharedSecret';
$orderId = getenv('ORDER_ID') ?: '12345';

$connector = Klarna\Rest\Transport\Connector::create(
    $merchantId,
    $sharedSecret,
    Klarna\Rest\Transport\ConnectorInterface::EU_TEST_BASE_URL
);

$order = new Klarna\Rest\OrderManagement\Order($connector, $orderId);
$order->fetch();
Order order = client.newOrder(orderId);
OrderData data = order.fetch();
IOrder order = client.NewOrder(orderId);
OrderData orderData = order.Fetch();

2. Handle the response from Klarna

Content-Type: application/json

Klarna will respond with 200 OK and body or an error message

HTTP/1.1 200 OK
Content-Type: application/json

{}

Update billing and/or shipping address

Update billing and/or shipping address for an order, subject to customer credit check.

Use case

The consumer needs to change his/her billing and/or shipping address.

 

 

1. Update the billing and/or shipping information and make the API call

Fields can be updated independently. To clear a field, set its value to "" (empty string). Mandatory fields can not be cleared.

$merchantId = getenv('MERCHANT_ID') ?: '0';
$sharedSecret = getenv('SHARED_SECRET') ?: 'sharedSecret';
$orderId = getenv('ORDER_ID') ?: '12345';

$connector = Klarna\Rest\Transport\Connector::create(
    $merchantId,
    $sharedSecret,
    Klarna\Rest\Transport\ConnectorInterface::EU_TEST_BASE_URL
);

$order = new Klarna\Rest\OrderManagement\Order($connector, $orderId);
$order->updateCustomerDetails([
    "billing_address" => [
        "email" => "user@example.com",
        "phone" => "57-3895734"
    ],
    "shipping_address" => [
        "email" => "user@example.com",
        "phone" => "57-3895734"
    ]
]);
Order order = client.newOrder(orderId);
UpdateCustomerDetails data = new UpdateCustomerDetails() {
    {
        setBillingAddress(
            new Address()
                .setStreetAddress("123 Fake St")
                .setCity("New York")
                .setRegion("NY")
                .setPostalCode("12345")
                .setCountry("US")
        );
        setShippingAddress(
            new Address()
                .setStreetAddress("123 Fake St")
                .setCity("New York")
                .setRegion("NY")
                .setPostalCode("12345")
                .setCountry("US")
        );
    }
};

order.updateCustomerDetails(data);
IOrder order = client.NewOrder(orderId);

UpdateCustomerDetails updateCustomerDetails = new UpdateCustomerDetails()
{
    ShippingAddress = new Address()
    {
        StreetAddress = "123 Fake St",
        City = "New York",
        Region = "NY",
        PostalCode = "12345",
        Country = "US"
    },

    BillingAddress = new Address()
    {
        StreetAddress = "123 Fake St",
        City = "New York",
        Region = "NY",
        PostalCode = "12345",
        Country = "US"
    }
};

order.UpdateCustomerDetails(updateCustomerDetails);

2. Handle the response from Klarna

Klarna will respond with 204 - The server has fulfilled the request or an error message

HTTP/1.1 204 No Content

Update merchant references

Update merchant specific reference information that could be added to an order

Use case

You want to use your own order id in the Klarna order.

 

 

1. Update the merchant references and make the API call

Update one or both merchant references. To clear a reference, set its value to "" (empty string).

$merchantId = getenv('MERCHANT_ID') ?: '0';
$sharedSecret = getenv('SHARED_SECRET') ?: 'sharedSecret';
$orderId = getenv('ORDER_ID') ?: '12345';

$connector = Klarna\Rest\Transport\Connector::create(
    $merchantId,
    $sharedSecret,
    Klarna\Rest\Transport\ConnectorInterface::EU_TEST_BASE_URL
);

$order = new Klarna\Rest\OrderManagement\Order($connector, $orderId);
$order->updateMerchantReferences([
    "merchant_reference1" => "15632423",
    "merchant_reference2" => "special order"
]);
UpdateMerchantReferences data = new UpdateMerchantReferences() {
      {
          setMerchantReference1("15632423");
          setMerchantReference2("Special Order");
      }
};

order.updateMerchantReferences(data);
IOrder order = client.NewOrder(orderId);
UpdateMerchantReferences data = new UpdateMerchantReferences()
{
    MerchantReference1 = "15632423",
    MerchantReference2 = "special order"
};
order.UpdateMerchantReferences(data);

2. Handle the response from Klarna

Klarna will respond with 204 - The server has fulfilled the request or an error message

HTTP/1.1 204 No Content

What's next?

You have now implemented all the features you need to handle your pre-delivery process, you can now continue to implement the delivery calls.