From a88d06bd9ead8d9a5946a75a8e23ed1867ef3ad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Gust?= Date: Wed, 18 Dec 2024 18:24:58 +0100 Subject: [PATCH 1/2] PSPAYPAL-878 filter payment tokens in account view --- src/Core/Api/VaultingService.php | 3 +++ src/Core/ViewConfig.php | 45 ++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/Core/Api/VaultingService.php b/src/Core/Api/VaultingService.php index 1ea81e74e..25c6bd30f 100644 --- a/src/Core/Api/VaultingService.php +++ b/src/Core/Api/VaultingService.php @@ -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; @@ -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 = []; } diff --git a/src/Core/ViewConfig.php b/src/Core/ViewConfig.php index d47723349..99e13e97a 100644 --- a/src/Core/ViewConfig.php +++ b/src/Core/ViewConfig.php @@ -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; @@ -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'; + } } From ef46aa6d2cb1d64abf96ec641eeb458da3b3de97 Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Thu, 19 Dec 2024 09:10:17 +0100 Subject: [PATCH 2/2] chageloge & version number --- CHANGELOG.md | 1 + metadata.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f94f4b1fb..a06da023e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - [0007745](https://bugs.oxid-esales.com/view.php?id=7745): Paypal checkout jumps back to step 2 with an error when an discount in relation to item value is used - [0007742](https://bugs.oxid-esales.com/view.php?id=7742): You get stuck in the checkout if the "Save payment method" option is activated for credit card payment - [0007695](https://bugs.oxid-esales.com/view.php?id=7695): Explain better Pseudo delivery costs +- Show vaulted Payments filtered by payment-method in account-view ### NEW diff --git a/metadata.php b/metadata.php index 684e762ee..e07c4ccaa 100755 --- a/metadata.php +++ b/metadata.php @@ -61,7 +61,7 @@ 'en' => 'Use of the online payment service from PayPal. Documentation: PayPal Checkout' ], 'thumbnail' => 'out/img/paypal.png', - 'version' => '2.5.2-rc.3', + 'version' => '2.5.2-rc.4', 'author' => 'OXID eSales AG', 'url' => 'https://www.oxid-esales.com', 'email' => 'info@oxid-esales.com',