extract logic for disabling both gateways into a helper function

This commit is contained in:
David Remer 2020-09-29 10:17:59 +03:00
parent cc1365d5e9
commit 8c6cb68b0c

View file

@ -60,16 +60,7 @@ class DisableGateways {
if ( ! isset( $methods[ PayPalGateway::ID ] ) && ! isset( $methods[ CreditCardGateway::ID ] ) ) {
return $methods;
}
if ( ! $this->settings->has( 'enabled' ) || ! $this->settings->get( 'enabled' ) ) {
unset( $methods[ PayPalGateway::ID ] );
unset( $methods[ CreditCardGateway::ID ] );
return $methods;
}
if (
! $this->settings->has( 'merchant_email' )
|| ! is_email( $this->settings->get( 'merchant_email' ) )
) {
if ( $this->disable_both_gateways() ) {
unset( $methods[ PayPalGateway::ID ] );
unset( $methods[ CreditCardGateway::ID ] );
return $methods;
@ -93,6 +84,22 @@ class DisableGateways {
return array( PayPalGateway::ID => $methods[ PayPalGateway::ID ] );
}
/**
* Whether both gateways should be disabled or not.
*
* @return bool
*/
private function disable_both_gateways() : bool {
if ( ! $this->settings->has( 'enabled' ) || ! $this->settings->get( 'enabled' ) ) {
return true;
}
if ( ! $this->settings->has( 'merchant_email' ) || ! is_email( $this->settings->get( 'merchant_email' ) ) ) {
return true;
}
return false;
}
/**
* Whether the Gateways need to be disabled. When we come to the checkout with a running PayPal
* session, we need to disable the other Gateways, so the customer can smoothly sail through the