Skip to content

Commit

Permalink
Adding version information in the Tpay configuration view (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
krzGablo committed Aug 6, 2024
1 parent bc1b90e commit 1ddac9a
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.9
2.1.0
4 changes: 4 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.1.0]
### Added
- Adding version information in the Tpay configuration view

## [2.0.9]
### Fixed
- Fixed refund scope
Expand Down
25 changes: 25 additions & 0 deletions Model/Config/Source/VersionInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Tpay\Magento2\Model\Config\Source;

use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Tpay\Magento2\Api\TpayConfigInterface;

class VersionInfo extends Field
{
/** @var TpayConfigInterface */
private $tpayConfig;

public function __construct(Context $context, TpayConfigInterface $tpayConfig, array $data = [])
{
$this->tpayConfig = $tpayConfig;
parent::__construct($context, $data);
}

protected function _getElementHtml(AbstractElement $element): string // phpcs:ignore
{
return $this->tpayConfig->buildMagentoInfo();
}
}
34 changes: 31 additions & 3 deletions Provider/ConfigurationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Tpay\Magento2\Provider;

use Composer\InstalledVersions;
use Composer\Autoload\ClassLoader;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\Locale\Resolver;
Expand Down Expand Up @@ -222,11 +222,13 @@ public function getMagentoVersion(): string

public function buildMagentoInfo(): string
{
$apiVersions = $this->getApisVersions();

return sprintf(
'magento2:%s|tpay-openapi-php:%s|tpay-php:%s|magento2basic:%s|PHP:%s',
$this->getMagentoVersion(),
InstalledVersions::getPrettyVersion('tpay-com/tpay-openapi-php'),
InstalledVersions::getPrettyVersion('tpay-com/tpay-php'),
$apiVersions[0],
$apiVersions[1],
$this->getTpayPluginVersion(),
phpversion()
);
Expand Down Expand Up @@ -257,4 +259,30 @@ private function getTpayPluginVersion(): string

return 'n/a';
}

private function getApisVersions(): array
{
$apiVersions = ['n/a', 'n/a'];

if (true === method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders')) {
$vendorDir = array_keys(ClassLoader::getRegisteredLoaders())[0];
$installed = $vendorDir.'/composer/installed.php';

if (false === file_exists($installed)) {
return $apiVersions;
}

$dir = require $installed;

if (isset($dir['versions']['tpay-com/tpay-openapi-php'])) {
$apiVersions[0] = $dir['versions']['tpay-com/tpay-openapi-php']['pretty_version'];
}

if (isset($dir['versions']['tpay-com/tpay-php'])) {
$apiVersions[1] = $dir['versions']['tpay-com/tpay-php']['pretty_version'];
}
}

return $apiVersions;
}
}
4 changes: 4 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
<field id="version_comment" translate="label" type="label" sortOrder="19" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Version information</label>
<frontend_model>Tpay\Magento2\Model\Config\Source\VersionInfo</frontend_model>
</field>
</group>
</section>
</system>
Expand Down
1 change: 1 addition & 0 deletions i18n/pl_PL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"Maximal amount for method","Maksymalna kwota"
"Leave empty for no limit","Puste pole bez ograniczeń"
"View bank payments","Widok płatności bankowych"
"Version information","Informacje o wersji"
"If you use other currencies visible on the website and pay in PLN, turn it on/off","W przypadku korzystania z innych walut widocznych na stronie i płatności w PLN należy włączyć/wyłączyć"
"Type in 6 digit code and press pay to commit blik payment.", "Wpisz 6 cyfrowy kod aby powiązać transakcję blik."
"Choose a payment method","Wybierz jeden ze sposobów płatności"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ define(
},

getRegulations: function () {
return window.checkoutConfig.tpaycards.payment.getRegulations;
return window.checkoutConfig.tpay.payment.getRegulations;
},

getLogoUrl: function (code) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ define(
},

getRegulations: function () {
return window.checkoutConfig.tpaycards.payment.getRegulations;
return window.checkoutConfig.tpay.payment.getRegulations;
},

getLogoUrl: function () {
Expand Down

0 comments on commit 1ddac9a

Please sign in to comment.