Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSPAYPAL-878 filter payment tokens in account view #375

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
'en' => 'Use of the online payment service from PayPal. Documentation: <a href="https://docs.oxid-esales.com/modules/paypal-checkout/en/latest/" target="_blank">PayPal Checkout</a>'
],
'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',
Expand Down
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';
}
}
Loading