This is the library reference for the Klarna payments JavaScript SDK. Here you can find a description of the different methods, their required parameters, and their returns.
This method initializes the Klarna payments library. It is mandatory and expects the client_token received when [ initiating a payment].
For more information about initializing the JavaScript SDK, see the check out section.
The container to render the application. It should be an HTML element or a valid CSS selector.
options.preferred_payment_method (String)
The payment method to be pre-selected, if possible.
options.payment_method_category (String)
The category of payment methods to be loaded. This value is used later to refer to the widget when calling authorize(). Using payment_method_category lets you load one payment method per widget. To load multiple payment methods, use the payment_method_categories property instead.
options.payment_method_categories (Array)
The categories of payment methods to be loaded. Use this property instead of payment_method_category to load multiple payment methods. When using the payment_method_categories array, include an additional string, instance_id, for each container element.
data (Object) An optional object with data to update on the session.
callback (load~callback) A function that will be called when the pre-assessment is completed.
If you don't specify any payment methods categories in the load() call, the payment methods loaded in the widget will correspond to those returned in the response to the initiate a payment session request.
This method only applies to the US market and is only relevant if you have a multi-step checkout with an order review page.
If your checkout enables the customer to review the order after the payment step, you can also share in this review page the payment method your customer selected previously. For this, Klarna offers a payment review widget.
Here's an example of the loadPaymentReview() call:
JAVASCRIPT
1
2
3
4
5
6
7
8
9
10
try {
Klarna.Payments.init({ client_token: '...' })
Klarna.Payments.loadPaymentReview({
container: '#klarna-payments-container'
}, function (res) { // loadPaymentReview~callback// ...
})
} catch (e) {
// Handle error. The loadPaymentReview~callback will have been called// with "{ show_form: false }" at this point.
An optional flag to turn off auto-finalization for the direct bank transfer payment method.
options.payment_method_category (String)
The payment method category that was provided in the previous load()load() call. If you don't provide this property in the authorize() call, but provided it in the corresponding load() call, the authorization will fail.
options.payment_method_categories (Array)
The array of payment method categories that was provided in the previous load()load() call. When using the payment_method_categories array, include an additional string, instance_id, for each container element. If you don't provide this property in the authorize() call, but provided it in the corresponding load() call, the authorization will fail.
data (Object) - An optional object with data to update on the session.
callback (authorize~callback) - A function to be called when the authorization is completed.
Reauthorize currently also includes { show_form: true/false } in the response. This is deprecated. Instead, only an { approved: true, authorization_token: string } response is correct for any action for reauthorizing.
You need to get a reauthorization if your customer made a change in the order. This applies to multi-step checkouts, where you offer a review page after selecting the payment method.
The authorization_token you received originally is only valid for that specific state of the order. If you attempt to place an order without doing a reauthorize, it will fail.
If the payment method widget is still visible, use a regular authorize() call instead.
We suggest you trigger reauthorize once the customer clicks to complete the order. As with authorize(), you can provide an optional update object including all order details. It is also possible to start with a server-side session update per REST API, followed by an empty client-side call to reauthorize. The reauthorize call may trigger your customer confirmation on changed financing details. The integration should wait for the callback function.
If it happens on a different page than where you originally ran init(), you need to initialize the SDK before doing reauthorize.
var theEventHandler = function () { ... }
Klarna.Payments.on('heightChanged', theEventHandler)
// unregister this specific listener for heightChanged
Klarna.Payments.off('heightChanged', theEventHandler)
// unregister _all_ listeners for heightChanged
Klarna.Payments.off('heightChanged')