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 73e84fa commit a320f84
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Model/ApiFacade/CardTransaction/CardOpen.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ 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->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();
}

Expand Down
34 changes: 18 additions & 16 deletions Model/ApiFacade/OpenApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@
namespace tpaycom\magento2basic\Model\ApiFacade;

use Magento\Payment\Model\InfoInterface;
use tpaycom\magento2basic\Api\TpayInterface;
use tpaycom\magento2basic\Model\ApiFacade\Transaction\Dto\Channel;
use tpaySDK\Api\TpayApi;

class OpenApi extends TpayApi
class OpenApi
{
public function __construct($clientId, $clientSecret, $productionMode = false, $scope = 'read')
/** @var TpayApi */
private $tpayApi;

public function __construct(TpayInterface $tpay)
{
$this->clientId = $clientId;
$this->clientSecret = $clientSecret;
$this->productionMode = $productionMode;
$this->scope = $scope;
$this->tpayApi = new TpayApi($tpay->getOpenApiClientId(), $tpay->getOpenApiPassword(), !$tpay->useSandboxMode());
$this->tpayApi->authorization();
$versions = $this->getPackagesVersions();
$this->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()
]
);
));
}

public function create(array $data): array
Expand All @@ -31,15 +33,15 @@ public function create(array $data): array
}

$transactionData = $this->handleDataStructure($data);
$transaction = $this->transactions()->createTransaction($transactionData);
$transaction = $this->tpayApi->transactions()->createTransaction($transactionData);

return $this->updateRedirectUrl($transaction);
}

public function createWithInstantRedirect(array $data): array
{
$transactionData = $this->handleDataStructure($data);
$transaction = $this->transactions()->createTransactionWithInstantRedirection($transactionData);
$transaction = $this->tpayApi->transactions()->createTransactionWithInstantRedirection($transactionData);

return $this->updateRedirectUrl($transaction);
}
Expand All @@ -49,7 +51,7 @@ public function createBlikZero(array $data): array
$transactionData = $this->handleDataStructure($data);
unset($transactionData['pay']);

$transaction = $this->transactions()->createTransactionWithInstantRedirection($transactionData);
$transaction = $this->tpayApi->transactions()->createTransactionWithInstantRedirection($transactionData);

$additional_payment_data = [
'channelId' => 64,
Expand All @@ -60,22 +62,22 @@ public function createBlikZero(array $data): array
],
];

$result = $this->transactions()->createInstantPaymentByTransactionId($additional_payment_data, $transaction['transactionId']);
$result = $this->tpayApi->transactions()->createInstantPaymentByTransactionId($additional_payment_data, $transaction['transactionId']);

return $this->updateRedirectUrl($this->waitForBlikAccept($result));
}

public function makeRefund(InfoInterface $payment, float $amount): array
{
return $this->transactions()->createRefundByTransactionId(
return $this->tpayApi->transactions()->createRefundByTransactionId(
['amount' => $amount],
$payment->getAdditionalInformation('transaction_id')
);
}

public function channels(): array
{
$result = $this->transactions()->getChannels();
$result = $this->tpayApi->transactions()->getChannels();
$channels = [];

foreach ($result['channels'] ?? [] as $channel) {
Expand Down Expand Up @@ -148,7 +150,7 @@ private function waitForBlikAccept(array $result): array
$i = 0;
do {
$correct = false;
$tpayStatus = $this->transactions()->getTransactionById($result['transactionId']);
$tpayStatus = $this->tpayApi->transactions()->getTransactionById($result['transactionId']);
$errors = 0;

foreach ($tpayStatus['payments']['attempts'] as $error) {
Expand Down Expand Up @@ -193,7 +195,7 @@ private function getPackagesVersions()
$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']];
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"magento/module-payment": "^100.0",
"magento/module-sales": "^100.0",
"tpay-com/tpay-openapi-php": "^1.6.6",
"tpay-com/tpay-php": "^2.4.3"
"tpay-com/tpay-php": "^2.4.3",
"ext-json": "*"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit a320f84

Please sign in to comment.