♻️ Never disable funding source “paypal”

Consolidate funding source logic into the responsible class
This commit is contained in:
Philipp Stracker 2025-03-12 14:36:41 +01:00
parent f178636951
commit a5ee2e29d5
No known key found for this signature in database
2 changed files with 22 additions and 31 deletions

View file

@ -1455,20 +1455,6 @@ document.querySelector("#payment").before(document.querySelector(".ppcp-messages
$disabled_funding_sources[] = 'paylater';
}
$disabled_funding_sources = array_filter(
$disabled_funding_sources,
/**
* Make sure paypal is not sent in disable funding.
*
* @param string $funding_source The funding_source.
*
* @psalm-suppress MissingClosureParamType
*/
function( $funding_source ) {
return $funding_source !== 'paypal';
}
);
if ( count( $disabled_funding_sources ) > 0 ) {
$params['disable-funding'] = implode( ',', array_unique( $disabled_funding_sources ) );
}

View file

@ -5,7 +5,7 @@
* @package WooCommerce\PayPalCommerce\Button\Helper
*/
declare(strict_types=1);
declare( strict_types = 1 );
namespace WooCommerce\PayPalCommerce\Button\Helper;
@ -38,7 +38,7 @@ class DisabledFundingSources {
/**
* DisabledFundingSources constructor.
*
* @param Settings $settings The settings.
* @param Settings $settings The settings.
* @param array $all_funding_sources All existing funding sources.
*/
public function __construct( Settings $settings, array $all_funding_sources ) {
@ -69,25 +69,22 @@ class DisabledFundingSources {
$is_card_gateway_enabled = isset( $available_gateways[ CardButtonGateway::ID ] );
$is_using_cards = $is_dcc_enabled || $is_card_gateway_enabled;
// Check if card is already in disabled funding (from settings value).
$card_key = array_search( 'card', $disable_funding, true );
$is_card_disabled = ( $card_key !== false );
if ( $is_block_context && $is_dcc_enabled ) {
// Rule 1: Block checkout with DCC - do not load ACDC.
if ( ! $is_card_disabled ) {
if ( ! in_array( 'card', $disable_funding, true ) ) {
$disable_funding[] = 'card';
}
} elseif ( ! $is_checkout_page ) {
// Rule 2: Non-checkout pages - do not load ACDC.
if ( ! $is_card_disabled ) {
if ( ! in_array( 'card', $disable_funding, true ) ) {
$disable_funding[] = 'card';
}
} elseif ( $is_classic_checkout && $is_using_cards ) {
// Rule 3: Standard checkout with card methods - load ACDC.
if ( $is_card_disabled ) {
unset( $disable_funding[ $card_key ] );
}
$disable_funding = array_filter(
$disable_funding,
static fn( string $funding_source ) => $funding_source !== 'card'
);
}
/**
@ -113,14 +110,22 @@ class DisabledFundingSources {
$disable_funding = array_keys( $this->all_funding_sources );
if ( $is_using_cards ) {
$card_key = array_search( 'card', $disable_funding, true );
if ( false !== $card_key ) {
unset( $disable_funding[ $card_key ] );
}
$disable_funding = array_filter(
$disable_funding,
static fn( string $funding_source ) => $funding_source !== 'card'
);
}
}
return apply_filters( 'woocommerce_paypal_payments_disabled_funding_sources', $disable_funding );
$disable_funding = apply_filters(
'woocommerce_paypal_payments_disabled_funding_sources',
$disable_funding
);
// Make sure "paypal" is never disabled in the funding-sources.
return array_filter(
$disable_funding,
static fn( string $funding_source ) => $funding_source !== 'paypal'
);
}
}