From 05c73303afb422d5ae6b1249999fc9ea5b879fa7 Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Tue, 4 Feb 2025 15:16:53 +0100 Subject: [PATCH] Settings UI: Fix eligibility checking for todos --- modules/ppcp-settings/services.php | 58 ++++++++----- .../src/Data/Definition/TodosDefinition.php | 84 ++++++++++++------- .../src/Service/TodosEligibilityService.php | 64 ++++++++++---- 3 files changed, 139 insertions(+), 67 deletions(-) diff --git a/modules/ppcp-settings/services.php b/modules/ppcp-settings/services.php index 2857bb3db..b5c4153e7 100644 --- a/modules/ppcp-settings/services.php +++ b/modules/ppcp-settings/services.php @@ -269,26 +269,46 @@ return array( ); }, 'settings.service.todos_eligibilities' => static function( ContainerInterface $container ): TodosEligibilityService { + $features = apply_filters( + 'woocommerce_paypal_payments_rest_common_merchant_features', + array() + ); + + $payment_endpoint = $container->get( 'settings.rest.payment' ); + $settings = $payment_endpoint->get_details()->get_data(); + + // Settings status. + $gateways = array( + 'apple_pay' => $settings['data']['ppcp-applepay']['enabled'] ?? false, + 'google_pay' => $settings['data']['ppcp-googlepay']['enabled'] ?? false, + 'axo' => $settings['data']['ppcp-axo-gateway']['enabled'] ?? false, + 'card-button' => $settings['data']['ppcp-card-button-gateway']['enabled'] ?? false, + ); + + // Merchant eligibility. + $capabilities = array( + 'apple_pay' => $features['apple_pay']['enabled'] ?? false, + 'google_pay' => $features['google_pay']['enabled'] ?? false, + 'acdc' => $features['advanced_credit_and_debit_cards']['enabled'] ?? false, + 'save_paypal' => $features['save_paypal_and_venmo']['enabled'] ?? false, + 'apm' => $features['alternative_payment_methods']['enabled'] ?? false, + 'paylater' => $features['pay_later_messaging']['enabled'] ?? false, + ); + return new TodosEligibilityService( - $container->has( 'axo.eligible' ) && $container->get( 'axo.eligible' ), - $container->has( 'card-fields.eligible' ) && $container->get( 'card-fields.eligible' ), - $container->has( 'paylater-configurator.is-available' ) && $container->get( 'paylater-configurator.is-available' ), - $container->has( 'wc-subscriptions.helper' ) && $container->get( 'wc-subscriptions.helper' )->plugin_is_active() && empty( - wc_get_products( - array( - 'type' => 'subscription', - 'limit' => 1, - ) - ) - ), - $container->has( 'apple-pay-domain.eligible' ) && $container->get( 'apple-pay-domain.eligible' ), - true, - $container->has( 'applepay.eligible' ) && $container->get( 'applepay.eligible' ), - $container->has( 'googlepay.eligible' ) && - $container->get( 'googlepay.eligible' ) && - ( $container->get( 'googlepay.available' ) && ! $container->get( 'googlepay.is_referral' ) ), - $container->has( 'paylater-messaging.available' ) && $container->get( 'paylater-messaging.available' ), - $container->has( 'button.basic-checkout.enabled' ) && ! $container->get( 'button.basic-checkout.enabled' ) + $capabilities['acdc'] && ! $gateways['axo'], // Enable Fastlane. + $capabilities['acdc'] && ! $gateways['card-button'], // Enable Credit and Debit Cards on your checkout. + true, // Enable Pay Later messaging. + true, // Add Pay Later messaging. + true, // Configure a PayPal Subscription. + true, // Add PayPal buttons. + true, // Register Domain for Apple Pay. + $capabilities['acdc'] && ! ( $capabilities['apple_pay'] && $capabilities['google_pay'] ), // Add digital wallets to your account. + $capabilities['acdc'] && ! $capabilities['apple_pay'], // Add Apple Pay to your account. + $capabilities['acdc'] && ! $capabilities['google_pay'], // Add Google Pay to your account. + true, // Configure a PayPal Subscription. + $capabilities['apple_pay'] && ! $gateways['apple_pay'], // Enable Apple Pay. + $capabilities['google_pay'] && ! $gateways['google_pay'] // Enable Google Pay. ); }, 'settings.rest.reset_dismissed_todos' => static function( ContainerInterface $container ): ResetDismissedTodosEndpoint { diff --git a/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php b/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php index e32fb79bd..40748b5f9 100644 --- a/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php +++ b/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php @@ -44,18 +44,19 @@ class TodosDefinition { $eligibility_checks = $this->eligibilities->get_eligibility_checks(); return array( - 'enable_fastlane' => array( + 'enable_fastlane' => array( 'title' => __( 'Enable Fastlane', 'woocommerce-paypal-payments' ), 'description' => __( 'Accelerate your guest checkout with Fastlane by PayPal', 'woocommerce-paypal-payments' ), 'isEligible' => $eligibility_checks['enable_fastlane'], 'action' => array( - 'type' => 'tab', - 'tab' => 'payment_methods', - 'section' => 'ppcp-fastlane', - 'modal' => 'ppcp-fastlane-gateway', + 'type' => 'tab', + 'tab' => 'payment_methods', + 'section' => 'ppcp-fastlane', + 'modal' => 'ppcp-fastlane-gateway', + 'highlight' => 'ppcp-fastlane-gateway', ), ), - 'enable_credit_debit_cards' => array( + 'enable_credit_debit_cards' => array( 'title' => __( 'Enable Credit and Debit Cards on your checkout', 'woocommerce-paypal-payments' ), 'description' => __( 'Credit and Debit Cards is now available for Blocks checkout pages', 'woocommerce-paypal-payments' ), 'isEligible' => $eligibility_checks['enable_credit_debit_cards'], @@ -66,7 +67,7 @@ class TodosDefinition { 'highlight' => 'ppcp-card-button-gateway', ), ), - 'enable_pay_later_messaging' => array( + 'enable_pay_later_messaging' => array( 'title' => __( 'Enable Pay Later messaging', 'woocommerce-paypal-payments' ), 'description' => __( 'Show Pay Later messaging to boost conversion rate and increase cart size.', 'woocommerce-paypal-payments' ), 'isEligible' => $eligibility_checks['enable_pay_later_messaging'], @@ -76,9 +77,9 @@ class TodosDefinition { 'section' => 'pay_later_messaging', ), ), - 'add_pay_later_messaging' => array( - 'title' => __( 'Add Pay Later messaging to site', 'woocommerce-paypal-payments' ), - 'description' => __( 'Present Pay Later messaging on your site to boost conversion rate and increase cart size.', 'woocommerce-paypal-payments' ), + 'add_pay_later_messaging' => array( + 'title' => __( 'Add Pay Later messaging', 'woocommerce-paypal-payments' ), + 'description' => __( 'Present Pay Later messaging on your page to boost conversion rate and increase cart size.', 'woocommerce-paypal-payments' ), 'isEligible' => $eligibility_checks['add_pay_later_messaging'], 'action' => array( 'type' => 'tab', @@ -86,7 +87,7 @@ class TodosDefinition { 'section' => 'pay_later_messaging', ), ), - 'configure_paypal_subscription' => array( + 'configure_paypal_subscription' => array( 'title' => __( 'Configure a PayPal Subscription', 'woocommerce-paypal-payments' ), 'description' => __( 'Connect a subscriptions-type product from WooCommerce with PayPal', 'woocommerce-paypal-payments' ), 'isEligible' => $eligibility_checks['configure_paypal_subscription'], @@ -95,7 +96,16 @@ class TodosDefinition { 'url' => admin_url( 'edit.php?post_type=product&product_type=subscription' ), ), ), - 'register_domain_apple_pay' => array( + 'add_paypal_buttons' => array( + 'title' => __( 'Add PayPal buttons', 'woocommerce-paypal-payments' ), + 'description' => __( 'Allow customers to check out quickly and securely from the page. Customers save time and get through checkout in fewer clicks.', 'woocommerce-paypal-payments' ), + 'isEligible' => $eligibility_checks['add_paypal_buttons'], + 'action' => array( + 'type' => 'tab', + 'tab' => 'styling', + ), + ), + 'register_domain_apple_pay' => array( 'title' => __( 'Register Domain for Apple Pay', 'woocommerce-paypal-payments' ), 'description' => __( 'To enable Apple Pay, you must register your domain with PayPal', 'woocommerce-paypal-payments' ), 'isEligible' => $eligibility_checks['register_domain_apple_pay'], @@ -105,43 +115,53 @@ class TodosDefinition { 'section' => 'apple_pay', ), ), - 'add_digital_wallets_to_account' => array( + 'add_digital_wallets' => array( 'title' => __( 'Add digital wallets to your account', 'woocommerce-paypal-payments' ), 'description' => __( 'Add the ability to accept Apple Pay & Google Pay to your PayPal account', 'woocommerce-paypal-payments' ), - 'isEligible' => $eligibility_checks['add_digital_wallets_to_account'], + 'isEligible' => $eligibility_checks['add_digital_wallets'], 'action' => array( 'type' => 'external', 'url' => 'https://www.paypal.com/businessmanage/account/settings', ), ), - 'enable_apple_pay' => array( + 'add_apple_pay' => array( + 'title' => __( 'Add Apple Pay to your account', 'woocommerce-paypal-payments' ), + 'description' => __( 'Add the ability to accept Apple Pay to your PayPal account', 'woocommerce-paypal-payments' ), + 'isEligible' => $eligibility_checks['add_apple_pay'], + 'action' => array( + 'type' => 'external', + 'url' => 'https://www.paypal.com/businessmanage/account/settings', + ), + ), + 'add_google_pay' => array( + 'title' => __( 'Add Google Pay to your account', 'woocommerce-paypal-payments' ), + 'description' => __( 'Add the ability to accept Google Pay to your PayPal account', 'woocommerce-paypal-payments' ), + 'isEligible' => $eligibility_checks['add_google_pay'], + 'action' => array( + 'type' => 'external', + 'url' => 'https://www.paypal.com/businessmanage/account/settings', + ), + ), + 'enable_apple_pay' => array( 'title' => __( 'Enable Apple Pay', 'woocommerce-paypal-payments' ), 'description' => __( 'Allow your buyers to check out via Apple Pay', 'woocommerce-paypal-payments' ), 'isEligible' => $eligibility_checks['enable_apple_pay'], 'action' => array( - 'type' => 'tab', - 'tab' => 'overview', - 'section' => 'apple_pay', + 'type' => 'tab', + 'tab' => 'payment_methods', + 'section' => 'ppcp-applepay', + 'highlight' => 'ppcp-applepay', ), ), - 'enable_google_pay' => array( + 'enable_google_pay' => array( 'title' => __( 'Enable Google Pay', 'woocommerce-paypal-payments' ), 'description' => __( 'Allow your buyers to check out via Google Pay', 'woocommerce-paypal-payments' ), 'isEligible' => $eligibility_checks['enable_google_pay'], 'action' => array( - 'type' => 'tab', - 'tab' => 'overview', - 'section' => 'google_pay', - ), - ), - 'add_paypal_buttons' => array( - 'title' => __( 'Add PayPal buttons to site', 'woocommerce-paypal-payments' ), - 'description' => __( 'Allow customers to check out quickly and securely. Customers save time and get through checkout in fewer clicks.', 'woocommerce-paypal-payments' ), - 'isEligible' => $eligibility_checks['add_paypal_buttons'], - 'action' => array( - 'type' => 'tab', - 'tab' => 'overview', - 'section' => 'styling', + 'type' => 'tab', + 'tab' => 'payment_methods', + 'section' => 'ppcp-googlepay', + 'highlight' => 'ppcp-googlepay', ), ), ); diff --git a/modules/ppcp-settings/src/Service/TodosEligibilityService.php b/modules/ppcp-settings/src/Service/TodosEligibilityService.php index cda79e7e3..c6e26cbf7 100644 --- a/modules/ppcp-settings/src/Service/TodosEligibilityService.php +++ b/modules/ppcp-settings/src/Service/TodosEligibilityService.php @@ -87,42 +87,72 @@ class TodosEligibilityService { */ private bool $is_paypal_buttons_eligible; + /** + * Whether PayPal subscription configuration is eligible. + * + * @var bool + */ + private bool $is_add_subscription_eligible; + + /** + * Whether enabling Apple Pay is eligible. + * + * @var bool + */ + private bool $is_enable_apple_pay_eligible; + + /** + * Whether enabling Google Pay is eligible. + * + * @var bool + */ + private bool $is_enable_google_pay_eligible; + /** * Constructor. * * @param bool $is_fastlane_eligible Whether Fastlane is eligible. * @param bool $is_card_payment_eligible Whether card payments are eligible. * @param bool $is_pay_later_messaging_eligible Whether Pay Later messaging is eligible. + * @param bool $is_pay_later_messaging_ui_eligible Whether Pay Later messaging for UI is eligible. * @param bool $is_subscription_eligible Whether subscriptions are eligible. + * @param bool $is_paypal_buttons_eligible Whether PayPal buttons are eligible. * @param bool $is_apple_pay_domain_eligible Whether Apple Pay domain registration is eligible. * @param bool $is_digital_wallet_eligible Whether digital wallet features are eligible. * @param bool $is_apple_pay_eligible Whether Apple Pay is eligible. * @param bool $is_google_pay_eligible Whether Google Pay is eligible. - * @param bool $is_pay_later_messaging_ui_eligible Whether Pay Later messaging for UI is eligible. - * @param bool $is_paypal_buttons_eligible Whether PayPal buttons are eligible. + * @param bool $is_add_subscription_eligible Whether PayPal subscription configuration is eligible. + * @param bool $is_enable_apple_pay_eligible Whether enabling Apple Pay is eligible. + * @param bool $is_enable_google_pay_eligible Whether enabling Google Pay is eligible. */ public function __construct( bool $is_fastlane_eligible, bool $is_card_payment_eligible, bool $is_pay_later_messaging_eligible, + bool $is_pay_later_messaging_ui_eligible, bool $is_subscription_eligible, + bool $is_paypal_buttons_eligible, bool $is_apple_pay_domain_eligible, bool $is_digital_wallet_eligible, bool $is_apple_pay_eligible, bool $is_google_pay_eligible, - bool $is_pay_later_messaging_ui_eligible = false, - bool $is_paypal_buttons_eligible = false + bool $is_add_subscription_eligible, + bool $is_enable_apple_pay_eligible, + bool $is_enable_google_pay_eligible ) { $this->is_fastlane_eligible = $is_fastlane_eligible; $this->is_card_payment_eligible = $is_card_payment_eligible; $this->is_pay_later_messaging_eligible = $is_pay_later_messaging_eligible; + $this->is_pay_later_messaging_ui_eligible = $is_pay_later_messaging_ui_eligible; $this->is_subscription_eligible = $is_subscription_eligible; + $this->is_paypal_buttons_eligible = $is_paypal_buttons_eligible; $this->is_apple_pay_domain_eligible = $is_apple_pay_domain_eligible; $this->is_digital_wallet_eligible = $is_digital_wallet_eligible; $this->is_apple_pay_eligible = $is_apple_pay_eligible; $this->is_google_pay_eligible = $is_google_pay_eligible; - $this->is_pay_later_messaging_ui_eligible = $is_pay_later_messaging_ui_eligible; - $this->is_paypal_buttons_eligible = $is_paypal_buttons_eligible; + $this->is_add_subscription_eligible = $is_add_subscription_eligible; + $this->is_enable_apple_pay_eligible = $is_enable_apple_pay_eligible; + $this->is_enable_google_pay_eligible = $is_enable_google_pay_eligible; } /** @@ -132,16 +162,18 @@ class TodosEligibilityService { */ public function get_eligibility_checks(): array { return array( - 'enable_fastlane' => fn() => ! $this->is_fastlane_eligible, - 'enable_credit_debit_cards' => fn() => $this->is_card_payment_eligible, - 'enable_pay_later_messaging' => fn() => ! $this->is_pay_later_messaging_eligible, - 'add_pay_later_messaging' => fn() => $this->is_pay_later_messaging_eligible && ! $this->is_pay_later_messaging_ui_eligible, - 'configure_paypal_subscription' => fn() => $this->is_subscription_eligible, - 'register_domain_apple_pay' => fn() => $this->is_apple_pay_domain_eligible, - 'add_digital_wallets_to_account' => fn() => $this->is_digital_wallet_eligible, - 'enable_apple_pay' => fn() => $this->is_apple_pay_eligible && ! $this->is_apple_pay_domain_eligible, - 'enable_google_pay' => fn() => $this->is_google_pay_eligible, - 'add_paypal_buttons' => fn() => $this->is_paypal_buttons_eligible, + 'enable_fastlane' => fn() => ! $this->is_fastlane_eligible, + 'enable_credit_debit_cards' => fn() => $this->is_card_payment_eligible, + 'enable_pay_later_messaging' => fn() => ! $this->is_pay_later_messaging_eligible, + 'add_pay_later_messaging' => fn() => $this->is_pay_later_messaging_eligible && ! $this->is_pay_later_messaging_ui_eligible, + 'configure_paypal_subscription' => fn() => $this->is_subscription_eligible, + 'add_paypal_buttons' => fn() => $this->is_paypal_buttons_eligible, + 'register_domain_apple_pay' => fn() => $this->is_apple_pay_domain_eligible, + 'add_digital_wallets' => fn() => $this->is_digital_wallet_eligible, + 'add_apple_pay' => fn() => $this->is_apple_pay_eligible, + 'add_google_pay' => fn() => $this->is_google_pay_eligible, + 'enable_apple_pay' => fn() => $this->is_enable_apple_pay_eligible, + 'enable_google_pay' => fn() => $this->is_enable_google_pay_eligible, ); } }