Skip to content

Commit

Permalink
move getUserIdForVaulting from ViewConfig to Controller-Traits
Browse files Browse the repository at this point in the history
  • Loading branch information
mariolorenz committed Dec 13, 2024
1 parent 39b9bee commit b20f652
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 53 deletions.
22 changes: 4 additions & 18 deletions src/Controller/PayPalVaultingCardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
namespace OxidSolutionCatalysts\PayPal\Controller;

use OxidEsales\Eshop\Application\Controller\AccountController;
use OxidEsales\Eshop\Core\Registry;
use OxidSolutionCatalysts\PayPal\Core\ServiceFactory;
use OxidSolutionCatalysts\PayPal\Service\ModuleSettings;
use OxidSolutionCatalysts\PayPal\Traits\AccountControllerTrait;
use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer;

/**
* user account menu for saving paypal for purchase later (vaulting without purchase)
* user account menu for saving paypal (acdc) for purchase later (vaulting without purchase)
*/
class PayPalVaultingCardController extends AccountController
{
use ServiceContainer;
use AccountControllerTrait;

public function render()
{
$this->_aViewData['vaultingUserId'] = $this->getViewConfig()->getUserIdForVaulting();
$this->_aViewData['vaultingUserId'] = $this->getUserIdForVaulting();
$moduleSettings = $this->getServiceFromContainer(ModuleSettings::class);

if ($moduleSettings->isVaultingAllowedForACDC()) {
Expand All @@ -26,18 +26,4 @@ public function render()

return parent::render();
}

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

if (!$vaultingService->deleteVaultedPayment($paymentTokenId)) {
Registry::getUtilsView()->addErrorToDisplay(
Registry::getLang()->translateString('OSC_PAYPAL_DELETE_FAILED'),
false,
true
);
}
}
}
20 changes: 3 additions & 17 deletions src/Controller/PayPalVaultingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
namespace OxidSolutionCatalysts\PayPal\Controller;

use OxidEsales\Eshop\Application\Controller\AccountController;
use OxidSolutionCatalysts\PayPal\Core\ServiceFactory;
use OxidSolutionCatalysts\PayPal\Service\ModuleSettings;
use OxidSolutionCatalysts\PayPal\Traits\AccountControllerTrait;
use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer;
use OxidEsales\Eshop\Core\Registry;

/**
* user account menu for saving paypal for purchase later (vaulting without purchase)
*/
class PayPalVaultingController extends AccountController
{
use ServiceContainer;
use AccountControllerTrait;

public function render()
{
$this->_aViewData['vaultingUserId'] = $this->getViewConfig()->getUserIdForVaulting();
$this->_aViewData['vaultingUserId'] = $this->getUserIdForVaulting();
$moduleSettings = $this->getServiceFromContainer(ModuleSettings::class);

if ($moduleSettings->isVaultingAllowedForPayPal()) {
Expand All @@ -26,18 +26,4 @@ public function render()

return parent::render();
}

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

if (!$vaultingService->deleteVaultedPayment($paymentTokenId)) {
Registry::getUtilsView()->addErrorToDisplay(
Registry::getLang()->translateString('OSC_PAYPAL_DELETE_FAILED'),
false,
true
);
}
}
}
18 changes: 0 additions & 18 deletions src/Core/ViewConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,24 +264,6 @@ public function showPayPalExpressInMiniBasket(): bool
return $showButton;
}

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"] ?? "";
}

/**
* get Session Vault Success
*
Expand Down
48 changes: 48 additions & 0 deletions src/Traits/AccountControllerTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidSolutionCatalysts\PayPal\Traits;

use OxidEsales\Eshop\Core\Registry;
use OxidSolutionCatalysts\PayPal\Core\ServiceFactory;

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

if (!$vaultingService->deleteVaultedPayment($paymentTokenId)) {
Registry::getUtilsView()->addErrorToDisplay(
Registry::getLang()->translateString('OSC_PAYPAL_DELETE_FAILED'),
false,
true
);
}
}

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 b20f652

Please sign in to comment.