From 7a03bda2ac4171cf05e1ac86d69b5ccfc3035eaf Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 17 Feb 2025 17:18:10 +0400 Subject: [PATCH 1/8] Map the "Invoice prefix" --- modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php b/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php index d3ce17290..5e43c7745 100644 --- a/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php +++ b/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php @@ -37,6 +37,7 @@ class SettingsTabMapHelper { 'subtotal_mismatch_behavior' => 'subtotal_adjustment', 'landing_page' => 'landing_page', 'smart_button_language' => 'button_language', + 'prefix' => 'invoice_prefix', ); } From 3e5f151bbb9d14db848def213bdd74490b07e9c0 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 17 Feb 2025 17:31:56 +0400 Subject: [PATCH 2/8] Map the "Order intent" --- .../src/Settings/SettingsTabMapHelper.php | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php b/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php index 5e43c7745..99f93c4ce 100644 --- a/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php +++ b/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php @@ -37,7 +37,8 @@ class SettingsTabMapHelper { 'subtotal_mismatch_behavior' => 'subtotal_adjustment', 'landing_page' => 'landing_page', 'smart_button_language' => 'button_language', - 'prefix' => 'invoice_prefix', + 'prefix' => 'invoice_prefix', + 'intent' => '', ); } @@ -58,6 +59,9 @@ class SettingsTabMapHelper { case 'landing_page': return $this->mapped_landing_page_value( $settings_model ); + case 'intent': + return $this->mapped_intent_value( $settings_model ); + default: return $settings_model[ $new_key ] ?? null; } @@ -99,4 +103,21 @@ class SettingsTabMapHelper { : ApplicationContext::LANDING_PAGE_NO_PREFERENCE ); } + + /** + * Retrieves the mapped value for the order intent from the new settings. + * + * @param array $settings_model The new settings model data as an array. + * @return 'AUTHORIZE'|'CAPTURE'|null The mapped 'intent' setting value. + */ + protected function mapped_intent_value( array $settings_model ): ?string { + $authorize_only = $settings_model['authorize_only'] ?? null; + $capture_virtual_orders = $settings_model['capture_virtual_orders'] ?? null; + + if ( is_null( $authorize_only ) && is_null( $capture_virtual_orders ) ) { + return null; + } + + return $authorize_only ? 'AUTHORIZE' : 'CAPTURE'; + } } From 228861ee89ffa80c64b074f8ae2bbfe0c22a8770 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 17 Feb 2025 17:33:53 +0400 Subject: [PATCH 3/8] Map the "vaulting" --- modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php b/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php index 99f93c4ce..5f3654366 100644 --- a/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php +++ b/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php @@ -39,6 +39,7 @@ class SettingsTabMapHelper { 'smart_button_language' => 'button_language', 'prefix' => 'invoice_prefix', 'intent' => '', + 'vault_enabled' => 'save_paypal_and_venmo', ); } From 0cdb46dfa6bdfd215cc713a79b29b5619d2bc912 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 17 Feb 2025 17:34:41 +0400 Subject: [PATCH 4/8] Map the vaulting for the Credit and Debit Cards --- modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php b/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php index 5f3654366..79a449d20 100644 --- a/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php +++ b/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php @@ -39,7 +39,7 @@ class SettingsTabMapHelper { 'smart_button_language' => 'button_language', 'prefix' => 'invoice_prefix', 'intent' => '', - 'vault_enabled' => 'save_paypal_and_venmo', + 'vault_enabled_dcc' => 'save_card_details', ); } From a71f687bcff142596057bb0f1513dc730a24f268 Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 17 Feb 2025 17:36:20 +0400 Subject: [PATCH 5/8] Map the "Pay Now Experience" --- .../src/Settings/SettingsTabMapHelper.php | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php b/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php index 79a449d20..3e5ccfbdb 100644 --- a/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php +++ b/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php @@ -30,16 +30,17 @@ class SettingsTabMapHelper { */ public function map(): array { return array( - 'disable_cards' => 'disabled_cards', - 'brand_name' => 'brand_name', - 'soft_descriptor' => 'soft_descriptor', - 'payee_preferred' => 'instant_payments_only', - 'subtotal_mismatch_behavior' => 'subtotal_adjustment', - 'landing_page' => 'landing_page', - 'smart_button_language' => 'button_language', - 'prefix' => 'invoice_prefix', - 'intent' => '', - 'vault_enabled_dcc' => 'save_card_details', + 'disable_cards' => 'disabled_cards', + 'brand_name' => 'brand_name', + 'soft_descriptor' => 'soft_descriptor', + 'payee_preferred' => 'instant_payments_only', + 'subtotal_mismatch_behavior' => 'subtotal_adjustment', + 'landing_page' => 'landing_page', + 'smart_button_language' => 'button_language', + 'prefix' => 'invoice_prefix', + 'intent' => '', + 'vault_enabled_dcc' => 'save_card_details', + 'blocks_final_review_enabled' => 'enable_pay_now', ); } From c1b1f47bbeecf50a89c83e49c9208c647c3d3cdd Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 17 Feb 2025 17:52:48 +0400 Subject: [PATCH 6/8] Fix the "Pay Now Experience" mapping value --- .../src/Settings/SettingsTabMapHelper.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php b/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php index 3e5ccfbdb..fddb31f99 100644 --- a/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php +++ b/modules/ppcp-compat/src/Settings/SettingsTabMapHelper.php @@ -64,6 +64,9 @@ class SettingsTabMapHelper { case 'intent': return $this->mapped_intent_value( $settings_model ); + case 'blocks_final_review_enabled': + return $this->mapped_pay_now_value( $settings_model ); + default: return $settings_model[ $new_key ] ?? null; } @@ -122,4 +125,20 @@ class SettingsTabMapHelper { return $authorize_only ? 'AUTHORIZE' : 'CAPTURE'; } + + /** + * Retrieves the mapped value for the "Pay Now Experience" from the new settings. + * + * @param array $settings_model The new settings model data as an array. + * @return bool|null The mapped 'Pay Now Experience' setting value. + */ + protected function mapped_pay_now_value( array $settings_model ): ?bool { + $enable_pay_now = $settings_model['enable_pay_now'] ?? null; + + if ( is_null( $enable_pay_now ) ) { + return null; + } + + return ! $enable_pay_now; + } } From fbeae9b0ed5e30dee1dbdf0a7fe3dec2bd9669ab Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Mon, 17 Feb 2025 20:17:51 +0400 Subject: [PATCH 7/8] Check if mapped value is not null before returning true --- modules/ppcp-wc-gateway/src/Settings/Settings.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-wc-gateway/src/Settings/Settings.php b/modules/ppcp-wc-gateway/src/Settings/Settings.php index 9340357a6..0e71dd3b8 100644 --- a/modules/ppcp-wc-gateway/src/Settings/Settings.php +++ b/modules/ppcp-wc-gateway/src/Settings/Settings.php @@ -120,7 +120,10 @@ class Settings implements ContainerInterface { * @return bool */ public function has( string $id ) { - if ( $this->settings_map_helper->has_mapped_key( $id ) ) { + if ( + $this->settings_map_helper->has_mapped_key( $id ) + && ! is_null( $this->settings_map_helper->mapped_value( $id ) ) + ) { return true; } From 745a1031bc54c622bd72e8c4b293148ac513da11 Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Mon, 17 Feb 2025 21:04:16 +0100 Subject: [PATCH 8/8] Todos: Update the eligibility conditions for the Subscription todo --- modules/ppcp-settings/services.php | 23 ++++++++-------- .../src/Data/Definition/TodosDefinition.php | 24 +++++++++++++---- .../src/Service/TodosEligibilityService.php | 10 ------- .../src/Helper/SubscriptionHelper.php | 27 +++++++++++++++++++ 4 files changed, 58 insertions(+), 26 deletions(-) diff --git a/modules/ppcp-settings/services.php b/modules/ppcp-settings/services.php index 9bb48f438..a91c1f9d4 100644 --- a/modules/ppcp-settings/services.php +++ b/modules/ppcp-settings/services.php @@ -307,7 +307,8 @@ return array( 'settings.data.definition.todos' => static function ( ContainerInterface $container ) : TodosDefinition { return new TodosDefinition( $container->get( 'settings.service.todos_eligibilities' ), - $container->get( 'settings.data.general' ) + $container->get( 'settings.data.general' ), + $container->get( 'wc-subscriptions.helper' ) ); }, 'settings.data.definition.methods' => static function ( ContainerInterface $container ) : PaymentMethodsDefinition { @@ -360,18 +361,18 @@ return array( $capabilities['acdc'] && ! $gateways['axo'], // Enable Fastlane. $capabilities['acdc'] && ! $gateways['card-button'], // Enable Credit and Debit Cards on your checkout. $is_pay_later_messaging_enabled_for_any_location, // Enable Pay Later messaging. - ! $is_pay_later_messaging_enabled_for_any_location && ! $pay_later_statuses['product'], // Add Pay Later messaging (Product page). - ! $is_pay_later_messaging_enabled_for_any_location && ! $pay_later_statuses['cart'], // Add Pay Later messaging (Cart). + ! $is_pay_later_messaging_enabled_for_any_location && ! $pay_later_statuses['product'], // Add Pay Later messaging (Product page). + ! $is_pay_later_messaging_enabled_for_any_location && ! $pay_later_statuses['cart'], // Add Pay Later messaging (Cart). ! $is_pay_later_messaging_enabled_for_any_location && ! $pay_later_statuses['checkout'], // Add Pay Later messaging (Checkout). - 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. + $container->has( 'save-payment-methods.eligible' ) && ! $container->get( 'save-payment-methods.eligible' ) && $container->has( 'wc-subscriptions.helper' ) && $container->get( 'wc-subscriptions.helper' ) + ->plugin_is_active(), // Configure a PayPal Subscription. + true, // Add PayPal buttons. + $capabilities['apple_pay'], // 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. + $capabilities['acdc'] && ! $capabilities['google_pay'], // Add Google Pay to your account. + $capabilities['apple_pay'] && ! $gateways['apple_pay'], // Enable Apple Pay. + $capabilities['google_pay'] && ! $gateways['google_pay'], // Enable Google Pay. ); }, ); diff --git a/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php b/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php index 204b81467..cb231ed22 100644 --- a/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php +++ b/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php @@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\Settings\Data\Definition; use WooCommerce\PayPalCommerce\Settings\Service\TodosEligibilityService; use WooCommerce\PayPalCommerce\Settings\Data\GeneralSettings; +use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper; /** * Class TodosDefinition @@ -34,18 +35,28 @@ class TodosDefinition { */ protected GeneralSettings $settings; + /** + * The subscription helper. + * + * @var SubscriptionHelper + */ + protected SubscriptionHelper $subscription_helper; + /** * Constructor. * * @param TodosEligibilityService $eligibilities The todos eligibility service. * @param GeneralSettings $settings The general settings service. + * @param SubscriptionHelper $subscription_helper The subscription helper. */ public function __construct( TodosEligibilityService $eligibilities, - GeneralSettings $settings + GeneralSettings $settings, + SubscriptionHelper $subscription_helper ) { - $this->eligibilities = $eligibilities; - $this->settings = $settings; + $this->eligibilities = $eligibilities; + $this->settings = $settings; + $this->subscription_helper = $subscription_helper; } /** @@ -126,8 +137,11 @@ class TodosDefinition { 'description' => __( 'Connect a subscriptions-type product from WooCommerce with PayPal', 'woocommerce-paypal-payments' ), 'isEligible' => $eligibility_checks['configure_paypal_subscription'], 'action' => array( - 'type' => 'external', - 'url' => admin_url( 'edit.php?post_type=product&product_type=subscription' ), + 'type' => 'external', + 'url' => $this->subscription_helper->has_subscription_products() + ? admin_url( 'edit.php?post_type=product&product_type=subscription' ) // If subscription products exist, go to the subscriptions products archive page. + : admin_url( 'post-new.php?post_type=product' ), // If there are no subscriptions products, go to create one. + 'completeOnClick' => true, ), 'priority' => 5, ), diff --git a/modules/ppcp-settings/src/Service/TodosEligibilityService.php b/modules/ppcp-settings/src/Service/TodosEligibilityService.php index 1f2a385e6..35e83d5a7 100644 --- a/modules/ppcp-settings/src/Service/TodosEligibilityService.php +++ b/modules/ppcp-settings/src/Service/TodosEligibilityService.php @@ -101,13 +101,6 @@ 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. * @@ -137,7 +130,6 @@ class TodosEligibilityService { * @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_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. */ @@ -154,7 +146,6 @@ class TodosEligibilityService { bool $is_digital_wallet_eligible, bool $is_apple_pay_eligible, bool $is_google_pay_eligible, - bool $is_add_subscription_eligible, bool $is_enable_apple_pay_eligible, bool $is_enable_google_pay_eligible ) { @@ -170,7 +161,6 @@ class TodosEligibilityService { $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_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; } diff --git a/modules/ppcp-wc-subscriptions/src/Helper/SubscriptionHelper.php b/modules/ppcp-wc-subscriptions/src/Helper/SubscriptionHelper.php index 45e481728..8bc1e40f5 100644 --- a/modules/ppcp-wc-subscriptions/src/Helper/SubscriptionHelper.php +++ b/modules/ppcp-wc-subscriptions/src/Helper/SubscriptionHelper.php @@ -21,6 +21,7 @@ use WCS_Manual_Renewal_Manager; use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException; use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway; +use WP_Query; /** * Class SubscriptionHelper @@ -342,4 +343,30 @@ class SubscriptionHelper { return ''; } + + /** + * Checks if any subscription products exist. + * + * @return bool + */ + public function has_subscription_products(): bool { + // Query for subscription products. + $args = array( + 'post_type' => 'product', + 'post_status' => 'publish', + 'posts_per_page' => 1, + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query + 'tax_query' => array( + array( + 'taxonomy' => 'product_type', + 'field' => 'slug', + 'terms' => 'subscription', + ), + ), + ); + + $subscription_products = new WP_Query( $args ); + + return $subscription_products->have_posts(); + } }