From 4139da3024199be38bb6a99b6f2127e04589bf45 Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Fri, 13 Dec 2024 21:02:54 +0100 Subject: [PATCH] move getUserIdForVaulting to Config --- .../PayPalVaultingCardController.php | 3 ++- src/Controller/PayPalVaultingController.php | 3 ++- src/Core/Config.php | 15 +++++++++++++++ src/Core/ViewConfig.php | 15 +++++++++++++++ src/Traits/AccountControllerTrait.php | 18 ------------------ 5 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/Controller/PayPalVaultingCardController.php b/src/Controller/PayPalVaultingCardController.php index 0febcff4..04d5ea51 100644 --- a/src/Controller/PayPalVaultingCardController.php +++ b/src/Controller/PayPalVaultingCardController.php @@ -3,6 +3,7 @@ namespace OxidSolutionCatalysts\PayPal\Controller; use OxidEsales\Eshop\Application\Controller\AccountController; +use OxidSolutionCatalysts\PayPal\Core\Config; use OxidSolutionCatalysts\PayPal\Service\ModuleSettings; use OxidSolutionCatalysts\PayPal\Traits\AccountControllerTrait; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; @@ -17,7 +18,7 @@ class PayPalVaultingCardController extends AccountController public function render() { - $this->_aViewData['vaultingUserId'] = $this->getUserIdForVaulting(); + $this->_aViewData['vaultingUserId'] = oxNew(Config::class)->getUserIdForVaulting(); $moduleSettings = $this->getServiceFromContainer(ModuleSettings::class); if ($moduleSettings->isVaultingAllowedForACDC()) { diff --git a/src/Controller/PayPalVaultingController.php b/src/Controller/PayPalVaultingController.php index 936da247..3a0be289 100644 --- a/src/Controller/PayPalVaultingController.php +++ b/src/Controller/PayPalVaultingController.php @@ -3,6 +3,7 @@ namespace OxidSolutionCatalysts\PayPal\Controller; use OxidEsales\Eshop\Application\Controller\AccountController; +use OxidSolutionCatalysts\PayPal\Core\Config; use OxidSolutionCatalysts\PayPal\Service\ModuleSettings; use OxidSolutionCatalysts\PayPal\Traits\AccountControllerTrait; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; @@ -17,7 +18,7 @@ class PayPalVaultingController extends AccountController public function render() { - $this->_aViewData['vaultingUserId'] = $this->getUserIdForVaulting(); + $this->_aViewData['vaultingUserId'] = oxNew(Config::class)->getUserIdForVaulting(); $moduleSettings = $this->getServiceFromContainer(ModuleSettings::class); if ($moduleSettings->isVaultingAllowedForPayPal()) { diff --git a/src/Core/Config.php b/src/Core/Config.php index e6ddd228..50ac9bd8 100755 --- a/src/Core/Config.php +++ b/src/Core/Config.php @@ -462,6 +462,21 @@ public function getIsVaultingActive(): bool return $this->getServiceFromContainer(ModuleSettings::class)->getIsVaultingActive(); } + public function getUserIdForVaulting(): string + { + $user = Registry::getConfig()->getUser(); + $payPalCustomerId = $user ? $user->getFieldData("oscpaypalcustomerid") : ''; + + if (!$payPalCustomerId) { + return ""; + } + + $vaultingService = Registry::get(ServiceFactory::class)->getVaultingService(); + $response = $vaultingService->generateUserIdToken($payPalCustomerId); + + return $response["id_token"] ?? ""; + } + public function getIsGooglePayDeliveryAdressActive(): bool { return $this->getServiceFromContainer(ModuleSettings::class)->getIsGooglePayDeliveryAddressActive(); diff --git a/src/Core/ViewConfig.php b/src/Core/ViewConfig.php index a5c97dc2..d4772334 100644 --- a/src/Core/ViewConfig.php +++ b/src/Core/ViewConfig.php @@ -264,6 +264,21 @@ public function showPayPalExpressInMiniBasket(): bool return $showButton; } + public function getUserIdForVaulting(): string + { + return oxNew(Config::class)->getUserIdForVaulting(); + } + + public function isVaultingAllowedForPayPal(): bool + { + return $this->getServiceFromContainer(ModuleSettings::class)->isVaultingAllowedForPayPal(); + } + + public function isVaultingAllowedForACDC(): bool + { + return $this->getServiceFromContainer(ModuleSettings::class)->isVaultingAllowedForACDC(); + } + /** * get Session Vault Success * diff --git a/src/Traits/AccountControllerTrait.php b/src/Traits/AccountControllerTrait.php index e36c1001..5d21bc8c 100644 --- a/src/Traits/AccountControllerTrait.php +++ b/src/Traits/AccountControllerTrait.php @@ -27,22 +27,4 @@ public function deleteVaultedPayment() ); } } - - public function getUserIdForVaulting(): string - { - if (!$this->getUser()) { - return ""; - } - - $payPalCustomerId = $this->getUser()->getFieldData("oscpaypalcustomerid"); - - if (!$payPalCustomerId) { - return ""; - } - - $vaultingService = Registry::get(ServiceFactory::class)->getVaultingService(); - $response = $vaultingService->generateUserIdToken($payPalCustomerId); - - return $response["id_token"] ?? ""; - } }