Skip to content

Commit

Permalink
Merge pull request #120 from pooliestudios/bugfix-api-test
Browse files Browse the repository at this point in the history
always use test-mode for api test; no longer test api in background
  • Loading branch information
janteuber authored Feb 23, 2023
2 parents fa6895b + 6caa6ab commit de81160
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
37 changes: 14 additions & 23 deletions src/Payone/Gateway/GatewayBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Payone/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) ;
Expand Down
2 changes: 1 addition & 1 deletion views/admin/options.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="wrap">
<h1>
Payone - Einstellungen
PAYONE - Einstellungen
<?php if ( count( $testable_gateways ) > 0 ) { ?>
<a href="#TB_inline?&width=400&height=300&inlineId=payone-modal-test-api-settings" class="button thickbox">
<?php _e( 'Test API settings', 'payone-woocommerce-3'); ?>
Expand Down

0 comments on commit de81160

Please sign in to comment.