Skip to content

Commit

Permalink
PSPAYPAL-878 filter payment tokens in account view
Browse files Browse the repository at this point in the history
  • Loading branch information
René Gust committed Dec 18, 2024
1 parent 4a3979e commit a88d06b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Core/Api/VaultingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\ViewConfig;
use OxidSolutionCatalysts\PayPal\Core\Constants;
use OxidSolutionCatalysts\PayPal\Service\Logger;
use OxidSolutionCatalysts\PayPal\Service\ModuleSettings;
use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer;
use OxidSolutionCatalysts\PayPalApi\Exception\ApiException;
Expand Down Expand Up @@ -242,6 +243,8 @@ public function getVaultPaymentTokens(string $paypalCustomerId): array
}
$result = json_decode((string)$body, true, 512, JSON_THROW_ON_ERROR);
} catch (ApiException|JsonException $e) {
$this->getServiceFromContainer(Logger::class)
->log('error', __CLASS__ . ' ' . __FUNCTION__ . ' : ' . $e->getMessage());
$result = [];
}

Expand Down
45 changes: 43 additions & 2 deletions src/Core/ViewConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,16 @@ public function getSessionVaultSuccess()
/**
* get Vault Token
*
* @return string|null
* @return array|null
*/
public function getVaultPaymentTokens()
{
if ($this->getIsVaultingActive() && $customerId = $this->getUser()->getFieldData("oscpaypalcustomerid")) {
$vaultingService = Registry::get(ServiceFactory::class)->getVaultingService();

return $vaultingService->getVaultPaymentTokens($customerId)["payment_tokens"] ?? null;
$vaultPaymentTokens = $vaultingService->getVaultPaymentTokens($customerId)["payment_tokens"] ?? null;

return $this->filterVaultPaymentTokensByController($vaultPaymentTokens);
}

return null;
Expand Down Expand Up @@ -599,4 +601,43 @@ public function isAcdcEligibility(): bool
{
return $this->getServiceFromContainer(ModuleSettings::class)->isAcdcEligibility();
}

private function filterVaultPaymentTokensByController($vaultPaymentTokens)
{
if (is_null($vaultPaymentTokens)) {
return null;
}

if ($this->isAccountVaultController()) {
return array_filter(
$vaultPaymentTokens,
function ($token) {
return array_key_exists('payment_source', $token)
&& !array_key_exists('card', $token['payment_source']);
}
);
}

if ($this->isAccountVaultCartController()) {
return array_filter(
$vaultPaymentTokens,
function ($token) {
return array_key_exists('payment_source', $token)
&& array_key_exists('card', $token['payment_source']);
}
);
}

return $vaultPaymentTokens;
}

private function isAccountVaultController(): bool
{
return Registry::getRequest()->getRequestEscapedParameter("cl") === 'oscaccountvault';
}

private function isAccountVaultCartController(): bool
{
return Registry::getRequest()->getRequestEscapedParameter("cl") === 'oscaccountvaultcard';
}
}

0 comments on commit a88d06b

Please sign in to comment.