Merge pull request #46 from woocommerce/issue-34-disable-dcc-when-gateway-disabled

Disable both gateways when gateway setting 'enabled' is false
This commit is contained in:
Rasmy Nguyen 2020-09-29 07:46:02 +00:00 committed by GitHub
commit 92276f9aa9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -60,10 +60,7 @@ class DisableGateways {
if ( ! isset( $methods[ PayPalGateway::ID ] ) && ! isset( $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;
@ -87,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