Show purchase 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_urls.confirmation property you used when you created the checkout order.

For instance with these merchant urls:

$merchantUrls = [
    'terms' => 'http://toc',
    'checkout' => 'http://checkout?klarna_order_id={checkout.order.id}',
    'confirmation' => 'http://confirmation?klarna_order_id={checkout.order.id}',
    'push' => 'http://push?klarna_order_id={checkout.order.id}'
];
final MerchantUrls urls = new MerchantUrls()
{
    {
        setTerms(
            "http://toc");
        setCheckout(
            "http://checkout?klarna_order_id={checkout.order.id}");
        setConfirmation(
            "http://confirmation?klarna_order_id={checkout.order.id}");
        setPush(
            "http://push?klarna_order_id={checkout.order.id}");
    }
};
MerchantUrls merchantUrls = new MerchantUrls
{
    Terms = new System.Uri(
        "http://toc"),
    Checkout = new System.Uri(
        "http://checkout?klarna_order_id={checkout.order.id}"),
    Confirmation = new System.Uri(
        "http://confirmation?klarna_order_id={checkout.order.id}"),
    Push = new System.Uri(
        "http://push?klarna_order_id={checkout.order.id}")
};

the users would be redirected to: http://confirmation?klarna_order_id=12345

1. Retrieve the checkout order

You should now use the checkout order URI found in the query parameter klarna_order_id to fetch the order from Klarna

$merchantId = 0;
$sharedSecret = 'sharedSecret';
$orderId = '12345';

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

$checkout = new \Klarna\Rest\Checkout\Order($connector, $orderId);

$checkout->fetch();
Client client = DefaultClient.newInstance(
    "merchantId", 
    "sharedSecret", 
    Client.EU_TEST_BASE_URL)

CheckoutOrder checkout = client.newCheckoutOrder("12345");
CheckoutOrderData orderData = checkout.fetch();
IConnector connector = ConnectorFactory.Create(
    "merchantId", 
    "sharedSecret", 
    Client.EuTestBaseUrl);

Client client = new Client(connector);

ICheckoutOrder checkout = client.NewCheckoutOrder("123456");
CheckoutOrderData orderData = checkout.Fetch();

2. Create an order in your system

You should now create the order in your system with the order data that you want to store. The full resource structure of an order can be found in the API Reference.

3. Render the confirmation snippet

The checkout order now contains an updated HTML snippet under the html_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.

echo "<div>{$checkout['html_snippet']}</div>";
out.println(String.format("<div>%s</div>", orderData.getHtmlSnippet()));
Response.Write(string.Format("<div>{0}</div>", orderData.HtmlSnippet));

This is what it should look like:


 

What's next?

You have now integrated Klarna Checkout into your confirmation page. 

The next step is to learn how to confirm purchase.