Skip to content

Commit

Permalink
move getUserIdForVaulting to Config
Browse files Browse the repository at this point in the history
  • Loading branch information
mariolorenz committed Dec 13, 2024
1 parent b20f652 commit 4139da3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/Controller/PayPalVaultingCardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()) {
Expand Down
3 changes: 2 additions & 1 deletion src/Controller/PayPalVaultingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()) {
Expand Down
15 changes: 15 additions & 0 deletions src/Core/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 15 additions & 0 deletions src/Core/ViewConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
18 changes: 0 additions & 18 deletions src/Traits/AccountControllerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"] ?? "";
}
}

0 comments on commit 4139da3

Please sign in to comment.