mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Merge branch 'PCP-4273-bcdc-button-is-visible-on-classic-checkout-and-on-express-checkout-even-when-acdc-is-enabled-or-disabled' of github.com:woocommerce/woocommerce-paypal-payments into PCP-4276-fastlane-is-broken-on-frontend
This commit is contained in:
commit
162ec8d0f9
4 changed files with 41 additions and 28 deletions
|
@ -9,7 +9,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\Compat\Settings;
|
||||
|
||||
use WooCommerce\PayPalCommerce\Settings\Data\PaymentSettings;
|
||||
use WooCommerce\PayPalCommerce\Axo\Gateway\AxoGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
|
||||
/**
|
||||
* A map of old to new payment method settings.
|
||||
|
@ -26,20 +27,18 @@ class PaymentMethodSettingsMapHelper {
|
|||
*/
|
||||
public function map(): array {
|
||||
return array(
|
||||
'dcc_enabled' => 'acdc',
|
||||
'axo_enabled' => 'axo',
|
||||
'dcc_enabled' => CreditCardGateway::ID,
|
||||
'axo_enabled' => AxoGateway::ID,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the value of a mapped key from the new settings.
|
||||
*
|
||||
* @param string $old_key The key from the legacy settings.
|
||||
* @param PaymentSettings $payment_settings The payment settings model.
|
||||
*
|
||||
* @param string $old_key The key from the legacy settings.
|
||||
* @return mixed The value of the mapped setting, (null if not found).
|
||||
*/
|
||||
public function mapped_value( string $old_key, PaymentSettings $payment_settings ): ?bool {
|
||||
public function mapped_value( string $old_key): ?bool {
|
||||
|
||||
$payment_method = $this->map()[ $old_key ] ?? false;
|
||||
|
||||
|
@ -47,6 +46,19 @@ class PaymentMethodSettingsMapHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
return $payment_settings->is_method_enabled( $payment_method );
|
||||
return $this->is_gateway_enabled( $payment_method );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the payment gateway with the given name is enabled.
|
||||
*
|
||||
* @param string $gateway_name The gateway name.
|
||||
* @return bool True if the payment gateway with the given name is enabled, otherwise false.
|
||||
*/
|
||||
protected function is_gateway_enabled( string $gateway_name ): bool {
|
||||
$gateway_settings = get_option( "woocommerce_{$gateway_name}_settings", [] );
|
||||
$gateway_enabled = $gateway_settings['enabled'] ?? false;
|
||||
|
||||
return $gateway_enabled === 'yes';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -214,7 +214,7 @@ class SettingsMapHelper {
|
|||
: $this->settings_tab_map_helper->mapped_value( $old_key, $this->model_cache[ $model_id ] );
|
||||
|
||||
case $model instanceof PaymentSettings:
|
||||
return $this->payment_method_settings_map_helper->mapped_value( $old_key, $model );
|
||||
return $this->payment_method_settings_map_helper->mapped_value( $old_key );
|
||||
|
||||
default:
|
||||
return $this->model_cache[ $model_id ][ $new_key ] ?? null;
|
||||
|
|
|
@ -89,13 +89,13 @@ class StylingSettingsMapHelper {
|
|||
return $this->mapped_disabled_funding_value( $styling_models, $payment_settings );
|
||||
|
||||
case 'googlepay_button_enabled':
|
||||
return $this->mapped_button_enabled_value( $styling_models, GooglePayGateway::ID, $payment_settings );
|
||||
return $this->mapped_button_enabled_value( $styling_models, GooglePayGateway::ID );
|
||||
|
||||
case 'applepay_button_enabled':
|
||||
return $this->mapped_button_enabled_value( $styling_models, ApplePayGateway::ID, $payment_settings );
|
||||
return $this->mapped_button_enabled_value( $styling_models, ApplePayGateway::ID );
|
||||
|
||||
case 'pay_later_button_enabled':
|
||||
return $this->mapped_button_enabled_value( $styling_models, 'pay-later', $payment_settings );
|
||||
return $this->mapped_button_enabled_value( $styling_models, 'pay-later' );
|
||||
|
||||
default:
|
||||
foreach ( $this->locations_map() as $old_location_name => $new_location_name ) {
|
||||
|
@ -257,28 +257,22 @@ class StylingSettingsMapHelper {
|
|||
/**
|
||||
* Retrieves the mapped enabled or disabled button value from the new settings.
|
||||
*
|
||||
* @param LocationStylingDTO[] $styling_models The list of location styling models.
|
||||
* @param string $button_name The button name (see {@link self::BUTTON_NAMES}).
|
||||
* @param AbstractDataModel|null $payment_settings The payment settings model.
|
||||
* @param LocationStylingDTO[] $styling_models The list of location styling models.
|
||||
* @param string $button_name The button name (see {@link self::BUTTON_NAMES}).
|
||||
* @return int The enabled (1) or disabled (0) state.
|
||||
* @throws RuntimeException If an invalid button name is provided.
|
||||
*/
|
||||
protected function mapped_button_enabled_value( array $styling_models, string $button_name, ?AbstractDataModel $payment_settings ): ?int {
|
||||
if ( is_null( $payment_settings ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function mapped_button_enabled_value( array $styling_models, string $button_name): ?int {
|
||||
if ( ! in_array( $button_name, self::BUTTON_NAMES, true ) ) {
|
||||
throw new RuntimeException( 'Wrong button name is provided.' );
|
||||
}
|
||||
|
||||
$locations_to_context_map = $this->current_context_to_new_button_location_map();
|
||||
$current_context = $locations_to_context_map[ $this->context() ] ?? '';
|
||||
assert( $payment_settings instanceof PaymentSettings );
|
||||
|
||||
foreach ( $styling_models as $model ) {
|
||||
if ( $model->enabled && $model->location === $current_context ) {
|
||||
if ( in_array( $button_name, $model->methods, true ) && $payment_settings->is_method_enabled( $button_name ) ) {
|
||||
if ( in_array( $button_name, $model->methods, true ) && $this->is_gateway_enabled( $button_name ) ) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -307,4 +301,17 @@ class StylingSettingsMapHelper {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the payment gateway with the given name is enabled.
|
||||
*
|
||||
* @param string $gateway_name The gateway name.
|
||||
* @return bool True if the payment gateway with the given name is enabled, otherwise false.
|
||||
*/
|
||||
protected function is_gateway_enabled( string $gateway_name ): bool {
|
||||
$gateway_settings = get_option( "woocommerce_{$gateway_name}_settings", [] );
|
||||
$gateway_enabled = $gateway_settings['enabled'] ?? false;
|
||||
|
||||
return $gateway_enabled === 'yes';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,12 +105,6 @@ class PaymentSettings extends AbstractDataModel {
|
|||
return $this->get_paylater_enabled();
|
||||
|
||||
default:
|
||||
if (
|
||||
! did_filter( 'woocommerce_payment_gateways' )
|
||||
|| doing_filter( 'woocommerce_payment_gateways' )
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
$gateway = $this->get_gateway( $method_id );
|
||||
|
||||
if ( $gateway ) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue