2

I'm building a kind of sandbox integration of Klarna Payments (to get it working in principle and implement the logic later into a real shop). The first step described in the docu, the session creating, has worked. Now I'm trying to get the Klarna widget displayed.

The example in the documentation shows, how to load one payment method (pay_later / invoice).

Klarna.Payments.load({
    container: '#klarna-payments-container',
    payment_method_category: 'pay_later'
  }, function (res) {
    console.debug(res);
})

I tried the same with pay_now, but it didn't work (Message "Payment method not available" on the page and {show_form: false} in the res object). And actually I want to see a form with three payment methods: pay_now, pay_later, and pay_over_time.

I took a look at the documentation of the load(). My expectation was to find a parameter like payment_method_categories. But the method only has payment_method_category and it needs to be a string...

How to get a defined list of Klarna payment methods available and loaded?

Probably some settings are in the Klarna backend / "control center" (Playground) or an API call for making the methods available are / is needed. If so, what needs to be done and how to do this?

automatix
  • 14,018
  • 26
  • 105
  • 230

1 Answers1

3

The Klarna Payments documentation is a bit confusing or I simply misunderstood it. Anyway, I thought, that the widget provides the (complete) form and that by following its steps I'm going to get the payment form. It's wrong. The widget only displays the block(-s) with the information about the payment method(-s). The actual form (the radio buttons and one or more buttons for the authorize call etc.) a concern of the implementer.

To get multiple defined Klarna payment methods following steps are needed:

1 The methods need to be activated by Klarna for this (test) merchant account.

The available methods are listed in the response of the session initialization call (POST /payments/v1/sessions):

{
    "session_id": "...",
    "client_token": "...",
    "payment_method_categories": [
        {
            "identifier": "direct_bank_transfer",
            ...
        },
        {
            "identifier": "pay_later",
            ...
        },
        {
            "identifier": "pay_over_time",
            ...
        },
        ...
    ]
}

2 Load the single payment blocks into separate HTML containers:

<script>
window.klarnaAsyncCallback = function () {
    Klarna.Payments.init({
        client_token: CLIENT_TOKEN
    });
    Klarna.Payments.load(
        {
            container: '#klarna-payments-container1',
            payment_method_category: 'pay_later'
        },
        function (res) {
            console.debug(res);
        }
    );
    Klarna.Payments.load(
        {
            container: '#klarna-payments-container2',
            payment_method_category: 'pay_over_time'
        },
        function (res) {
            console.debug(res);
        }
    );
    Klarna.Payments.load(
        {
            container: '#klarna-payments-container3',
            payment_method_category: 'direct_bank_transfer'
        },
        function (res) {
            console.debug(res);
        }
    );
};
</script>
<div id="klarna-payments-container1"></div>
<div id="klarna-payments-container2"></div>
<div id="klarna-payments-container3"></div>

The result should be look like this:

enter image description here

That's it. No visible form elements are provided (meaning: it is already the correct result). The implementer is responsible for the form and can now freely create and decorate a custom one.

automatix
  • 14,018
  • 26
  • 105
  • 230
  • Thanks for that information, that helped me well. Can you give me a hint where I can add the payment methods in the playground environment. At "store" I can only choose pay_later and I don't find any possibility to add another payment method... – Der Alex Jan 22 '21 at 12:13
  • 1
    Hi Alex, The methods need to be activated by Klarna for your merchant account. – automatix Jan 22 '21 at 14:01
  • Can someone explain why you have to ask Klarna to activate them? With Klarna Payments I only get pay_later and pay_over_time, but with Klarna Checkout I also get credit card payments and bank transfer using the same Klarna Playground credentials. – iamfredrik Aug 30 '22 at 15:50