Skip to content

Commit

Permalink
Version fix
Browse files Browse the repository at this point in the history
  • Loading branch information
krzGablo committed Jan 23, 2024
1 parent c5eeea4 commit 891f480
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
23 changes: 13 additions & 10 deletions Model/ApiFacade/CardTransaction/CardOpen.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ public function __construct(TpayInterface $tpay, TpayTokensService $tokensServic
$this->tpayService = $tpayService;
$this->tpayApi = new TpayApi($tpay->getOpenApiClientId(), $tpay->getOpenApiPassword(), !$tpay->useSandboxMode());
$versions = $this->getPackagesVersions();
$this->tpayApi->authorization()->setClientName(implode('|', [
$this->tpayApi->authorization()->setClientName(implode(
'|',
[
'magento2:' . $this->getMagentoVersion(),
'tpay-com/tpay-openapi-php:' . $versions[0],
'tpay-com/tpay-php:' . $versions[1],
'PHP:' . phpversion()
]
));
$this->tpayApi->authorization();
}

public function makeCardTransaction(string $orderId): string
Expand All @@ -52,7 +53,7 @@ public function makeCardTransaction(string $orderId): string
$this->tpayPaymentConfig = $this->tpay->getTpayFormData($orderId);

if (isset($additionalPaymentInformation['card_id']) && false !== $additionalPaymentInformation['card_id'] && $this->tpay->getCardSaveEnabled()) {
$cardId = (int)$additionalPaymentInformation['card_id'];
$cardId = (int) $additionalPaymentInformation['card_id'];

return $this->processSavedCardPayment($orderId, $cardId);
}
Expand Down Expand Up @@ -88,9 +89,9 @@ private function processSavedCardPayment(string $orderId, int $cardId): string
$paymentResult = $result['payments'] ?? [];

if (isset($paymentResult['status']) && 'declined' === $paymentResult['status']) {
$this->tpayService->addCommentToHistory($orderId, 'Failed to pay by saved card, Elavon rejection code: ' . $paymentResult['reason']);
$this->tpayService->addCommentToHistory($orderId, 'Failed to pay by saved card, Elavon rejection code: ' .$paymentResult['reason']);
} else {
$this->tpayService->addCommentToHistory($orderId, 'Failed to pay by saved card, error: ' . $paymentResult['err_desc']);
$this->tpayService->addCommentToHistory($orderId, 'Failed to pay by saved card, error: ' .$paymentResult['err_desc']);
}
} catch (Exception $e) {
return 'magento2basic/tpay/error';
Expand All @@ -112,7 +113,7 @@ private function addToPaymentData(string $orderId, string $key, $value)

private function processNewCardPayment(string $orderId, array $additionalPaymentInformation): string
{
$saveCard = isset($additionalPaymentInformation['card_save']) && $this->tpay->getCardSaveEnabled() ? (bool)$additionalPaymentInformation['card_save'] : false;
$saveCard = isset($additionalPaymentInformation['card_save']) && $this->tpay->getCardSaveEnabled() ? (bool) $additionalPaymentInformation['card_save'] : false;
try {
$transaction = $this->tpayApi->Transactions->createTransaction($this->handleDataStructure());
$request = [
Expand All @@ -131,7 +132,7 @@ private function processNewCardPayment(string $orderId, array $additionalPayment

if (isset($result['transactionPaymentUrl']) && 'pending' === $result['payments']['status']) {
$url3ds = $result['transactionPaymentUrl'];
$this->tpayService->addCommentToHistory($orderId, '3DS Transaction link ' . $url3ds);
$this->tpayService->addCommentToHistory($orderId, '3DS Transaction link ' .$url3ds);
$this->addToPaymentData($orderId, 'transaction_url', $url3ds);
$this->saveCard($orderId, $saveCard, $additionalPaymentInformation);

Expand All @@ -157,7 +158,7 @@ private function saveCard(string $orderId, bool $saveCard, array $additionalPaym
private function handleDataStructure(): array
{
return [
'amount' => (float)$this->tpayPaymentConfig['amount'],
'amount' => (float) $this->tpayPaymentConfig['amount'],
'description' => $this->tpayPaymentConfig['description'],
'hiddenDescription' => $this->tpayPaymentConfig['crc'],
'payer' => [
Expand Down Expand Up @@ -197,19 +198,21 @@ private function getMagentoVersion()
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productMetadata = $objectManager->get('\Magento\Framework\App\ProductMetadataInterface');

return $productMetadata->getVersion();
}

private function getPackagesVersions()
{
$dir = __DIR__ . '/../../../composer.json';
$dir = __DIR__ .'/../../composer.json';
if (file_exists($dir)) {
$composerJson = json_decode(
file_get_contents(__DIR__ . '/../../../composer.json'), true
file_get_contents(__DIR__ .'/../../composer.json'), true
)['require'] ?? [];

return [$composerJson['tpay-com/tpay-openapi-php'], $composerJson['tpay-com/tpay-php']];
}

return ['n/a', 'n/a'];
}
}
10 changes: 7 additions & 3 deletions Model/ApiFacade/OpenApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public function __construct(TpayInterface $tpay)
$this->tpayApi = new TpayApi($tpay->getOpenApiClientId(), $tpay->getOpenApiPassword(), !$tpay->useSandboxMode());
$this->tpayApi->authorization();
$versions = $this->getPackagesVersions();
$this->tpayApi->authorization()->setClientName(implode('|', [
$this->tpayApi->authorization()->setClientName(implode(
'|',
[
'magento2:' . $this->getMagentoVersion(),
'tpay-com/tpay-openapi-php:' . $versions[0],
'tpay-com/tpay-php:' . $versions[1],
Expand Down Expand Up @@ -187,19 +189,21 @@ private function getMagentoVersion()
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productMetadata = $objectManager->get('\Magento\Framework\App\ProductMetadataInterface');

return $productMetadata->getVersion();
}

private function getPackagesVersions()
{
$dir = __DIR__ . '/../../composer.json';
$dir = __DIR__ .'/../../composer.json';
if (file_exists($dir)) {
$composerJson = json_decode(
file_get_contents(__DIR__ . '/../../composer.json'), true
file_get_contents(__DIR__ .'/../../composer.json'), true
)['require'] ?? [];

return [$composerJson['tpay-com/tpay-openapi-php'], $composerJson['tpay-com/tpay-php']];
}

return ['n/a', 'n/a'];
}
}

0 comments on commit 891f480

Please sign in to comment.