From 03e34328f9fcb6b140eea9e58983d132e8d3f24a Mon Sep 17 00:00:00 2001 From: David Remer Date: Wed, 19 Aug 2020 09:35:48 +0300 Subject: [PATCH] show messages only for US merchants --- modules.local/ppcp-button/services.php | 8 ++- .../ppcp-button/src/Assets/SmartButton.php | 11 +++- .../ppcp-button/src/Helper/MessagesApply.php | 22 +++++++ modules.local/ppcp-wc-gateway/services.php | 59 ++++++++++--------- .../src/Settings/SettingsRenderer.php | 17 +++++- 5 files changed, 85 insertions(+), 32 deletions(-) create mode 100644 modules.local/ppcp-button/src/Helper/MessagesApply.php diff --git a/modules.local/ppcp-button/services.php b/modules.local/ppcp-button/services.php index cffe3a967..6fa9b6bee 100644 --- a/modules.local/ppcp-button/services.php +++ b/modules.local/ppcp-button/services.php @@ -14,6 +14,7 @@ use Inpsyde\PayPalCommerce\Button\Endpoint\CreateOrderEndpoint; use Inpsyde\PayPalCommerce\Button\Endpoint\DataClientIdEndpoint; use Inpsyde\PayPalCommerce\Button\Endpoint\RequestData; use Inpsyde\PayPalCommerce\Button\Exception\RuntimeException; +use Inpsyde\PayPalCommerce\Button\Helper\MessagesApply; use Inpsyde\PayPalCommerce\Button\Helper\ThreeDSecure; use Inpsyde\PayPalCommerce\Onboarding\Environment; use Inpsyde\PayPalCommerce\Onboarding\State; @@ -61,6 +62,7 @@ return [ $clientId = $container->get('button.client_id'); $dccApplies = $container->get('api.helpers.dccapplies'); $subscriptionHelper = $container->get('subscription.helper'); + $messagesApply = $container->get('button.helper.messages-apply'); return new SmartButton( $container->get('button.url'), $container->get('session.handler'), @@ -71,7 +73,8 @@ return [ $clientId, $requestData, $dccApplies, - $subscriptionHelper + $subscriptionHelper, + $messagesApply ); }, 'button.url' => static function (ContainerInterface $container): string { @@ -120,4 +123,7 @@ return [ 'button.helper.three-d-secure' => static function (ContainerInterface $container): ThreeDSecure { return new ThreeDSecure(); }, + 'button.helper.messages-apply' => static function (ContainerInterface $container): MessagesApply { + return new MessagesApply(); + }, ]; diff --git a/modules.local/ppcp-button/src/Assets/SmartButton.php b/modules.local/ppcp-button/src/Assets/SmartButton.php index 26ab95a51..2cb6d7111 100644 --- a/modules.local/ppcp-button/src/Assets/SmartButton.php +++ b/modules.local/ppcp-button/src/Assets/SmartButton.php @@ -14,6 +14,7 @@ use Inpsyde\PayPalCommerce\Button\Endpoint\ChangeCartEndpoint; use Inpsyde\PayPalCommerce\Button\Endpoint\CreateOrderEndpoint; use Inpsyde\PayPalCommerce\Button\Endpoint\DataClientIdEndpoint; use Inpsyde\PayPalCommerce\Button\Endpoint\RequestData; +use Inpsyde\PayPalCommerce\Button\Helper\MessagesApply; use Inpsyde\PayPalCommerce\Session\SessionHandler; use Inpsyde\PayPalCommerce\Subscription\Helper\SubscriptionHelper; use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings; @@ -30,6 +31,7 @@ class SmartButton implements SmartButtonInterface private $requestData; private $dccApplies; private $subscriptionHelper; + private $messagesApply; public function __construct( string $moduleUrl, @@ -41,7 +43,8 @@ class SmartButton implements SmartButtonInterface string $clientId, RequestData $requestData, DccApplies $dccApplies, - SubscriptionHelper $subscriptionHelper + SubscriptionHelper $subscriptionHelper, + MessagesApply $messagesApply ) { $this->moduleUrl = $moduleUrl; @@ -54,6 +57,7 @@ class SmartButton implements SmartButtonInterface $this->requestData = $requestData; $this->dccApplies = $dccApplies; $this->subscriptionHelper = $subscriptionHelper; + $this->messagesApply = $messagesApply; } // phpcs:disable Inpsyde.CodeQuality.FunctionLength.TooLong @@ -514,7 +518,10 @@ class SmartButton implements SmartButtonInterface private function components(): array { - $components = ['buttons', 'messages']; + $components = ['buttons']; + if ($this->messagesApply->forCountry()) { + $components[] = 'messages'; + } if ($this->dccIsEnabled()) { $components[] = 'hosted-fields'; } diff --git a/modules.local/ppcp-button/src/Helper/MessagesApply.php b/modules.local/ppcp-button/src/Helper/MessagesApply.php new file mode 100644 index 000000000..8ab6372a3 --- /dev/null +++ b/modules.local/ppcp-button/src/Helper/MessagesApply.php @@ -0,0 +1,22 @@ +countries, true); + } +} \ No newline at end of file diff --git a/modules.local/ppcp-wc-gateway/services.php b/modules.local/ppcp-wc-gateway/services.php index 785d77caf..8210d16fc 100644 --- a/modules.local/ppcp-wc-gateway/services.php +++ b/modules.local/ppcp-wc-gateway/services.php @@ -75,7 +75,14 @@ return [ $state = $container->get('onboarding.state'); $fields = $container->get('wcgateway.settings.fields'); $dccApplies = $container->get('api.helpers.dccapplies'); - return new SettingsRenderer($settings, $state, $fields, $dccApplies); + $messagesApply = $container->get('button.helper.messages-apply'); + return new SettingsRenderer( + $settings, + $state, + $fields, + $dccApplies, + $messagesApply + ); }, 'wcgateway.settings.listener' => static function (ContainerInterface $container): SettingsListener { $settings = $container->get('wcgateway.settings'); @@ -565,7 +572,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], 'message_enabled' => [ @@ -577,7 +584,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], 'message_layout' => [ @@ -598,7 +605,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], 'message_logo' => [ @@ -621,7 +628,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], 'message_position' => [ @@ -643,7 +650,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], 'message_color' => [ @@ -666,7 +673,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], 'message_flex_color' => [ @@ -692,7 +699,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], 'message_flex_ratio' => [ @@ -715,7 +722,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], @@ -855,7 +862,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], 'message_product_enabled' => [ @@ -867,7 +874,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], 'message_product_layout' => [ @@ -888,7 +895,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], 'message_product_logo' => [ @@ -911,7 +918,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], 'message_product_position' => [ @@ -933,7 +940,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], 'message_product_color' => [ @@ -956,7 +963,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], 'message_product_flex_color' => [ @@ -982,7 +989,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], 'message_product_flex_ratio' => [ @@ -1005,7 +1012,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], @@ -1267,8 +1274,6 @@ return [ 'gateway' => 'paypal', ], - - 'message_cart_heading' => [ 'heading' => __('Message on Cart', 'woocommerce-paypal-commerce-gateway'), 'type' => 'ppcp-heading', @@ -1276,7 +1281,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], 'message_cart_enabled' => [ @@ -1288,7 +1293,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], 'message_cart_layout' => [ @@ -1309,7 +1314,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], 'message_cart_logo' => [ @@ -1332,7 +1337,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], 'message_cart_position' => [ @@ -1354,7 +1359,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], 'message_cart_color' => [ @@ -1377,7 +1382,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], 'message_cart_flex_color' => [ @@ -1403,7 +1408,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], 'message_cart_flex_ratio' => [ @@ -1426,7 +1431,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], - 'requirements' => [], + 'requirements' => ['messages'], 'gateway' => 'paypal', ], diff --git a/modules.local/ppcp-wc-gateway/src/Settings/SettingsRenderer.php b/modules.local/ppcp-wc-gateway/src/Settings/SettingsRenderer.php index 27c2257c2..ae446e507 100644 --- a/modules.local/ppcp-wc-gateway/src/Settings/SettingsRenderer.php +++ b/modules.local/ppcp-wc-gateway/src/Settings/SettingsRenderer.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Inpsyde\PayPalCommerce\WcGateway\Settings; use Inpsyde\PayPalCommerce\ApiClient\Helper\DccApplies; +use Inpsyde\PayPalCommerce\Button\Helper\MessagesApply; use Inpsyde\PayPalCommerce\Onboarding\State; use Psr\Container\ContainerInterface; @@ -15,17 +16,20 @@ class SettingsRenderer private $state; private $fields; private $dccApplies; + private $messagesApply; public function __construct( ContainerInterface $settings, State $state, array $fields, - DccApplies $dccApplies + DccApplies $dccApplies, + MessagesApply $messagesApply ) { $this->settings = $settings; $this->state = $state; $this->fields = $fields; $this->dccApplies = $dccApplies; + $this->messagesApply = $messagesApply; } //phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType @@ -140,7 +144,16 @@ class SettingsRenderer if (! $isDcc && ! in_array($config['gateway'], ['all', 'paypal'], true)) { continue; } - if (in_array('dcc', $config['requirements'], true) && ! $this->dccApplies->forCountryCurrency()) { + if ( + in_array('dcc', $config['requirements'], true) + && ! $this->dccApplies->forCountryCurrency() + ) { + continue; + } + if ( + in_array('messages', $config['requirements'], true) + && ! $this->messagesApply->forCountry() + ) { continue; } $value = $this->settings->has($field) ? $this->settings->get($field) : null;