mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Ensure express card button is not rendered when advanced card gateway is enabled
This commit is contained in:
parent
0e6f6bfc97
commit
7be9a7751a
2 changed files with 30 additions and 10 deletions
|
@ -58,16 +58,28 @@ class DisabledFundingSources {
|
||||||
? $this->settings->get( 'disable_funding' )
|
? $this->settings->get( 'disable_funding' )
|
||||||
: array();
|
: 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';
|
$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();
|
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
|
||||||
$is_separate_card_enabled = isset( $available_gateways[ CardButtonGateway::ID ] );
|
$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 );
|
$key = array_search( 'card', $disable_funding, true );
|
||||||
if ( false !== $key ) {
|
if ( false !== $key ) {
|
||||||
unset( $disable_funding[ $key ] );
|
unset( $disable_funding[ $key ] );
|
||||||
|
|
|
@ -21,7 +21,11 @@ class DisabledFundingSourcesTest extends TestCase
|
||||||
$this->settings = Mockery::mock(Settings::class);
|
$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, []);
|
$sut = new DisabledFundingSources($this->settings, []);
|
||||||
|
|
||||||
|
@ -30,10 +34,14 @@ class DisabledFundingSourcesTest extends TestCase
|
||||||
|
|
||||||
when('is_checkout')->justReturn(true);
|
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, []);
|
$sut = new DisabledFundingSources($this->settings, []);
|
||||||
|
|
||||||
|
@ -42,10 +50,10 @@ class DisabledFundingSourcesTest extends TestCase
|
||||||
|
|
||||||
when('is_checkout')->justReturn(false);
|
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, [
|
$sut = new DisabledFundingSources($this->settings, [
|
||||||
'card' => 'Credit or debit cards',
|
'card' => 'Credit or debit cards',
|
||||||
|
@ -58,7 +66,7 @@ class DisabledFundingSourcesTest extends TestCase
|
||||||
|
|
||||||
when('is_checkout')->justReturn(true);
|
when('is_checkout')->justReturn(true);
|
||||||
|
|
||||||
$this->assertEquals(['foo'], $sut->sources('checkout-block'));
|
$this->assertEquals(['card', 'foo'], $sut->sources('checkout-block'));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setExpectations(
|
private function setExpectations(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue