Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check if Payment limited by Country or UserGroup ... #373

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading