Delivery

The following actions can be taken when the item is being 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

Capture the full amount

Use this call when fulfillment is completed, e.g. physical products are being shipped to the customer.

Use case

You have sent the goods to the consumer and want to capture the amount for the item(s).

 

 

1. Add the order information and make the API call

'captured_amount' must be equal to or less than the order's 'remaining_authorized_amount'.
Shipping address is inherited from the order.

The capture amount can optionally be accompanied by a descriptive text and order lines for the captured items.

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

$info = [
    [
        "shipping_company" => "DHL",
        "shipping_method" => "Home",
        "tracking_uri" => "tracking-uri",
        "tracking_number" => "1234567890",
        "return_tracking_number" => "E-55-KL",
        "return_shipping_company" => "DHL",
        "return_tracking_uri" => "return-tracking-uri"
    ]
];

$data = [
    "captured_amount" => $order['order_amount'],
    "description" => "Shipped part of the order",
    "order_lines" => $order['order_lines'],
    "shipping_info" => $info
]);

$order->createCapture($data);
String merchantId = "0";
String sharedSecret = "sharedSecret";
String orderId = "12345";

Client client = DefaultClient.newInstance(
    merchantId,
    sharedSecret,
    Client.EU_TEST_BASE_URL);

Capture capture = client.newCapture(orderId);
OrderData order = client.newOrder(orderId).fetch();

final List<ShippingInfo> info = new ArrayList<ShippingInfo>()
{
    {
        add(new ShippingInfo()
                .setShippingCompany("DHL")
                .setShippingMethod("Home")
                .setTrackingUri("tracking-uri")
                .setTrackingNumber("1234567890")
                .setReturnTrackingNumber("E-55-KL")
                .setReturnShippingCompany("DHL")
                .setReturnTrackingUri("return-tracking-uri"));
    }
};

CaptureData data = new CaptureData() {
    {
        setCapturedAmount(order.getOrderAmount());
        setDescription("Shipped all of the order");
        setOrderLines(order.getOrderLines());
        setShippingInfo(info);
    }
};

capture.create(data);
const string MerchantId = "0";
const string SharedSecret = "sharedSecret";
string orderId = "12345";

IConnector connector = ConnectorFactory.Create(
    MerchantId,
    SharedSecret,
    Client.EuTestBaseUrl);

Client client = new Client(connector)

IOrder order = client.NewOrder(orderId);
CheckoutOrderData orderData = order.Fetch()
ICapture capture = client.NewCapture(order.Location);

ShippingInfo shippingInfo = new ShippingInfo
{
    ShippingCompany = "DHL",
    ShippingMethod = "Home",
    TrackingUri = new Uri("tracking-uri"),
    TrackingNumber = "1234567890",
    ReturnTrackingNumber = "E-55-KL",
    ReturnShippingCompany = "DHL",
    ReturnTrackingUri = new Uri("return-tracking-uri")
};

CaptureData captureData = new CaptureData()
{
    CapturedAmount = orderData.OrderAmount,
    Description = "Shipped part of the order",
    OrderLines = orderData.OrderLines,
    ShippingInfo = new List<ShippingInfo>() { shippingInfo }
};

capture.Create(captureData);

2. Handle the response from Klarna

Klarna will respond with 201 - Created or an error message

HTTP/1.1 201 Created
Location: http://klarna/orders/{order.id}/captures/{capture.id}

Capture part of the order amount

Use this call when part of the fulfillment is completed, e.g. physical goods are being shipped to the customer.

Use case

You have sent at least part of the order to the consumer and want to capture the amount for the item(s) that have been shipped.

1. Add the order information and make the API call

'captured_amount' must be equal to or less than the order's 'remaining_authorized_amount'.
Shipping address is inherited from the order.

The capture amount can optionally be accompanied by a descriptive text and order lines for the captured items.

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

$lines = [
    [
        "type" => "physical",
        "reference" => "123050",
        "name" => "Tomatoes",
        "quantity" => 2,
        "quantity_unit" => "kg",
        "unit_price" => 600,
        "tax_rate" => 2500,
        "total_amount" => 6000,
        "total_tax_amount" => 1200
    ]
];
$info = [
    [
        "shipping_company" => "DHL",
        "shipping_method" => "Home",
        "tracking_uri" => "tracking-uri",
        "tracking_number" => "1234567890",
        "return_tracking_number" => "E-55-KL",
        "return_shipping_company" => "DHL",
        "return_tracking_uri" => "return-tracking-uri"
    ]
];

$data = [
    "captured_amount" => 1200, // Full amount is 6000
    "description" => "Shipped part of the order",
    "order_lines" => $lines,
    "shipping_info" => $info
];

$order->createCapture($data);
String merchantId = "0";
String sharedSecret = "sharedSecret";
String orderId = "12345";

Client client = DefaultClient.newInstance(
    merchantId,
    sharedSecret,
    Client.EU_TEST_BASE_URL);

Capture capture = client.newCapture(orderId);

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

final List<ShippingInfo> info = new ArrayList<ShippingInfo>()
{
    {
        add(new ShippingInfo()
                .setShippingCompany("DHL")
                .setShippingMethod("Home")
                .setTrackingUri("tracking-uri")
                .setTrackingNumber("1234567890")
                .setReturnTrackingNumber("E-55-KL")
                .setReturnShippingCompany("DHL")
                .setReturnTrackingUri("return-tracking-uri"));
    }
};

CaptureData data = new CaptureData() {
    {
        setCapturedAmount(1200L); //total order amount is 6000L
        setDescription("Shipped part of the order");
        setOrderLines(lines);
        setShippingInfo(info);
    }
};

capture.create(data);
const string MerchantId = "0";
const string SharedSecret = "sharedSecret";
string orderId = "12345";

IConnector connector = ConnectorFactory.Create(
    MerchantId,
    SharedSecret,
    Client.EuTestBaseUrl);

Client client = new Client(connector)

IOrder order = client.NewOrder(orderId);
ICapture capture = client.NewCapture(order.Location);

List<OrderLine> lines = new List<OrderLine>();

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

ShippingInfo shippingInfo = new ShippingInfo
{
    ShippingCompany = "DHL",
    ShippingMethod = "Home",
    TrackingUri = new Uri("tracking-uri"),
    TrackingNumber = "1234567890",
    ReturnTrackingNumber = "E-55-KL",
    ReturnShippingCompany = "DHL",
    ReturnTrackingUri = new Uri("return-tracking-uri")
};

CaptureData captureData = new CaptureData()
{
    CapturedAmount = 1200, //full amount is 6000
    Description = "Shipped part of the order",
    OrderLines = lines,
    ShippingInfo = new List<ShippingInfo>() { shippingInfo }
};

capture.Create(captureData);

2. Handle the response from Klarna

Klarna will respond with 201 - Created or an error message

HTTP/1.1 201 Created
Location: http://klarna/orders/{order.id}/captures/{capture.id}

What's next?

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