diff --git a/classes/requests/class-kp-requests.php b/classes/requests/class-kp-requests.php index eb03a290..26fcaf49 100644 --- a/classes/requests/class-kp-requests.php +++ b/classes/requests/class-kp-requests.php @@ -76,9 +76,10 @@ public function __construct( $arguments ) { */ protected function get_base_url( $country, $settings ) { $country_data = KP_Form_Fields::$kp_form_auto_countries[ strtolower( $country ?? '' ) ] ?? null; + $testmode = wc_string_to_bool( $settings['testmode'] ?? 'no' ); // Get the testmode setting. $region = strtolower( apply_filters( 'klarna_base_region', $country_data['endpoint'] ?? '' ) ); // Get the region from the country parameters, blank for EU. - $playground = 'yes' === $settings['testmode'] ? '.playground' : ''; // If testmode is enabled, add playground to the subdomain. + $playground = $testmode ? '.playground' : ''; // If testmode is enabled, add playground to the subdomain. $subdomain = "api{$region}{$playground}"; // Combine the string to one subdomain. return "https://{$subdomain}.klarna.com/"; // Return the full base url for the api. @@ -90,13 +91,14 @@ protected function get_base_url( $country, $settings ) { public function set_credentials() { $country = strtolower( $this->arguments['country'] ) ?? strtolower( kp_get_klarna_country() ); // Get the country from the arguments, or the fetch from helper method. $combined_eu = isset( $this->settings['combine_eu_credentials'] ) ? ( 'yes' === $this->settings['combine_eu_credentials'] ) : false; // Check if we should combine the EU credentials. + $testmode = wc_string_to_bool( $this->settings['testmode'] ?? 'no' ); // Get the testmode setting. // If the country is a EU country, check if we should get the credentials from the EU settings. if ( $combined_eu && key_exists( $country, KP_Form_Fields::available_countries( 'eu' ) ) ) { $country = 'eu'; } - $prefix = 'yes' === $this->settings['testmode'] ? 'test_' : ''; // If testmode is enabled, add test_ to the setting strings. + $prefix = $testmode ? 'test_' : ''; // If testmode is enabled, add test_ to the setting strings. $merchant_id = "{$prefix}merchant_id_{$country}"; $shared_secret = "{$prefix}shared_secret_{$country}"; diff --git a/includes/kp-functions.php b/includes/kp-functions.php index 5e74f522..37df5949 100644 --- a/includes/kp-functions.php +++ b/includes/kp-functions.php @@ -83,7 +83,9 @@ function kp_get_klarna_country( $order = false ) { * @return void */ function kp_save_order_meta_data( $order, $response ) { - $environment = 'yes' === get_option( 'woocommerce_klarna_payments_settings' )['testmode'] ? 'test' : 'live'; + $settings = get_option( 'woocommerce_klarna_payments_settings', array() ); + $testmode = wc_string_to_bool( $settings['testmode'] ?? 'no' ); + $environment = $testmode ? 'test' : 'live'; $klarna_country = kp_get_klarna_country( $order ); @@ -340,7 +342,7 @@ function kp_is_country_available( $country ) { $country = strtolower( $country ); if ( empty( $available_countries ) ) { // See if the country has values saved from the old settings, before the available countries setting was added. - $testmode = $settings['testmode'] ?? 'no'; + $testmode = wc_string_to_bool( $settings['testmode'] ?? 'no' ); $prefix = $testmode ? 'test_' : ''; // If the country is a EU country, check if we are using the combined EU credentials. diff --git a/klarna-payments-for-woocommerce.php b/klarna-payments-for-woocommerce.php index b5ba1fc2..aa8c0ef5 100644 --- a/klarna-payments-for-woocommerce.php +++ b/klarna-payments-for-woocommerce.php @@ -5,12 +5,12 @@ * Description: Provides Klarna Payments as payment method to WooCommerce. * Author: klarna * Author URI: https://www.klarna.com/ - * Version: 3.7.2 + * Version: 3.7.3 * Text Domain: klarna-payments-for-woocommerce * Domain Path: /languages * * WC requires at least: 5.6.0 - * WC tested up to: 9.2.3 + * WC tested up to: 9.3.1 * Requires Plugins: woocommerce * * Copyright (c) 2017-2024 Krokedil @@ -42,7 +42,7 @@ /** * Required minimums and constants */ -define( 'WC_KLARNA_PAYMENTS_VERSION', '3.7.2' ); +define( 'WC_KLARNA_PAYMENTS_VERSION', '3.7.3' ); define( 'WC_KLARNA_PAYMENTS_MIN_PHP_VER', '7.4.0' ); define( 'WC_KLARNA_PAYMENTS_MIN_WC_VER', '5.6.0' ); define( 'WC_KLARNA_PAYMENTS_MAIN_FILE', __FILE__ ); diff --git a/readme.txt b/readme.txt index 195c9fdd..7c2c7acc 100644 --- a/readme.txt +++ b/readme.txt @@ -7,7 +7,7 @@ Tested up to: 6.6.2 Requires PHP: 7.4 WC requires at least: 5.6.0 WC tested up to: 9.2.3 -Stable tag: 3.7.2 +Stable tag: 3.7.3 License: GPLv3 or later License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -51,6 +51,9 @@ For help setting up and configuring Klarna Payments for WooCommerce please refer == Changelog == += 2024.09.13 - version 3.7.3 = +* Fix - Fix an issue with getting the correct credentials in some cases when not using the combined setting for EU countries. + = 2024.09.12 - version 3.7.2 = * Fix - Fixed a undefined index warning related to new settings.