Ensure express card button is not rendered when advanced card gateway is enabled

This commit is contained in:
Emili Castells Guasch 2024-06-28 17:20:16 +02:00
parent 0e6f6bfc97
commit 7be9a7751a
2 changed files with 30 additions and 10 deletions

View file

@ -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 ] );

View file

@ -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(