mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Fix Fastlane regressions
This commit is contained in:
parent
162ec8d0f9
commit
868fdd8a8f
4 changed files with 52 additions and 26 deletions
|
@ -107,11 +107,9 @@ class AxoBlockModule implements ServiceModule, ExtendingModule, ExecutableModule
|
|||
'woocommerce_blocks_payment_method_type_registration',
|
||||
function( PaymentMethodRegistry $payment_method_registry ) use ( $c ): void {
|
||||
/*
|
||||
* Only register the method if we are not in the admin
|
||||
* (to avoid two Debit & Credit Cards gateways in the
|
||||
* checkout block in the editor: one from ACDC one from Axo).
|
||||
* Only register the method if we are not in the admin or the customer is not logged in.
|
||||
*/
|
||||
if ( ! is_admin() ) {
|
||||
if ( ! is_user_logged_in() ) {
|
||||
$payment_method_registry->register( $c->get( 'axoblock.method' ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class PaymentMethodSettingsMapHelper {
|
|||
* @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): ?bool {
|
||||
public function mapped_value( string $old_key ): ?bool {
|
||||
|
||||
$payment_method = $this->map()[ $old_key ] ?? false;
|
||||
|
||||
|
@ -56,7 +56,7 @@ class PaymentMethodSettingsMapHelper {
|
|||
* @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_settings = get_option( "woocommerce_{$gateway_name}_settings", array() );
|
||||
$gateway_enabled = $gateway_settings['enabled'] ?? false;
|
||||
|
||||
return $gateway_enabled === 'yes';
|
||||
|
|
|
@ -262,7 +262,7 @@ class StylingSettingsMapHelper {
|
|||
* @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): ?int {
|
||||
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.' );
|
||||
}
|
||||
|
@ -309,8 +309,8 @@ class StylingSettingsMapHelper {
|
|||
* @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;
|
||||
$gateway_settings = get_option( "woocommerce_{$gateway_name}_settings", array() );
|
||||
$gateway_enabled = $gateway_settings['enabled'] ?? false;
|
||||
|
||||
return $gateway_enabled === 'yes';
|
||||
}
|
||||
|
|
|
@ -449,6 +449,32 @@ class SettingsModule implements ServiceModule, ExecutableModule {
|
|||
}
|
||||
);
|
||||
|
||||
// Remove the Fastlane gateway if the customer is logged in, ensuring that we don't interfere with the Fastlane gateway status in the settings UI.
|
||||
add_filter(
|
||||
'woocommerce_available_payment_gateways',
|
||||
/**
|
||||
* Param types removed to avoid third-party issues.
|
||||
*
|
||||
* @psalm-suppress MissingClosureParamType
|
||||
*/
|
||||
static function ( $methods ) use ( $container ) : array {
|
||||
if ( ! is_array( $methods ) ) {
|
||||
return $methods;
|
||||
}
|
||||
|
||||
if ( is_user_logged_in() && ! is_admin() ) {
|
||||
foreach ( $methods as $key => $method ) {
|
||||
if ( $method instanceof WC_Payment_Gateway && $method->id === 'ppcp-axo-gateway' ) {
|
||||
unset( $methods[ $key ] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $methods;
|
||||
}
|
||||
);
|
||||
|
||||
add_filter(
|
||||
'woocommerce_paypal_payments_gateway_title',
|
||||
function ( string $title, WC_Payment_Gateway $gateway ) {
|
||||
|
@ -502,23 +528,25 @@ class SettingsModule implements ServiceModule, ExecutableModule {
|
|||
2
|
||||
);
|
||||
|
||||
add_filter( 'woocommerce_paypal_payments_axo_gateway_should_update_enabled', '__return_false' );
|
||||
add_filter(
|
||||
'woocommerce_paypal_payments_axo_gateway_title',
|
||||
function ( string $title, WC_Payment_Gateway $gateway ) {
|
||||
return $gateway->get_option( 'title', $title );
|
||||
},
|
||||
10,
|
||||
2
|
||||
);
|
||||
add_filter(
|
||||
'woocommerce_paypal_payments_axo_gateway_description',
|
||||
function ( string $description, WC_Payment_Gateway $gateway ) {
|
||||
return $gateway->get_option( 'description', $description );
|
||||
},
|
||||
10,
|
||||
2
|
||||
);
|
||||
if ( is_admin() ) {
|
||||
add_filter( 'woocommerce_paypal_payments_axo_gateway_should_update_enabled', '__return_false' );
|
||||
add_filter(
|
||||
'woocommerce_paypal_payments_axo_gateway_title',
|
||||
function ( string $title, WC_Payment_Gateway $gateway ) {
|
||||
return $gateway->get_option( 'title', $title );
|
||||
},
|
||||
10,
|
||||
2
|
||||
);
|
||||
add_filter(
|
||||
'woocommerce_paypal_payments_axo_gateway_description',
|
||||
function ( string $description, WC_Payment_Gateway $gateway ) {
|
||||
return $gateway->get_option( 'description', $description );
|
||||
},
|
||||
10,
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue