Skip to content

Commit

Permalink
Merge pull request #415 from krokedil/develop
Browse files Browse the repository at this point in the history
Version 3.7.3
  • Loading branch information
MichaelBengtsson authored Sep 13, 2024
2 parents 2f4a783 + a33f131 commit 5fc8fe6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
6 changes: 4 additions & 2 deletions classes/requests/class-kp-requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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}";
Expand Down
6 changes: 4 additions & 2 deletions includes/kp-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions klarna-payments-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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__ );
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.

Expand Down

0 comments on commit 5fc8fe6

Please sign in to comment.