diff --git a/Model/ApiFacade/CardTransaction/CardOpen.php b/Model/ApiFacade/CardTransaction/CardOpen.php index 7e661a9..ebe9601 100755 --- a/Model/ApiFacade/CardTransaction/CardOpen.php +++ b/Model/ApiFacade/CardTransaction/CardOpen.php @@ -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(); } diff --git a/Model/ApiFacade/OpenApi.php b/Model/ApiFacade/OpenApi.php index 9338746..65b2526 100755 --- a/Model/ApiFacade/OpenApi.php +++ b/Model/ApiFacade/OpenApi.php @@ -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 @@ -31,7 +33,7 @@ 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); } @@ -39,7 +41,7 @@ public function create(array $data): array 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); } @@ -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, @@ -60,14 +62,14 @@ 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') ); @@ -75,7 +77,7 @@ public function makeRefund(InfoInterface $payment, float $amount): array public function channels(): array { - $result = $this->transactions()->getChannels(); + $result = $this->tpayApi->transactions()->getChannels(); $channels = []; foreach ($result['channels'] ?? [] as $channel) { @@ -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) { @@ -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']]; diff --git a/composer.json b/composer.json index 21a7b5e..e081d2c 100755 --- a/composer.json +++ b/composer.json @@ -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": {