How to integrate Instant Shopping into a product page within your domain
Instant shopping is deprecated. Use Express button instead.
You complete this step leveraging the Instant Shopping Button Keys API from your server-side
As a first step you need to obtain a Button key which you can reuse for displaying Instant Shopping buttons in multiple product pages. This key is used to identify you as a merchant and also to link to some necessary configuration options.
Since this key can be reused for displaying buttons in multiple pages, it is advised that you generate it once and then store it somewhere within your system.
To obtain a key you can use the Instant Shopping Button Keys Service. An example of a request to this service is given below. Note that you need to use your API credentials to authenticate.
You can include more setup options here, e.g. options, merchant_data, merchant_reference, etc., as shown in the API documentation.
The minimum information needed to setup a Key is the URL of an endpoint where the Instant Shopping Button’s server-side will ping you when an Order is authorized.
Read about Klarna’s API URLs to know the base URL, and about Authentication to know how to authenticate when calling our REST API. More detailed documentation on the Instant Shopping orders API is available in the API documentation.
Upon success the response of this service will provide you the button key.
You complete this step from your client-side
After successfully completing this part you should see the Instant Shopping Button like in the image below:
You will need to make sure that the Instant Shopping Button Javascript SDK is available on the page you want to display the Instant Shopping Button.
To do this add the following script tag as soon as possible in the page (e.g. <head>).
At this step you decide where you want to place the Instant Shopping button within the page by positioning the HTML container element.
It is important to add a data attribute named data-instance-id to this element, which will uniquely identify this button. Note that you will refer to the value of this attribute when you use the JavaScript API and need to provide the setup.instance_id option. This is particularly necessary if you want to show multiple buttons on the same page. In that case each data-instance-id should be different and unique for this page.
You will now need to provide all the information necessary to support the purchase flow. This information refers to the product(s) being sold, relevant shipping options, locale, currency, etc.
Note that you will use the button key created from the previous step.
Below you see an example of the configuration options that are necessary for the consumer flow. Please note that the order_amount and order_tax_amount will be calculated by the service.
Consult our Javascript Docs for more information.
The klarnaAsyncCallback is executed as soon as the Instant Shopping Javascript SDK is ready.
You should define this function before the script tag for fetching lib.js (see 2.a) and as early as possible in the page, e.g. head.
If you would like for a user to be presented with product specification options (examples include choices for size, color, etc.), use theitemsobject array instead of theorder_linesobject array. If you use both, Instant Shopping will default to using theorder_linesobject array.
When the JavaScript SDK has processed the load call, the provided callback will be invoked. The callback argument will be an object containing the following properties:
Below you can read in details the cases you need to handle:
If show_button: true then the Instant Shopping Button is offered and rendered inside the <klarna-instant-shopping> container.
If show_button: false and there is an error object available, then it is advised to consult the errors and investigate if there is something you can do with calling the load to recover from this state.
If show_button: false then the button is not offered.
In case you have selectors in the product page with which customers can change between product variations, you will need to keep updating Instant Shopping after it has been loaded. For example, the customer has chosen a different color or size for the product, or some shipping options have become available, etc. In such cases you can use our Javascript SDK update function to re-configure the Instant Shopping with the new options.
Example
As with the load call, when the JavaScript SDK has processed the update call, the provided callback will be invoked. The callback argument will be an object containing the following properties:
You complete this step leveraging the Instant Shopping Button Keys API from your server-side
When the consumer has chosen to finalize the purchase, our server-side will ping you at the merchant_urls.place_order, and prompt you to place the order for a specific authorization_token. Remember that the URL for this endpoint was defined in the first step when you created this button key.
You will place the order through our REST API, and will be notified immediately about the successful or failed order placement. So you are able at this point already to create the order within your system.
You can choose to deny the purchase and in this case provide a deny reason and/or a URL to redirect the consumer to.
Note:Read about Klarna’s API URLs to know the base URL, and about Authentication to know how to authenticate when calling our REST API. More detailed documentation on the Instant Shopping orders API is available in the API documentation.
During this request we make available to you both the authorization_token to use next for placing the order, but also the details of the authorized order. Below you see an example of how the Request Body looks.
The response from the place order request is not important for Klarna Instant Shopping to progress the purchase flow.
Instead you should proceed with all validations (stock, shipping capabilities, prices, etc.) on your side. Once those are done, approve or deny the order following the request guidelines below.
If you need to deny the purchase you need to perform a DELETE call though our API and provide some information in the request body. Note that you need to use your API credentials to authenticate.
Below you may find examples of how deny requests may look:
1. Deny order request with code:
2. Deny order request with predefined code:
3. Deny order request with own code and message:
You can specify a deny_redirect_url only, or a deny_code and deny_message.
The acceptable values for deny_code are:
The successful response look like below:
If you accept the order, then you need to place the order with our REST API. You do so by performing an HTTP POST in our API for the specific authorization_token and passing to the request body the complete Order. Note that you need to use your API credentials to authenticate.
Place order request
This is an example of how the Request could look like. Note that potential shipping fees are included in the order_lines object.
The response of the order placement endpoint may be success or failure.
Instead of immediately accepting the order, it may happen that Klarna flags this transaction for additional review. This is indicated if the fraud_status is PENDING. An order marked as PENDING is subject to manual review which may result in getting rejected. Therefore we advise that you handle those orders carefully and mark them as pending within your internal systems too. Read more about what to do next in our section about pending orders. When it comes to the Instant Shopping flow, the consumer will have been informed of a successful purchase even in this case. This means that you will need to contact them only if the order fails to go through.
Other possible error statuses are:
You can use the authorization_token to fetch the complete order authorization information before placing the order. Note that you need to use your API credentials to authenticate.
Request to GET Authorized Order
When the purchase is completed the consumer is notified via suitable messaging within the Instant Shopping. There, we show a call-to-action button for directing the consumer to a new location. This location is the post-purchase page you have supplied through the merchant_urls.confirmation when setting up the Instant Shopping Button.
The URL of this page has already been defined either in the first step when you created this button key or in the step when you approved the order. If you choose to do this when you approve the order, then you can customize and personalize what this page will be for the specific consumer and purchase.
Below you see how a successful purchase looks like in the Instant Shopping flow:
For instance with these merchant urls:
the consumer after closing our dialog will land to:http://example.com/upsell-similar-product.php
After the order is created, you can manage the order either manually via our Merchant Portal or through our Order Management API.