Skip to content

Getting started with Payway and Klarna payments

Target audience: Developers, Stakeholders

Getting started checklist

  1. Contact Klarna for playground credentials.
  2. Setup payment provider configuration(s) based on given credentials.
  3. Follow the implementation guide.
  4. Test the implementation with Adeprimo and Klarna in a testing environment.

Klarna Credentials

  • API Credentials can be found in the Klarna Portal.
  • In Payway you set up Klarna Payments for one or more titles. That means you can have one or more Klarna Payments configurations.
  • For test/staging environment you'll probably only need one set of Klarna credentials.
  • For production depending on how you want to split your orders/economy you may want separate credentials for each Payway title.

The basic implementation

To place your first Klarna Payments order with Payway, a purchase session will have to be established.

Create session

To establish your first session, the following parameters are required:

Parameter Description Example Value
code The easiest way is to navigate to PAP -> Packages & Campaigns, and locate the product that you wish to sell.
Once located, you will find the product code both in the table view as well as in the edit view.
If you wish to go via our API, you can read more here.
adeprimo_digital
period_id You can find the associated period ids for a given product code using our API here. 585a4768edce2c5e6f000001
period_type If the subscription is recurring or limited limited / recurring
confirmation_url URL to your confirmation page for the customer https://adeprimo.se/receipt

While more parameters can be defined, this is all you need to know for now.

After having defined these parameters, you will want to perform the following HTTP request, including the payload above:

curl --request POST \
  --url https://payway-api.stage.adeprimo.se/external/api/v1/klarna_payments/create_session \
  --header 'accept: application/json' \
  --header 'authorization: Bearer token' \
  --header 'content-type: application/json' \
  --data '{
            "code": "",
            "period_id": "",
            "period_type": "",
            "confirmation_url": ""
          }'

Now that you have a session, you can use it to start the purchase and be that much closer to a finalized order!

Once you have the klarna_client_token from the session response you are ready to build the Klarna Payment Widget on your purchase page. More details on how you do this can be found in the Klarna documentation. The Example app also contains a working implementation of the Klarna Payment Widget.

Authorize purchase against Klarna

When the user presses the buy button you must, using javascript, perform an authorized call to Klarna. You will in return get a authorization_token.

Example without error handling:

var btn = document.getElementById("approve_purchase");
var klarna_authorization_token_input = document.getElementById('klarna_authorization_token');
var form = document.getElementById('authorize_form');
var payment_method_category = 'direct_debit/pay_now or any of the payment methods available to you in your Klarna payments setup.'

btn.addEventListener("click", function() {
Klarna.Payments.authorize({
    payment_method_category: payment_method_category
},{}, function (response) {
    if(response.approved) {
        klarna_authorization_token_input.value = response.authorization_token;
        form.submit(); //post the authorization token to your backend
    }
});

Place order

To create your first order with Payway, the following parameters are required:

Parameter Description Example Value
klarna_authorization_token The authorization token acquired when creating the session klarna_authorization_token
klarna_payments_session_id The session id acquired when creating the sesssion klarna_payments_session_id
browser_ip The IP address of the customer 127.0.0.1
browser_language The browser language used by the customer sv-SE
browser_user_agent The customer's user agent Mozilla/5.0 (Windows NT 10.0; Win64; x64)

While more parameters can be defined, this is all you need to know for now.

After having defined these parameters, you will want to perform the following HTTP request, including the payload above:

curl --request POST \
  --url https://payway-api.stage.adeprimo.se/external/api/v1/klarna_payments/place_order \
  --header 'accept: application/json' \
  --header 'authorization: Bearer token' \
  --header 'content-type: application/json' \
  --data '{
            "klarna_authorization_token": "",
            "klarna_payments_session_id": "",
            "browser_ip": "",
            "browser_language": "",
            "browser_user_agent": ""
          }'

And that's it! Granted you got a 200 OK response, you have now successfully placed your first Klarna Payments order with Payway.

Go live checklist

  1. Contact Klarna for production credentials.
  2. Setup payment provider configuration(s) based on given credentials.
  3. If possible, do a soft release to ease verification and potential blowback.