Skip to content

Commit

Permalink
Use new clientName identification mechanism (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
s4ddly authored Jul 8, 2024
1 parent 2a1ddaf commit 6a98a08
Show file tree
Hide file tree
Showing 12 changed files with 860 additions and 1,058 deletions.
4 changes: 2 additions & 2 deletions .dev-tools/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"ergebnis/composer-normalize": "^2.35",
"kubawerlos/composer-smaller-lock": "^1.0.1",
"magento/magento2ce": "^2.4",
"php-cs-fixer/shim": "^3.23",
"phpstan/phpstan": "^1.10.30",
"php-cs-fixer/shim": "3.23",
"phpstan/phpstan": "1.10.30",
"tpay-com/coding-standards": "^1.0.1",
"tpay-com/tpay-openapi-php": "^1.3",
"tpay-com/tpay-php": "^2.3.4",
Expand Down
1,845 changes: 830 additions & 1,015 deletions .dev-tools/composer.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Continuous integration

on:
pull_request:
push:

jobs:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/sca.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Static code analysis

on:
pull_request:
push:

jobs:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/.dev-tools/vendor/
/.dev-tools/.php-cs-fixer.cache
.idea/
vendor
composer.lock
5 changes: 2 additions & 3 deletions Model/ApiFacade/CardTransaction/CardOpen.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Tpay\Magento2\Api\TpayInterface;
use Tpay\Magento2\Service\TpayService;
use Tpay\Magento2\Service\TpayTokensService;
use tpaySDK\Api\TpayApi;
use Tpay\OpenApi\Api\TpayApi;

class CardOpen
{
Expand All @@ -34,8 +34,7 @@ public function __construct(TpayInterface $tpay, TpayConfigInterface $tpayConfig
$this->tpayConfig = $tpayConfig;
$this->tokensService = $tokensService;
$this->tpayService = $tpayService;
$this->tpayApi = new TpayApi($tpayConfig->getOpenApiClientId(), $tpayConfig->getOpenApiPassword(), !$tpayConfig->useSandboxMode());
$this->tpayApi->transactions()->setClientName($tpayConfig->buildMagentoInfo());
$this->tpayApi = new TpayApi($tpayConfig->getOpenApiClientId(), $tpayConfig->getOpenApiPassword(), !$tpayConfig->useSandboxMode(), 'read', null, $tpayConfig->buildMagentoInfo());
}

public function makeFullCardTransactionProcess(string $orderId, ?array $customerToken = null): string
Expand Down
7 changes: 4 additions & 3 deletions Model/ApiFacade/OpenApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Magento\Payment\Model\InfoInterface;
use Tpay\Magento2\Api\TpayConfigInterface;
use Tpay\Magento2\Model\ApiFacade\Transaction\Dto\Channel;
use tpaySDK\Api\TpayApi;
use Tpay\OpenApi\Api\TpayApi;

class OpenApi
{
Expand All @@ -20,12 +20,13 @@ class OpenApi
public function __construct(TpayConfigInterface $tpay, CacheInterface $cache)
{
$this->cache = $cache;
$this->tpayApi = new TpayApi($tpay->getOpenApiClientId(), $tpay->getOpenApiPassword(), !$tpay->useSandboxMode());
$this->tpayApi = new TpayApi($tpay->getOpenApiClientId(), $tpay->getOpenApiPassword(), !$tpay->useSandboxMode(), 'read', null, $tpay->buildMagentoInfo());
$token = $this->cache->load($this->getAuthTokenCacheKey($tpay));

if ($token) {
$this->tpayApi->setCustomToken(unserialize($token));
}
$this->tpayApi->transactions()->setClientName($tpay->buildMagentoInfo());

if (!$token) {
$this->cache->save(serialize($this->tpayApi->getToken()), $this->getAuthTokenCacheKey($tpay), [\Magento\Framework\App\Config::CACHE_TAG], 7100);
}
Expand Down
8 changes: 5 additions & 3 deletions Model/ApiFacade/TpayConfig/ConfigOpen.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ public function showChannels(): ?string

public function createScript(string $script): string
{
return "
<script type=\"text/javascript\">
return <<<EOD
<script type="text/javascript">
require(['jquery'], function ($) {
$.getScript('{$this->generateURL($script)}');
});
</script>";
</script>
EOD;
}

public function getTerms(): ?string
Expand Down
8 changes: 5 additions & 3 deletions Model/ApiFacade/TpayConfig/ConfigOrigin.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ public function showChannels(): ?string

public function createScript(string $script): string
{
return "
<script type=\"text/javascript\">
return <<<EOD
<script type="text/javascript">
require(['jquery'], function ($) {
$.getScript('{$this->generateURL($script)}');
});
</script>";
</script>
EOD;
}

public function getTerms(): ?string
Expand Down
1 change: 1 addition & 0 deletions Model/ApiFacade/Transaction/TransactionOriginApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class TransactionOriginApi extends PaymentBlik
* @param string $apiKey
* @param int $merchantId
* @param string $merchantSecret
* @param mixed $isProd
*/
public function __construct($apiPassword, $apiKey, $merchantId, $merchantSecret, $isProd = true)
{
Expand Down
34 changes: 8 additions & 26 deletions Provider/ConfigurationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Tpay\Magento2\Provider;

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

public function buildMagentoInfo(): string
{
$versions = $this->getPackagesVersions();

return implode(
'|',
[
'magento2:'.$this->getMagentoVersion(),
'tpay-com/tpay-openapi-php:'.$versions[0],
'tpay-com/tpay-php:'.$versions[1],
'magento2basic:'.$this->getTpayPluginVersion(),
'PHP:'.phpversion(),
]
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'),
$this->getTpayPluginVersion(),
phpversion()
);
}

Expand All @@ -249,21 +246,6 @@ public function isPlnPayment(): bool
return 'PLN' == $this->storeManager->getStore()->getBaseCurrencyCode() && 'PLN' == $this->storeManager->getStore()->getCurrentCurrencyCode();
}

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

return [$composerJson['tpay-com/tpay-openapi-php'], $composerJson['tpay-com/tpay-php']];
}

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

private function getTpayPluginVersion(): string
{
$dir = __DIR__.'/../.version';
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"php": ">=7.1",
"ext-json": "*",
"magento/framework": "^102.0 || ^103.0",
"tpay-com/tpay-openapi-php": "^1.7.1",
"tpay-com/tpay-openapi-php": "^1.8.0",
"tpay-com/tpay-php": "^2.4.7"
},
"autoload": {
Expand Down

0 comments on commit 6a98a08

Please sign in to comment.