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

Show confirmation

This tutorial will cover how to retrieve a checkout order and render the confirmation HTML snippet on your confirmation page. Once the consumer has completed the purchase they will be redirected to the confirmation page as specified by the merchant.confirmation_uri property.

The order status changes to checkout_complete before the consumer is redirected.

Use case

A consumer has completed a purchase and you want to show them a confirmation page.

Prerequisites

1. Retrieve the checkout order

Use the checkout order ID stored in the session to fetch the order from Klarna.

1
2
3
4
5
6
7
8
9
10
11
IConnector connector = Connector.create(
        "sharedSecret", IConnector.TEST_BASE_URL);

// This is just a placeholder for the example.
// For example in jsp you could do
// String orderID = (String) request.getParameter("klarna_order_id");
String orderID = "12345";

Order order = new Order(connector, orderID);

order.fetch();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$connector = Klarna_Checkout_Connector::create(
  $sharedSecret,
  Klarna_Checkout_Connector::BASE_TEST_URL
);

$order = new Klarna_Checkout_Order($connector, $orderID);
try {
  $order->fetch();
  var_dump($order);
} catch (Klarna_Checkout_ApiErrorException $e) {
  var_dump($e->getMessage());
  var_dump($e->getPayload());
  die;
}
1
2
3
4
5
6
7
8
9
10
# Instance of the HTTP library that is being used in the server
request = {}

order_id = request['klarna_order_id']

connector = klarnacheckout.create_connector('shared_secret',
                                            klarnacheckout.BASE_TEST_URL)

order = klarnacheckout.Order(connector, order_id)
order.fetch()
1
2
3
4
5
6
7
8
9
10
11
' Create connector
Dim connector : Set connector = CreateConnector("sharedSecret")
connector.SetBaseUri KCO_TEST_BASE_URI

' Retrieve order id from query string.
Dim orderID : orderID = Request.QueryString("klarna_order_id")

Dim order : Set order = CreateOrder(connector)
order.ID orderID

order.Fetch
1
2
3
4
5
6
7
8
9
var connector = Connector.Create("sharedSecret", Connector.TestBaseUri);

// Retrieve order id from query string.
// var orderId = Request.QueryString["klarna_order_id"] as string;
var orderId = "1245";

var order = new Order(connector, orderId);

order.Fetch();

2. Render the confirmation snippet

The checkout order now contains an updated HTML snippet under the gui.snippet property. You should extract the HTML snippet and display it on your confirmation page.

Note: You should remove any browser session references to the checkout order after you have rendered the confirmation snippet.

1
2
3
4
5
6
7
8
9
Map<String, Object> gui = (Map<String, Object>) order.get("gui");

String snippet = gui.get("snippet").toString();

// Output the snippet to the customer.
System.out.println(String.format("<div>%s</div>", snippet));

// Clear session object from klarna_checkout data.
// session.removeAttribute("klarna_order_id");
1
2
3
4
5
$snippet = $order['gui']['snippet'];

echo "<div>{$snippet}</div>";

unset($_SESSION['klarna_checkout']);
1
2
3
print "<div>%s</div>" % (order["gui"]["snippet"])

del session['klarna_order_id']
1
2
3
4
5
6
7
Dim resourceData : Set resourceData = order.Marshal()

Dim snippet : snippet = resourceData.gui.snippet

Response.Write("<div>" & snippet & "</div>")

Session("klarna_order_id") = ""
1
2
3
4
5
6
7
8
var gui = order.GetValue("gui") as JObject;
var snippet = gui["snippet"];


Response.Write(string.Format("<div>{0}</div>", snippet));

// Clear session object.
// session["klarna_order_id"] = null;

This is what it should look like:

This is what it should look like:

This is what it should look like:

This is what it should look like:

This is what it should look like:

This is what it should look like:

This is what it should look like:

This is what it should look like:

Full code example

The complete code example used for rendering the confirmation snippet can be found in the example section of our client libraries .

What’s next?

You have now integrated Klarna Checkout into your confirmation page.

The next step is to learn how to confirm purchase .