From c344b02c8e5b8f4870aa4b19da49ca56b798dbac Mon Sep 17 00:00:00 2001 From: Dirk Olbertz Date: Wed, 22 Feb 2023 15:05:39 +0100 Subject: [PATCH 1/2] always use test-mode for api test; no longer test api in background --- src/Payone/Gateway/GatewayBase.php | 37 +++++++++++------------------- src/Payone/Plugin.php | 2 +- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/Payone/Gateway/GatewayBase.php b/src/Payone/Gateway/GatewayBase.php index 4cb8432..fcf7ea5 100644 --- a/src/Payone/Gateway/GatewayBase.php +++ b/src/Payone/Gateway/GatewayBase.php @@ -9,7 +9,6 @@ abstract class GatewayBase extends \WC_Payment_Gateway { const TRANSIENT_KEY_SELECT_GATEWAY = 'payone_select_gateway'; - const OPTION_KEY_API_VALUES_VALID = 'payone_api_values_valid'; /** * @var array @@ -155,12 +154,12 @@ public function get_mode() { } public function admin_options() { - parent::admin_options(); - - if ( ! $this->payone_api_settings_are_valid( true ) ) { - $this->add_error( __( 'Connection to PAYONE API failed', 'payone-woocommerce-3' ) ); + if ( ! $this->payone_api_settings_are_valid() ) { + $this->add_error( __( 'Connection to PAYONE API failed', 'payone-woocommerce-3' ) ); $this->display_errors(); } + + parent::admin_options(); } public function payone_is_testable() { @@ -171,23 +170,19 @@ public function payone_is_testable() { /** * @return bool */ - public function payone_api_settings_are_valid( $force = false ) { + public function payone_api_settings_are_valid() { $test_result = true; if ( $this->payone_is_testable() ) { - $transient_key = self::OPTION_KEY_API_VALUES_VALID . '_' . $this->id; - - $test_result = false; - $transient_result = null; - if ( $force === false ) { - $transient_result = get_transient( $transient_key ); // is false, when transient not found - $test_result = 'yes' === $transient_result; - } - if ( $force === true || $transient_result === false ) { - $test_result = ( new $this->test_transaction_classname( $this ) ) - ->test_request_successful(); - set_transient( $transient_key, $test_result ? 'yes' : 'no', 60 * 60 ); // 1 hour caching - } + $test_result = ( new $this->test_transaction_classname( $this ) ) + ->set( 'mode', 'test' ) + ->test_request_successful(); + + if ( ! $test_result ) { + $this->enabled = 'no'; + $this->settings['enabled'] = 'no'; + $this->update_option( 'enabled', $this->enabled ); + } } return $test_result; @@ -335,10 +330,6 @@ public function is_available() { $is_available = in_array( $country, $this->countries, true ); } - if ( $is_available ) { - $is_available = $this->payone_api_settings_are_valid(); - } - return $is_available; } diff --git a/src/Payone/Plugin.php b/src/Payone/Plugin.php index 4e8ded3..2062604 100644 --- a/src/Payone/Plugin.php +++ b/src/Payone/Plugin.php @@ -408,7 +408,7 @@ private function process_check_api_settings_callback() { $gateway = self::find_gateway( $gateway_id ); if ( $gateway ) { - $result = $gateway->payone_api_settings_are_valid( true ); + $result = $gateway->payone_api_settings_are_valid(); } $message = $result ? __( 'successful', 'payone-woocommerce-3' ) : __( 'failed', 'payone-woocommerce-3' ) ; From 6caa6abedb968486e94b8c6d47540a04a68d1fdf Mon Sep 17 00:00:00 2001 From: Dirk Olbertz Date: Wed, 22 Feb 2023 15:51:32 +0100 Subject: [PATCH 2/2] text change --- views/admin/options.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/admin/options.php b/views/admin/options.php index d95310c..fc5cf5f 100644 --- a/views/admin/options.php +++ b/views/admin/options.php @@ -1,6 +1,6 @@

- Payone - Einstellungen + PAYONE - Einstellungen 0 ) { ?>