Skip to content

Commit

Permalink
Version presentation fix (#48)
Browse files Browse the repository at this point in the history
Co-authored-by: Karol Wojciechowski <karol.wojciechowski@tpay.com>
  • Loading branch information
krzGablo and Karol Wojciechowski committed Mar 19, 2024
1 parent 46315d8 commit bd2ed85
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 6 deletions.
1 change: 1 addition & 0 deletions .version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.0.3
6 changes: 3 additions & 3 deletions Model/ApiFacade/OpenApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

class OpenApi
{
public const AUTH_TOKEN_CACHE_KEY = 'tpay_auth_token_%s';

/** @var TpayApi */
private $tpayApi;

private $cache;

const AUTH_TOKEN_CACHE_KEY = 'tpay_auth_token_%s';

public function __construct(TpayConfigInterface $tpay, CacheInterface $cache)
{
$this->cache = $cache;
Expand All @@ -26,7 +26,7 @@ public function __construct(TpayConfigInterface $tpay, CacheInterface $cache)
$this->tpayApi->setCustomToken(unserialize($token));
}
$this->tpayApi->authorization()->setClientName($tpay->buildMagentoInfo());
if(!$token){
if (!$token) {
$this->cache->save(serialize($this->tpayApi->getToken()), $this->getAuthTokenCacheKey($tpay));
}
}
Expand Down
4 changes: 4 additions & 0 deletions Model/TpayPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class TpayPayment extends Adapter implements TpayInterface
/** @var LoggerInterface */
protected $logger;

/** @var CacheInterface */
protected $cache;

private $supportedVendors = [
'visa',
'jcb',
Expand Down Expand Up @@ -118,6 +121,7 @@ public function __construct(
$this->configurationProvider = $configurationProvider;
$this->infoInstance = $infoInstance;
$this->resolver = $resolver;
$this->cache = $cache;
parent::__construct(
$eventManager,
$valueHandlerPool,
Expand Down
31 changes: 31 additions & 0 deletions Observer/LoggerInjectObserver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Tpay\Magento2\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Psr\Log\LoggerInterface;
use Tpay\OpenApi\Utilities\Logger as OpenApiLogger;
use Tpay\OriginApi\Utilities\Logger as OriginApiLogger;

/**
* This is temporary logger injector into Tpay classess.
* After moving currency card sales into open api and simplification of our API
* This Observer will disappear
*/
class LoggerInjectObserver implements ObserverInterface
{
/** @var LoggerInterface */
private $logger;

public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}

public function execute(Observer $observer)
{
OpenApiLogger::setLogger($this->logger);
OriginApiLogger::setLogger($this->logger);
}
}
15 changes: 13 additions & 2 deletions Provider/ConfigurationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public function buildMagentoInfo(): string
'magento2:'.$this->getMagentoVersion(),
'tpay-com/tpay-openapi-php:'.$versions[0],
'tpay-com/tpay-php:'.$versions[1],
'magento2basic:'.$this->getTpayPluginVersion(),
'PHP:'.phpversion(),
]
);
Expand All @@ -215,10 +216,10 @@ public function getConfigData($field, $storeId = null)

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

Expand All @@ -227,4 +228,14 @@ private function getPackagesVersions(): array

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

private function getTpayPluginVersion(): string
{
$dir = __DIR__.'/../.version';
if (file_exists($dir)) {
return file_get_contents(__DIR__.'/../.version');
}

return 'n/a';
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"ext-json": "*",
"magento/framework": "^102.0 || ^103.0",
"tpay-com/tpay-openapi-php": "^1.7.1",
"tpay-com/tpay-php": "^2.4.3"
"tpay-com/tpay-php": "^2.4.4"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 6 additions & 0 deletions etc/events.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="controller_action_predispatch">
<observer name="tpay_magento2_loggers" instance="Tpay\Magento2\Observer\LoggerInjectObserver" shared="false" />
</event>
</config>

0 comments on commit bd2ed85

Please sign in to comment.