diff --git a/modules.local/ppcp-button/services.php b/modules.local/ppcp-button/services.php index c9cadc79d..a2a1076ba 100644 --- a/modules.local/ppcp-button/services.php +++ b/modules.local/ppcp-button/services.php @@ -56,6 +56,7 @@ return [ $requestData = $container->get('button.request-data'); $clientId = $container->get('button.client_id'); + $dccApplies = $container->get('api.helpers.dccapplies'); return new SmartButton( $container->get('button.url'), $container->get('session.handler'), @@ -64,7 +65,8 @@ return [ $identityToken, $payerFactory, $clientId, - $requestData + $requestData, + $dccApplies ); }, 'button.url' => static function (ContainerInterface $container): string { diff --git a/modules.local/ppcp-button/src/Assets/SmartButton.php b/modules.local/ppcp-button/src/Assets/SmartButton.php index 0a55842bd..565610025 100644 --- a/modules.local/ppcp-button/src/Assets/SmartButton.php +++ b/modules.local/ppcp-button/src/Assets/SmartButton.php @@ -7,6 +7,7 @@ namespace Inpsyde\PayPalCommerce\Button\Assets; use Inpsyde\PayPalCommerce\ApiClient\Endpoint\IdentityToken; use Inpsyde\PayPalCommerce\ApiClient\Exception\RuntimeException; use Inpsyde\PayPalCommerce\ApiClient\Factory\PayerFactory; +use Inpsyde\PayPalCommerce\ApiClient\Helper\DccApplies; use Inpsyde\PayPalCommerce\ApiClient\Repository\PayeeRepository; use Inpsyde\PayPalCommerce\Button\Endpoint\ApproveOrderEndpoint; use Inpsyde\PayPalCommerce\Button\Endpoint\ChangeCartEndpoint; @@ -25,6 +26,7 @@ class SmartButton implements SmartButtonInterface private $payerFactory; private $clientId; private $requestData; + private $dccApplies; public function __construct( string $moduleUrl, @@ -34,7 +36,8 @@ class SmartButton implements SmartButtonInterface IdentityToken $identityToken, PayerFactory $payerFactory, string $clientId, - RequestData $requestData + RequestData $requestData, + DccApplies $dccApplies ) { $this->moduleUrl = $moduleUrl; @@ -45,6 +48,7 @@ class SmartButton implements SmartButtonInterface $this->payerFactory = $payerFactory; $this->clientId = $clientId; $this->requestData = $requestData; + $this->dccApplies = $dccApplies; } // phpcs:disable Inpsyde.CodeQuality.FunctionLength.TooLong @@ -70,7 +74,7 @@ class SmartButton implements SmartButtonInterface echo '
'; }; - $canRenderDcc = $this->settings->has('client_id') && $this->settings->get('client_id'); + $canRenderDcc = $this->dccApplies->forCountryCurrency() && $this->settings->has('client_id') && $this->settings->get('client_id'); $dccRenderer = static function (bool $miniCart = false) use ($canRenderDcc) { $id = ($miniCart) ? 'ppcp-hosted-fields-mini-cart' : 'ppcp-hosted-fields'; if (! $canRenderDcc) { @@ -305,7 +309,7 @@ class SmartButton implements SmartButtonInterface 'integration-date' => date('Y-m-d'), 'components' => implode(',', $this->components()), //ToDo: Probably only needed, when DCC - 'vault' => is_user_logged_in() ? 'true' : 'false', + 'vault' => $this->dccIsEnabled() ? 'true' : 'false', 'commit' => is_checkout() ? 'true' : 'false', 'intent' => ($this->settings->has('intent')) ? $this->settings->get('intent') : 'capture', ]; @@ -331,7 +335,7 @@ class SmartButton implements SmartButtonInterface 'data-partner-attribution-id' => $this->bnCodeForContext($this->context()), ]; try { - if (! is_user_logged_in()) { + if (! is_user_logged_in() || ! $this->dccIsEnabled()) { return $attributes; } $clientToken = $this->identityToken->generateForCustomer((int) get_current_user_id()); @@ -395,6 +399,9 @@ class SmartButton implements SmartButtonInterface private function dccIsEnabled(): bool { + if (! $this->dccApplies->forCountryCurrency()) { + return false; + } $keys = [ 'dcc_cart_enabled', 'dcc_mini_cart_enabled', diff --git a/modules.local/ppcp-wc-gateway/services.php b/modules.local/ppcp-wc-gateway/services.php index 47a5b5838..ef08d7676 100644 --- a/modules.local/ppcp-wc-gateway/services.php +++ b/modules.local/ppcp-wc-gateway/services.php @@ -57,7 +57,8 @@ return [ $settings = $container->get('wcgateway.settings'); $state = $container->get('onboarding.state'); $fields = $container->get('wcgateway.settings.fields'); - return new SettingsRenderer($settings, $state, $fields); + $dccApplies = $container->get('api.helpers.dccapplies'); + return new SettingsRenderer($settings, $state, $fields, $dccApplies); }, 'wcgateway.settings.listener' => static function (ContainerInterface $container): SettingsListener { $settings = $container->get('wcgateway.settings'); @@ -133,6 +134,7 @@ return [ 'screens' => [ State::STATE_PROGRESSIVE, ], + 'requirements' => [], ], 'sandbox_on' => [ 'title' => __('Sandbox', 'woocommerce-paypal-commerce-gateway'), @@ -142,6 +144,7 @@ return [ 'screens' => [ State::STATE_START, ], + 'requirements' => [], ], 'sandbox_on_info' => [ 'title' => __('Sandbox', 'woocommerce-paypal-commerce-gateway'), @@ -152,6 +155,7 @@ return [ State::STATE_ONBOARDED, ], 'hidden' => 'sandbox_on', + 'requirements' => [], ], 'merchant_email' => [ 'title' => __('Email address', 'woocommerce-paypal-commerce-gateway'), @@ -162,6 +166,7 @@ return [ 'screens' => [ State::STATE_START, ], + 'requirements' => [], ], 'merchant_email_info' => [ 'title' => __('Email address', 'woocommerce-paypal-commerce-gateway'), @@ -172,6 +177,7 @@ return [ State::STATE_ONBOARDED, ], 'hidden' => 'merchant_email', + 'requirements' => [], ], 'title' => [ 'title' => __('Title', 'woocommerce-paypal-commerce-gateway'), @@ -186,6 +192,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], + 'requirements' => [], ], 'description' => [ 'title' => __('Description', 'woocommerce-paypal-commerce-gateway'), @@ -203,6 +210,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], + 'requirements' => [], ], 'intent' => [ 'title' => __('Intent', 'woocommerce-paypal-commerce-gateway'), @@ -221,6 +229,7 @@ return [ 'screens' => [ State::STATE_ONBOARDED, ], + 'requirements' => [], ], 'button_single_product_enabled' => [ 'title' => __('Buttons on Single Product', 'woocommerce-paypal-commerce-gateway'), @@ -231,6 +240,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], + 'requirements' => [], ], 'button_mini_cart_enabled' => [ 'title' => __('Buttons on Mini Cart', 'woocommerce-paypal-commerce-gateway'), @@ -241,6 +251,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], + 'requirements' => [], ], 'button_cart_enabled' => [ 'title' => __('Buttons on Cart', 'woocommerce-paypal-commerce-gateway'), @@ -251,6 +262,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], + 'requirements' => [], ], 'button_label' => [ 'title' => __('Button Label', 'woocommerce-paypal-commerce-gateway'), @@ -272,6 +284,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], + 'requirements' => [], ], 'brand_name' => [ 'title' => __('Brand Name', 'woocommerce-paypal-commerce-gateway'), @@ -286,6 +299,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], + 'requirements' => [], ], 'landing_page' => [ 'title' => __('Landing Page', 'woocommerce-paypal-commerce-gateway'), @@ -305,6 +319,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], + 'requirements' => [], ], 'button_color' => [ 'title' => __('Color', 'woocommerce-paypal-commerce-gateway'), @@ -326,6 +341,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], + 'requirements' => [], ], 'button_shape' => [ 'title' => __('Shape', 'woocommerce-paypal-commerce-gateway'), @@ -345,6 +361,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], + 'requirements' => [], ], 'disable_funding' => [ 'title' => __('Disable funding sources', 'woocommerce-paypal-commerce-gateway'), @@ -373,6 +390,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], + 'requirements' => [], ], 'dcc_cart_enabled' => [ 'title' => __('Enable credit card on cart', 'woocommerce-paypal-commerce-gateway'), @@ -382,6 +400,9 @@ return [ 'screens' => [ State::STATE_ONBOARDED, ], + 'requirements' => [ + 'dcc', + ], ], 'dcc_mini_cart_enabled' => [ 'title' => __('Enable credit card on mini cart', 'woocommerce-paypal-commerce-gateway'), @@ -391,6 +412,9 @@ return [ 'screens' => [ State::STATE_ONBOARDED, ], + 'requirements' => [ + 'dcc', + ], ], 'dcc_checkout_enabled' => [ 'title' => __('Enable credit card on checkout', 'woocommerce-paypal-commerce-gateway'), @@ -400,6 +424,9 @@ return [ 'screens' => [ State::STATE_ONBOARDED, ], + 'requirements' => [ + 'dcc', + ], ], 'dcc_single_product_enabled' => [ 'title' => __('Enable credit card on products', 'woocommerce-paypal-commerce-gateway'), @@ -409,6 +436,9 @@ return [ 'screens' => [ State::STATE_ONBOARDED, ], + 'requirements' => [ + 'dcc', + ], ], 'disable_cards' => [ 'title' => __('Disable specific credid cards', 'woocommerce-paypal-commerce-gateway'), @@ -432,6 +462,9 @@ return [ 'screens' => [ State::STATE_ONBOARDED, ], + 'requirements' => [ + 'dcc', + ], ], 'logging_enabled' => [ 'title' => __('Logging', 'woocommerce-paypal-commerce-gateway'), @@ -445,6 +478,7 @@ return [ State::STATE_PROGRESSIVE, State::STATE_ONBOARDED, ], + 'requirements' => [], ], ]; }, diff --git a/modules.local/ppcp-wc-gateway/src/Settings/SettingsRenderer.php b/modules.local/ppcp-wc-gateway/src/Settings/SettingsRenderer.php index 84d5b12c9..2de0d61fc 100644 --- a/modules.local/ppcp-wc-gateway/src/Settings/SettingsRenderer.php +++ b/modules.local/ppcp-wc-gateway/src/Settings/SettingsRenderer.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Inpsyde\PayPalCommerce\WcGateway\Settings; +use Inpsyde\PayPalCommerce\ApiClient\Helper\DccApplies; use Inpsyde\PayPalCommerce\Onboarding\State; use Psr\Container\ContainerInterface; @@ -13,15 +14,18 @@ class SettingsRenderer private $settings; private $state; private $fields; + private $dccApplies; public function __construct( ContainerInterface $settings, State $state, - array $fields + array $fields, + DccApplies $dccApplies ) { $this->settings = $settings; $this->state = $state; $this->fields = $fields; + $this->dccApplies = $dccApplies; } //phpcs:disable Inpsyde.CodeQuality.ArgumentTypeDeclaration.NoArgumentType @@ -67,6 +71,9 @@ class SettingsRenderer if (! in_array($this->state->currentState(), $config['screens'], true)) { continue; } + if (in_array('dcc', $config['requirements'], true) && ! $this->dccApplies->forCountryCurrency()) { + continue; + } $value = $this->settings->has($field) ? $this->settings->get($field) : null; $id = 'ppcp[' . $field . ']'; ?>