Skip to content

Commit

Permalink
take over from OXID6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
mariolorenz committed Jan 17, 2025
1 parent f617e3d commit b2e69a1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
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
23 changes: 22 additions & 1 deletion src/Core/Api/VaultingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,28 @@ 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 b2e69a1

Please sign in to comment.