From a3989401de978a6de3a40dde8de67d14403c2a2a Mon Sep 17 00:00:00 2001 From: Himad M Date: Thu, 19 Dec 2024 14:36:26 +0100 Subject: [PATCH 01/14] New Settings UI: Disable settings in send-only countries --- .../js/Components/Screens/SendOnlyMessage.js | 16 ++++++++++++++++ .../resources/js/Components/Screens/Settings.js | 7 +++++++ modules/ppcp-settings/services.php | 1 + .../ppcp-settings/src/Data/CommonSettings.php | 8 +++++--- .../src/Endpoint/CommonRestEndpoint.php | 11 +++++++---- 5 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 modules/ppcp-settings/resources/js/Components/Screens/SendOnlyMessage.js diff --git a/modules/ppcp-settings/resources/js/Components/Screens/SendOnlyMessage.js b/modules/ppcp-settings/resources/js/Components/Screens/SendOnlyMessage.js new file mode 100644 index 000000000..967a3f7cd --- /dev/null +++ b/modules/ppcp-settings/resources/js/Components/Screens/SendOnlyMessage.js @@ -0,0 +1,16 @@ +const SendOnlyMessage = () => { + return ( +

+ Your current WooCommerce store location is in a "send-only" country, + according to PayPal's policies. Sellers in these countries are + unable to receive payments via PayPal. Since receiving payments is + essential for using the PayPal Payments extension, you will not be + able to connect your PayPal account while operating from a + "send-only" country. To activate PayPal, please update your + WooCommerce store location to a supported region and connect a + PayPal account eligible for receiving payments. +

+ ); +}; + +export default SendOnlyMessage; diff --git a/modules/ppcp-settings/resources/js/Components/Screens/Settings.js b/modules/ppcp-settings/resources/js/Components/Screens/Settings.js index bc79b34b3..112200e87 100644 --- a/modules/ppcp-settings/resources/js/Components/Screens/Settings.js +++ b/modules/ppcp-settings/resources/js/Components/Screens/Settings.js @@ -7,9 +7,12 @@ import SpinnerOverlay from '../ReusableComponents/SpinnerOverlay'; import Onboarding from './Onboarding/Onboarding'; import SettingsScreen from './SettingsScreen'; +import { useMerchantInfo } from '../../data/common/hooks'; +import SendOnlyMessage from './SendOnlyMessage'; const Settings = () => { const onboardingProgress = OnboardingHooks.useSteps(); + const { merchant } = useMerchantInfo(); // Disable the "Changes you made might not be saved" browser warning. useEffect( () => { @@ -38,6 +41,10 @@ const Settings = () => { ); } + if ( merchant.isCurrentCountrySendOnly ) { + return ; + } + if ( ! onboardingProgress.completed ) { return ; } diff --git a/modules/ppcp-settings/services.php b/modules/ppcp-settings/services.php index 349c13350..9629fd8dd 100644 --- a/modules/ppcp-settings/services.php +++ b/modules/ppcp-settings/services.php @@ -63,6 +63,7 @@ return new CommonSettings( $container->get( 'api.shop.country' ), $container->get( 'api.shop.currency.getter' )->get(), + $container->get( 'wcgateway.is-send-only-country' ) ); }, 'settings.rest.onboarding' => static function ( ContainerInterface $container ) : OnboardingRestEndpoint { diff --git a/modules/ppcp-settings/src/Data/CommonSettings.php b/modules/ppcp-settings/src/Data/CommonSettings.php index 1894255ff..cee01f881 100644 --- a/modules/ppcp-settings/src/Data/CommonSettings.php +++ b/modules/ppcp-settings/src/Data/CommonSettings.php @@ -41,11 +41,13 @@ class CommonSettings extends AbstractDataModel { * * @param string $country WooCommerce store country. * @param string $currency WooCommerce store currency. + * @param bool $is_current_country_send_only Indicates whether the current store's country is classified as a send-only country. */ - public function __construct( string $country, string $currency ) { + public function __construct( string $country, string $currency, bool $is_current_country_send_only ) { parent::__construct(); - $this->woo_settings['country'] = $country; - $this->woo_settings['currency'] = $currency; + $this->woo_settings['country'] = $country; + $this->woo_settings['currency'] = $currency; + $this->data['is_current_country_send_only'] = $is_current_country_send_only; } /** diff --git a/modules/ppcp-settings/src/Endpoint/CommonRestEndpoint.php b/modules/ppcp-settings/src/Endpoint/CommonRestEndpoint.php index 7524e7e31..178814e8d 100644 --- a/modules/ppcp-settings/src/Endpoint/CommonRestEndpoint.php +++ b/modules/ppcp-settings/src/Endpoint/CommonRestEndpoint.php @@ -66,18 +66,21 @@ class CommonRestEndpoint extends RestEndpoint { * @var array */ private array $merchant_info_map = array( - 'merchant_connected' => array( + 'merchant_connected' => array( 'js_name' => 'isConnected', ), - 'sandbox_merchant' => array( + 'sandbox_merchant' => array( 'js_name' => 'isSandbox', ), - 'merchant_id' => array( + 'merchant_id' => array( 'js_name' => 'id', ), - 'merchant_email' => array( + 'merchant_email' => array( 'js_name' => 'email', ), + 'is_current_country_send_only' => array( + 'js_name' => 'isCurrentCountrySendOnly', + ), ); /** From 9278edff2256d2078ddb3b9d15398f6fdfc07d9f Mon Sep 17 00:00:00 2001 From: Himad M Date: Thu, 26 Dec 2024 13:22:17 +0100 Subject: [PATCH 02/14] New Settings UI: Adjust send-only country message and notices --- .../src/PayLaterConfiguratorModule.php | 12 ++++++++-- .../js/Components/Screens/SendOnlyMessage.js | 24 ++++++++++--------- modules/ppcp-wc-gateway/services.php | 7 +++--- .../src/Notice/ConnectAdminNotice.php | 17 +++++++++---- 4 files changed, 40 insertions(+), 20 deletions(-) diff --git a/modules/ppcp-paylater-configurator/src/PayLaterConfiguratorModule.php b/modules/ppcp-paylater-configurator/src/PayLaterConfiguratorModule.php index 2c13bed71..1506ef829 100644 --- a/modules/ppcp-paylater-configurator/src/PayLaterConfiguratorModule.php +++ b/modules/ppcp-paylater-configurator/src/PayLaterConfiguratorModule.php @@ -9,6 +9,7 @@ namespace WooCommerce\PayPalCommerce\PayLaterConfigurator; +use WooCommerce\PayPalCommerce\Onboarding\State; use WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint\GetConfig; use WooCommerce\PayPalCommerce\PayLaterConfigurator\Endpoint\SaveConfig; use WooCommerce\PayPalCommerce\PayLaterConfigurator\Factory\ConfigFactory; @@ -68,8 +69,9 @@ static function () use ( $c ) { $current_page_id = $c->get( 'wcgateway.current-ppcp-settings-page-id' ); $is_wc_settings_page = $c->get( 'wcgateway.is-wc-settings-page' ); $messaging_locations = $c->get( 'paylater-configurator.messaging-locations' ); + $onboarding_state = $c->get( 'onboarding.state' ); - self::add_paylater_update_notice( $messaging_locations, $is_wc_settings_page, $current_page_id ); + self::add_paylater_update_notice( $messaging_locations, $is_wc_settings_page, $current_page_id, $onboarding_state ); $settings = $c->get( 'wcgateway.settings' ); assert( $settings instanceof Settings ); @@ -162,10 +164,16 @@ static function () use ( $c ) { * @param array $message_locations PayLater messaging locations. * @param bool $is_settings_page Whether the current page is a WC settings page. * @param string $current_page_id ID of current settings page tab. + * @param State $onboarding_state Onboarding state. * * @return void */ - private static function add_paylater_update_notice( array $message_locations, bool $is_settings_page, string $current_page_id ) : void { + private static function add_paylater_update_notice( array $message_locations, bool $is_settings_page, string $current_page_id, State $onboarding_state ) : void { + // Don't display the notice if the user has not completed the onboarding process. + if ( $onboarding_state->current_state() !== State::STATE_ONBOARDED ) { + return; + } + // The message must be registered on any WC-Settings page, except for the Pay Later page. if ( ! $is_settings_page || Settings::PAY_LATER_TAB_ID === $current_page_id ) { return; diff --git a/modules/ppcp-settings/resources/js/Components/Screens/SendOnlyMessage.js b/modules/ppcp-settings/resources/js/Components/Screens/SendOnlyMessage.js index 967a3f7cd..884f790fc 100644 --- a/modules/ppcp-settings/resources/js/Components/Screens/SendOnlyMessage.js +++ b/modules/ppcp-settings/resources/js/Components/Screens/SendOnlyMessage.js @@ -1,16 +1,18 @@ +import { __, sprintf } from '@wordpress/i18n'; + const SendOnlyMessage = () => { - return ( -

- Your current WooCommerce store location is in a "send-only" country, - according to PayPal's policies. Sellers in these countries are - unable to receive payments via PayPal. Since receiving payments is - essential for using the PayPal Payments extension, you will not be - able to connect your PayPal account while operating from a - "send-only" country. To activate PayPal, please update your - WooCommerce store location to a supported region and connect a - PayPal account eligible for receiving payments. -

+ const settingsPageUrl = '/wp-admin/admin.php?page=wc-settings'; + + const message = sprintf( + /* translators: 1: URL to the WooCommerce store location settings */ + __( + 'Your current WooCommerce store location is in a "send-only" country, according to PayPal\'s policies. Sellers in these countries are unable to receive payments via PayPal. Since receiving payments is essential for using the PayPal Payments extension, you will not be able to connect your PayPal account while operating from a "send-only" country. To activate PayPal, please update your WooCommerce store location to a supported region and connect a PayPal account eligible for receiving payments.', + 'woocommerce-paypal-payments' + ), + settingsPageUrl ); + + return

; }; export default SendOnlyMessage; diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 9447c981e..e17c1077d 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -343,9 +343,10 @@ static function ( ContainerInterface $container ): Settings { } ), 'wcgateway.notice.connect' => static function ( ContainerInterface $container ): ConnectAdminNotice { - $state = $container->get( 'onboarding.state' ); - $settings = $container->get( 'wcgateway.settings' ); - return new ConnectAdminNotice( $state, $settings ); + $state = $container->get( 'onboarding.state' ); + $settings = $container->get( 'wcgateway.settings' ); + $is_current_country_send_only = $container->get( 'wcgateway.is-send-only-country' ); + return new ConnectAdminNotice( $state, $settings, $is_current_country_send_only ); }, 'wcgateway.notice.currency-unsupported' => static function ( ContainerInterface $container ): UnsupportedCurrencyAdminNotice { $state = $container->get( 'onboarding.state' ); diff --git a/modules/ppcp-wc-gateway/src/Notice/ConnectAdminNotice.php b/modules/ppcp-wc-gateway/src/Notice/ConnectAdminNotice.php index e8d88adec..60085a992 100644 --- a/modules/ppcp-wc-gateway/src/Notice/ConnectAdminNotice.php +++ b/modules/ppcp-wc-gateway/src/Notice/ConnectAdminNotice.php @@ -33,15 +33,24 @@ class ConnectAdminNotice { */ private $settings; + /** + * Whether the current store's country is classified as a send-only country.. + * + * @var bool + */ + private bool $is_current_country_send_only; + /** * ConnectAdminNotice constructor. * * @param State $state The state. * @param ContainerInterface $settings The settings. + * @param bool $is_current_country_send_only Whether the current store's country is classified as a send-only country. */ - public function __construct( State $state, ContainerInterface $settings ) { - $this->state = $state; - $this->settings = $settings; + public function __construct( State $state, ContainerInterface $settings, bool $is_current_country_send_only ) { + $this->state = $state; + $this->settings = $settings; + $this->is_current_country_send_only = $is_current_country_send_only; } /** @@ -71,6 +80,6 @@ public function connect_message() { * @return bool */ protected function should_display(): bool { - return $this->state->current_state() !== State::STATE_ONBOARDED; + return $this->state->current_state() !== State::STATE_ONBOARDED && $this->is_current_country_send_only === false; } } From d5e9e2aecb13675850476ad104dfece874f807aa Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Thu, 9 Jan 2025 13:02:20 +0100 Subject: [PATCH 03/14] Add isBusy property to FeatureSettings button --- .../ReusableComponents/SettingsBlocks/FeatureSettingsBlock.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/FeatureSettingsBlock.js b/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/FeatureSettingsBlock.js index 0d104a70c..e5194806f 100644 --- a/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/FeatureSettingsBlock.js +++ b/modules/ppcp-settings/resources/js/Components/ReusableComponents/SettingsBlocks/FeatureSettingsBlock.js @@ -39,6 +39,7 @@ const FeatureSettingsBlock = ( { title, description, ...props } ) => {