Skip to content

Commit

Permalink
Merge pull request #381 from OXID-eSales/PSPAYPAL-880-simple-solution
Browse files Browse the repository at this point in the history
Duplicated vaults removed from vaulting lists
  • Loading branch information
mariolorenz authored Jan 17, 2025
2 parents aa4ec28 + ea0ec7c commit e8e12aa
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Controller/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function render()
$vaultedPaymentTokens = $vaultingService->getVaultPaymentTokens($paypalCustomerId)["payment_tokens"];
if ($vaultedPaymentTokens) {
$vaultedPaymentSources = [];
$uniquePaypalVaultedPaymentSources = [];
foreach ($vaultedPaymentTokens as $vaultedPaymentToken) {
foreach ($vaultedPaymentToken["payment_source"] as $paymentType => $paymentSource) {
if ($paymentType === "card" && $moduleSettings->isVaultingAllowedForACDC()) {
Expand All @@ -68,8 +69,21 @@ public function render()
$string . $paymentSource["last_digits"];
} elseif ($paymentType === "paypal" && $moduleSettings->isVaultingAllowedForPayPal()) {
$string = $lang->translateString("OSC_PAYPAL_CARD_PAYPAL_PAYMENT");

$email = $paymentSource["email_address"];
$payer_id = $paymentSource["payer_id"];

if(!isset($uniquePaypalVaultedPaymentSources[$email])) {
$uniquePaypalVaultedPaymentSources[$email] = [];
}

if( in_array($payer_id, $uniquePaypalVaultedPaymentSources[$email])) {
continue;
}

$uniquePaypalVaultedPaymentSources[$email][] = $payer_id;
$vaultedPaymentSources[$paymentType][] =
$string . " " . $paymentSource["email_address"];
$string . " " . $email;
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/Core/Api/VaultingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,30 @@ public function getVaultPaymentTokens(string $paypalCustomerId): array
->log('error', __CLASS__ . ' ' . __FUNCTION__ . ' : ' . $e->getMessage());
$result = [];
}
$moduleSettings = $this->getServiceFromContainer(ModuleSettings::class);
$vaultedPaymentTokens = $result['payment_tokens'];
$filteredVaultedPaymentTokens = [];
$uniquePaypalVaultedPaymentSources = [];
foreach ($vaultedPaymentTokens as $vaultedPaymentToken) {
foreach ($vaultedPaymentToken["payment_source"] as $paymentType => $paymentSource) {
if ($paymentType === 'paypal' && $moduleSettings->isVaultingAllowedForPayPal()) {
$email = $paymentSource["email_address"];
$payer_id = $paymentSource["payer_id"];

if (!isset($uniquePaypalVaultedPaymentSources[$email])) {
$uniquePaypalVaultedPaymentSources[$email] = [];
}

if (in_array($payer_id, $uniquePaypalVaultedPaymentSources[$email])) {
continue;
}

$uniquePaypalVaultedPaymentSources[$email][] = $payer_id;
}
$filteredVaultedPaymentTokens[] = $vaultedPaymentToken;
}
}
$result['payment_tokens'] = $filteredVaultedPaymentTokens;

return is_array($result) ? $result : [];
}
Expand Down

0 comments on commit e8e12aa

Please sign in to comment.