mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
show messages only for US merchants
This commit is contained in:
parent
54652951bb
commit
03e34328f9
5 changed files with 85 additions and 32 deletions
|
@ -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();
|
||||
},
|
||||
];
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
|
|
22
modules.local/ppcp-button/src/Helper/MessagesApply.php
Normal file
22
modules.local/ppcp-button/src/Helper/MessagesApply.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\PayPalCommerce\Button\Helper;
|
||||
|
||||
|
||||
use Inpsyde\PayPalCommerce\ApiClient\Helper\DccApplies;
|
||||
|
||||
class MessagesApply
|
||||
{
|
||||
|
||||
private $countries = [
|
||||
'US',
|
||||
];
|
||||
public function forCountry() : bool
|
||||
{
|
||||
|
||||
$region = wc_get_base_location();
|
||||
$country = $region['country'];
|
||||
return in_array($country, $this->countries, true);
|
||||
}
|
||||
}
|
|
@ -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',
|
||||
],
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue