Klarna API key password length

Created on 13 January 2025, about 1 month ago

Problem/Motivation

Klarna API key passwords may be up to 255 characters in length. The default maxlength of Drupal text fields is 128 characters. This has not been overridden in the password field in the config form, resulting in being unable to store a full Klarna API key password.

Steps to reproduce

Install module and set up a payment gateway. Attempt to copy and paste a Klarna API key password longer than 128 characters into the password field.

Proposed resolution

Add'#maxlength' => 255 into the password field definition in /src/Plugin/Commerce/PaymentGateway/Klarna.php

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇬🇧United Kingdom gillmead

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @gillmead
  • 🇸🇪Sweden cruze72

    I have tested the latest version of the module beta-3.0.0 and get the following error message:

    An error occurred for order #698: [Klarna\ApiException]: [401] Client error: `POST https://api.klarna.com/payments/v1/sessions` resulted in a `401 Unauthorized` response: @"error_code": "PERMISSION_DENIED", "error_message": "Authentication failed or permission not granted"

    I added suggested fix but still get the error.

  • First commit to issue fork.
  • 🇫🇮Finland tuutti

    I have tested the latest version of the module beta-3.0.0 and get the following error message

    Can you check if overriding the API key in settings.php works?

    Add something like this to your settings.php file, just replace the klarna_payments with the actual ID of your Klarna payment gateway:

    $config['commerce_payment.commerce_payment_gateway.klarna_payments']['configuration']['password'] = '123';

  • 🇸🇪Sweden cruze72

    Hi,
    Unfortunately not.

    Error when processing a transaction:
    An error occurred for order #709: [Klarna\ApiException]: [401] Client error: `POST https://api.klarna.com/payments/v1/sessions` resulted in a `401 Unauthorized` response: @"error_code": "PERMISSION_DENIED", "error_message": "Authentication failed or permission not granted"

    Error when running drush command:
    [error] Config commerce_payment.commerce_payment_gateway.klarna_payments does not exist

    I have tested with password key in the following formats:
    $config['commerce_payment.commerce_payment_gateway.klarna_payments']['configuration']['password']
    = '';
    $config['commerce_payment.commerce_payment_gateway.klarna_payments']['configuration']['password']
    = '';

  • 🇫🇮Finland tuutti

    You need to change the klarna_payments part to match whatever your payment gateway ID is.

    You can find it by going to Commerce -> Configuration -> Payment gateways.

    It should be the value of "ID" field. In my case it's klarna_payments:

    So if your ID were called klarna_something, then the drush command should be:

    drush cget commerce_payment.commerce_payment_gateway.klarna_something --include-overridden

    And the $config:

    $config['commerce_payment.commerce_payment_gateway.klarna_something']['configuration']['password']
    = 'apikey';
    
  • 🇸🇪Sweden cruze72

    Got it. Here is the result:

    uuid: f7d15d54-b589-4a9c-bfdf-55716c0716d7
    langcode: en
    status: true
    dependencies:
    module:
    - commerce_klarna_payments
    id: klarna
    label: Klarna
    weight: null
    plugin: klarna_payments
    configuration:
    display_label: 'Klarna Payments'
    mode: live
    payment_method_types:
    - 'Credit card'
    collect_billing_information: true
    username: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
    password: bnlNIW8pL0NXUGw_TTJLKjY4akpqRXB0SVdmSmxrVU0sYzQyZDg0YzktYjYxMy00NzJlLThlYjYtYjM0ZmYwNDQ4Y2VhLDEsNWJIQTU2ajFBa3Ro
    region: eu
    cancel_fraudulent_orders: false
    options:
    color_border: ''
    color_border_selected: ''
    color_text: ''
    color_details: ''
    radius_border: ''
    conditions: { }
    conditionOperator: AND

  • 🇸🇪Sweden cruze72

    Upon further testing it appears the same error message is shown with the similar Commerce Klarna Checkout module.

    "PERMISSION_DENIED", "error_message": "Authentication failed or permission not granted"

    Would this indicate that either Klarna has changed their API or i am using the wrong login credentials.

    Within the Klarna merchant portal there are three options for integrating:
    1.Klarna API keys
    2. Client ID with password
    3. SMTP authentication

    I've tried with all three variants and in the case of #1 - with and without the 'klarna_live_api_' prefix in the password.

    I am assuming i should use #1 ...?

  • 🇫🇮Finland tuutti

    Go to Settings -> Klarna API Keys -> click "Generate new Klarna API Key" button and it should give a downloadable text file with "username" and "password".

    The password should include the klarna_live_api_ prefix

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024