diff --git a/modules/ppcp-button/src/Helper/DisabledFundingSources.php b/modules/ppcp-button/src/Helper/DisabledFundingSources.php index fc60ba96b..203208b47 100644 --- a/modules/ppcp-button/src/Helper/DisabledFundingSources.php +++ b/modules/ppcp-button/src/Helper/DisabledFundingSources.php @@ -58,16 +58,28 @@ class DisabledFundingSources { ? $this->settings->get( 'disable_funding' ) : array(); - if ( ! is_checkout() ) { + $is_dcc_enabled = $this->settings->has( 'dcc_enabled' ) && $this->settings->get( 'dcc_enabled' ); + + if ( + ! is_checkout() + || ( $is_dcc_enabled && in_array( $context, array( 'checkout-block', 'cart-block' ), true ) ) + ) { $disable_funding[] = 'card'; } - $is_dcc_enabled = $this->settings->has( 'dcc_enabled' ) && $this->settings->get( 'dcc_enabled' ); - $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); $is_separate_card_enabled = isset( $available_gateways[ CardButtonGateway::ID ] ); - if ( is_checkout() && ( $is_dcc_enabled || $is_separate_card_enabled ) ) { + if ( + ( + is_checkout() + && ! in_array( $context, array( 'checkout-block', 'cart-block' ), true ) + ) + && ( + $is_dcc_enabled + || $is_separate_card_enabled + ) + ) { $key = array_search( 'card', $disable_funding, true ); if ( false !== $key ) { unset( $disable_funding[ $key ] ); diff --git a/tests/PHPUnit/Button/Helper/DisabledFundingSourcesTest.php b/tests/PHPUnit/Button/Helper/DisabledFundingSourcesTest.php index 7185a2255..5651c8393 100644 --- a/tests/PHPUnit/Button/Helper/DisabledFundingSourcesTest.php +++ b/tests/PHPUnit/Button/Helper/DisabledFundingSourcesTest.php @@ -21,7 +21,11 @@ class DisabledFundingSourcesTest extends TestCase $this->settings = Mockery::mock(Settings::class); } - public function test_is_checkout_true_does_not_add_card() + /** + * Block checkout page configured in WC "Checkout page" setting, + * `is_checkout` returns true when visiting the block checkout page. + */ + public function test_is_checkout_true_add_card_when_checkout_block_context() { $sut = new DisabledFundingSources($this->settings, []); @@ -30,10 +34,14 @@ class DisabledFundingSourcesTest extends TestCase when('is_checkout')->justReturn(true); - $this->assertEquals([], $sut->sources('')); + $this->assertEquals(['card'], $sut->sources('checkout-block')); } - public function test_is_checkout_false_adds_card() + /** + * Classic checkout page configured in WC "Checkout page" setting, + * `is_checkout` returns false when visiting the block checkout page. + */ + public function test_is_checkout_false_add_card_when_checkout_context() { $sut = new DisabledFundingSources($this->settings, []); @@ -42,10 +50,10 @@ class DisabledFundingSourcesTest extends TestCase when('is_checkout')->justReturn(false); - $this->assertEquals(['card'], $sut->sources('checkout-block')); + $this->assertEquals(['card'], $sut->sources('checkout')); } - public function test_checkout_block_context_adds_source() + public function test_is_checkout_true_add_allowed_sources_when_checkout_block_context() { $sut = new DisabledFundingSources($this->settings, [ 'card' => 'Credit or debit cards', @@ -58,7 +66,7 @@ class DisabledFundingSourcesTest extends TestCase when('is_checkout')->justReturn(true); - $this->assertEquals(['foo'], $sut->sources('checkout-block')); + $this->assertEquals(['card', 'foo'], $sut->sources('checkout-block')); } private function setExpectations(