Skip to content

Commit

Permalink
AdditionalInfo fix
Browse files Browse the repository at this point in the history
  • Loading branch information
krzGablo committed Mar 15, 2024
1 parent 3a63179 commit 54c88e1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
9 changes: 7 additions & 2 deletions Model/ApiFacade/CardTransaction/CardApiFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ public function __construct(TpayInterface $tpay, TpayConfigInterface $tpayConfig
$this->createOpenApiInstance($tpay, $tpayConfig, $tokensService, $tpayService);
}

public function makeCardTransaction(string $orderId): string
public function makeCardTransaction(string $orderId, ?array $customerToken = null): string
{
return $this->getCurrent()->makeFullCardTransactionProcess($orderId);
return $this->getCurrent()->makeFullCardTransactionProcess($orderId, $customerToken);
}

public function payTransaction(string $orderId, array $additionalPaymentInformation, ?string $transactionId = null, ?array $customerToken = null): string
{
return $this->useOpenCard ? $this->cardOpen->payTransaction($orderId, $additionalPaymentInformation, $transactionId, $customerToken) : 'error';
}

private function getCurrent()
Expand Down
12 changes: 6 additions & 6 deletions Model/ApiFacade/CardTransaction/CardOpen.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public function __construct(TpayInterface $tpay, TpayConfigInterface $tpayConfig
$this->tpayApi->authorization()->setClientName($tpayConfig->buildMagentoInfo());
}

public function makeFullCardTransactionProcess(string $orderId): string
public function makeFullCardTransactionProcess(string $orderId, ?array $customerToken = null): string
{
$additionalPaymentInformation = $this->getAdditionalData($orderId);
$transaction = $this->makeCardTransaction($orderId);

return $this->payTransaction($orderId, $additionalPaymentInformation, $transaction['transactionId'] ?? null);
return $this->payTransaction($orderId, $additionalPaymentInformation, $transaction['transactionId'] ?? null, $customerToken);
}

public function getAdditionalData(string $orderId): array
Expand Down Expand Up @@ -74,24 +74,24 @@ public function createTransaction(): array
return $transaction;
}

public function payTransaction(string $orderId, array $additionalPaymentInformation, ?string $transactionId = null): string
public function payTransaction(string $orderId, array $additionalPaymentInformation, ?string $transactionId = null, ?array $customerToken = null): string
{
if (isset($additionalPaymentInformation['card_id']) && false !== $additionalPaymentInformation['card_id'] && $this->tpayConfig->getCardSaveEnabled()) {
$cardId = (int) $additionalPaymentInformation['card_id'];

return $this->processSavedCardPayment($orderId, $cardId, $transactionId);
return $this->processSavedCardPayment($orderId, $cardId, $transactionId, $customerToken);
}

return $this->processNewCardPayment($orderId, $additionalPaymentInformation, $transactionId);
}

private function processSavedCardPayment(string $orderId, int $cardId, ?string $transactionId = null): string
private function processSavedCardPayment(string $orderId, int $cardId, ?string $transactionId = null, ?array $customerToken = null): string
{
if (!$transactionId) {
return 'magento2basic/tpay';
}

$customerToken = $this->tokensService->getTokenById($cardId, $this->tpay->getCustomerId($orderId));
$customerToken ??= $this->tokensService->getTokenById($cardId, $this->tpay->getCustomerId($orderId));

if ($customerToken) {
try {
Expand Down
24 changes: 8 additions & 16 deletions Model/ApiFacade/CardTransaction/CardOrigin.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(TpayInterface $tpay, TpayConfigInterface $tpayConfig
parent::__construct();
}

public function makeFullCardTransactionProcess(string $orderId): string
public function makeFullCardTransactionProcess(string $orderId, ?array $customerToken = null): string
{
$payment = $this->tpayService->getPayment($orderId);
$paymentData = $payment->getData();
Expand All @@ -61,25 +61,18 @@ public function makeFullCardTransactionProcess(string $orderId): string
if (isset($additionalPaymentInformation['card_id']) && false !== $additionalPaymentInformation['card_id'] && $this->tpayConfig->getCardSaveEnabled()) {
$cardId = (int) $additionalPaymentInformation['card_id'];

return $this->processSavedCardPayment($orderId, $cardId);
return $this->processSavedCardPayment($orderId, $cardId, $customerToken);
}

return $this->processNewCardPayment($orderId, $additionalPaymentInformation);
}

private function processSavedCardPayment(string $orderId, string $cardId): string
private function processSavedCardPayment(string $orderId, int $cardId, ?array $customerToken = null): string
{
$customerTokens = $this->tokensService->getCustomerTokens($this->tpay->getCustomerId($orderId));

$isValid = false;
$token = '';
foreach ($customerTokens as $key => $value) {
if ((int) $value['tokenId'] === $cardId) {
$isValid = true;
$token = $value['token'];
}
}
if ($isValid) {
$customerToken ??= $this->tokensService->getTokenById($cardId, $this->tpay->getCustomerId($orderId));

if ($customerToken) {
$token = $customerToken['cli_auth'];
try {
$paymentResult = $this->presale($this->tpayPaymentConfig['description'], $token);

Expand Down Expand Up @@ -108,8 +101,7 @@ private function processSavedCardPayment(string $orderId, string $cardId): strin
} catch (Exception $e) {
return $this->trySaleAgain($orderId);
}
}
if (!$isValid) {
} else {
$this->tpayService->addCommentToHistory($orderId, 'Attempt of payment by not owned card has been blocked!');
}

Expand Down

0 comments on commit 54c88e1

Please sign in to comment.