diff --git a/src/Service/ModuleSettings.php b/src/Service/ModuleSettings.php index a3295111..1ca002d3 100755 --- a/src/Service/ModuleSettings.php +++ b/src/Service/ModuleSettings.php @@ -10,6 +10,7 @@ namespace OxidSolutionCatalysts\PayPal\Service; use OxidEsales\Eshop\Application\Model\Country; +use OxidEsales\Eshop\Application\Model\DeliverySetList; use OxidEsales\Eshop\Application\Model\Payment; use OxidEsales\Eshop\Application\Model\Shop; use OxidEsales\Eshop\Application\Model\User; @@ -80,6 +81,9 @@ class ModuleSettings /** @var Logger */ private $logger; + /** @var UserRepository */ + private $userRepository; + //TODO: we need service for fetching module settings from db (this one) //another class for moduleconfiguration (database values/edefaults) //and the view configuration should go into some separate class @@ -89,12 +93,14 @@ public function __construct( ModuleSettingBridgeInterface $moduleSettingBridge, ContextInterface $context, ModuleConfigurationDaoBridgeInterface $moduleConfigurationDaoBridgeInterface, - Logger $logger + Logger $logger, + UserRepository $userRepository ) { $this->moduleSettingBridge = $moduleSettingBridge; $this->context = $context; $this->moduleConfigurationDaoBridgeInterface = $moduleConfigurationDaoBridgeInterface; $this->logger = $logger; + $this->userRepository = $userRepository; } public function showAllPayPalBanners(): bool @@ -626,9 +632,34 @@ public function isVaultingAllowedForPayment(string $paymentId): bool $payment->load($paymentId); $paymentEnabled = (bool)$payment->oxpayments__oxactive->value; $paymentType = PayPalDefinitions::getPayPalDefinitions()[$paymentId]["vaultingtype"]; + + $session = Registry::getSession(); + $actShipSet = $session->getVariable('sShipSet'); + $basket = $session->getBasket(); + $user = $session->getUser(); + $payPalDefinitions = PayPalDefinitions::getPayPalDefinitions(); + $actShopCurrency = Registry::getConfig()->getActShopCurrencyObject(); + $userCountryIso = $this->userRepository->getUserCountryIso(); + + [, , $paymentList] = + Registry::get(DeliverySetList::class)->getDeliverySetData( + $actShipSet, + $user, + $basket + ); + return $paymentEnabled && $this->getIsVaultingActive() && - PayPalDefinitions::isPayPalVaultingPossible($paymentId, $paymentType); + PayPalDefinitions::isPayPalVaultingPossible($paymentId, $paymentType) && + array_key_exists($paymentId, $paymentList) && + ( + empty($payPalDefinitions[$paymentId]['currencies']) || + in_array($actShopCurrency->name, $payPalDefinitions[$paymentId]['currencies'], true) + ) && + ( + empty($payPalDefinitions[$paymentId]['countries']) || + in_array($userCountryIso, $payPalDefinitions[$paymentId]['countries'], true) + ); } /** diff --git a/src/Traits/AccountControllerTrait.php b/src/Traits/AccountControllerTrait.php index 5d21bc8c..51dfea57 100644 --- a/src/Traits/AccountControllerTrait.php +++ b/src/Traits/AccountControllerTrait.php @@ -14,7 +14,7 @@ trait AccountControllerTrait { - public function deleteVaultedPayment() + public function deleteVaultedPayment(): void { $paymentTokenId = Registry::getRequest()->getRequestEscapedParameter("paymentTokenId"); $vaultingService = Registry::get(ServiceFactory::class)->getVaultingService();