From bd2ed85f6c8d0613a2f68e8012ccdc06f2499cae Mon Sep 17 00:00:00 2001 From: krzGablo <147171777+krzGablo@users.noreply.github.com> Date: Tue, 19 Mar 2024 16:58:15 +0100 Subject: [PATCH] Version presentation fix (#48) Co-authored-by: Karol Wojciechowski --- .version | 1 + Model/ApiFacade/OpenApi.php | 6 +++--- Model/TpayPayment.php | 4 ++++ Observer/LoggerInjectObserver.php | 31 ++++++++++++++++++++++++++++++ Provider/ConfigurationProvider.php | 15 +++++++++++++-- composer.json | 2 +- etc/events.xml | 6 ++++++ 7 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 .version create mode 100644 Observer/LoggerInjectObserver.php create mode 100644 etc/events.xml diff --git a/.version b/.version new file mode 100644 index 0000000..6acdb44 --- /dev/null +++ b/.version @@ -0,0 +1 @@ +2.0.3 \ No newline at end of file diff --git a/Model/ApiFacade/OpenApi.php b/Model/ApiFacade/OpenApi.php index 03e3c51..182a828 100755 --- a/Model/ApiFacade/OpenApi.php +++ b/Model/ApiFacade/OpenApi.php @@ -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; @@ -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)); } } diff --git a/Model/TpayPayment.php b/Model/TpayPayment.php index eed48c0..eb55fcc 100755 --- a/Model/TpayPayment.php +++ b/Model/TpayPayment.php @@ -78,6 +78,9 @@ class TpayPayment extends Adapter implements TpayInterface /** @var LoggerInterface */ protected $logger; + /** @var CacheInterface */ + protected $cache; + private $supportedVendors = [ 'visa', 'jcb', @@ -118,6 +121,7 @@ public function __construct( $this->configurationProvider = $configurationProvider; $this->infoInstance = $infoInstance; $this->resolver = $resolver; + $this->cache = $cache; parent::__construct( $eventManager, $valueHandlerPool, diff --git a/Observer/LoggerInjectObserver.php b/Observer/LoggerInjectObserver.php new file mode 100644 index 0000000..3777a57 --- /dev/null +++ b/Observer/LoggerInjectObserver.php @@ -0,0 +1,31 @@ +logger = $logger; + } + + public function execute(Observer $observer) + { + OpenApiLogger::setLogger($this->logger); + OriginApiLogger::setLogger($this->logger); + } +} diff --git a/Provider/ConfigurationProvider.php b/Provider/ConfigurationProvider.php index 8841e2d..b80bb5f 100755 --- a/Provider/ConfigurationProvider.php +++ b/Provider/ConfigurationProvider.php @@ -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(), ] ); @@ -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'] ?? []; @@ -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'; + } } diff --git a/composer.json b/composer.json index 70c8b7f..2e574df 100755 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/etc/events.xml b/etc/events.xml new file mode 100644 index 0000000..06939e8 --- /dev/null +++ b/etc/events.xml @@ -0,0 +1,6 @@ + + + + +