Skip to content

Commit

Permalink
Merge pull request #373 from OXID-eSales/PSPAYPAL-817_Vaulting
Browse files Browse the repository at this point in the history
Add check if Payment limited by Country or UserGroup ...
  • Loading branch information
mariolorenz authored Dec 17, 2024
2 parents 7d5354b + 845def3 commit 1b668c5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
35 changes: 33 additions & 2 deletions src/Service/ModuleSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/AccountControllerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

trait AccountControllerTrait
{
public function deleteVaultedPayment()
public function deleteVaultedPayment(): void
{
$paymentTokenId = Registry::getRequest()->getRequestEscapedParameter("paymentTokenId");
$vaultingService = Registry::get(ServiceFactory::class)->getVaultingService();
Expand Down

0 comments on commit 1b668c5

Please sign in to comment.