From a3989401de978a6de3a40dde8de67d14403c2a2a Mon Sep 17 00:00:00 2001 From: Himad M Date: Thu, 19 Dec 2024 14:36:26 +0100 Subject: [PATCH] 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 array( 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', + ), ); /**