Skip to content

Commit

Permalink
Merge remote-tracking branch 'tpay-com/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
wmwnuk committed Jul 22, 2024
2 parents 297a525 + fe55e45 commit 8b4b8dd
Show file tree
Hide file tree
Showing 36 changed files with 1,153 additions and 1,214 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
32 changes: 32 additions & 0 deletions .github/workflows/create_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Create release

on:
workflow_dispatch:
inputs:
version:
description: 'Version to create'
required: true

jobs:
create_release:
runs-on: ubuntu-latest

steps:
- name: Checkout source
uses: actions/checkout@v3

- name: Check .version
run: if [ $(grep ${{ github.event.inputs.version }} .version -c) != 1 ]; then exit 1; fi

- name: Check Changelog
run: if [ $(grep ${{ github.event.inputs.version }} CHANGELOG.md -c) != 1 ]; then exit 1; fi

- run: git archive --output=tpay-magento2-basic.zip HEAD

- name: Create Github release
uses: ncipollo/release-action@v1
with:
tag: ${{ github.event.inputs.version }}
name: "v${{ github.event.inputs.version }}"
generateReleaseNotes: true
artifacts: tpay-magento2-basic.zip
31 changes: 31 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Pull request

on:
pull_request:

permissions:
contents: write

jobs:
check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions/upload-artifact@v4
id: plugin-upload
with:
name: 'tpay-magento2-basic'
path: './'

- uses: actions/github-script@v6
with:
github-token: ${{ secrets.TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Tpay Magento2 plugin - ${{ steps.plugin-upload.outputs.artifact-url }}'
})
22 changes: 0 additions & 22 deletions .github/workflows/release.yaml

This file was deleted.

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
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.7
2.0.8
16 changes: 9 additions & 7 deletions Api/TpayConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ public function getTitle(): ?string;

public function getCardTitle(): ?string;

public function isOriginApiEnabled(): bool;
public function isOriginApiEnabled(?int $storeId = null): bool;

public function isOpenApiEnabled(): bool;
public function isOpenApiEnabled(?int $storeId = null): bool;

public function isCardEnabled(): bool;

public function isOriginApiCardUse(): bool;

public function getApiPassword(): ?string;
public function getApiPassword(?int $storeId = null): ?string;

public function getOpenApiPassword(): ?string;
public function getOpenApiPassword(?int $storeId = null): ?string;

public function getApiKey(): ?string;
public function getApiKey(?int $storeId = null): ?string;

public function getSecurityCode(?int $storeId = null): ?string;

public function getOpenApiClientId(): ?string;
public function getOpenApiClientId(?int $storeId = null): ?string;

public function getMerchantId(): ?int;
public function getMerchantId(?int $storeId = null): ?int;

public function getBlikLevelZeroStatus(): bool;

Expand All @@ -42,6 +42,8 @@ public function redirectToChannel(): bool;
/** Return url for a tpay.com terms */
public function getTermsURL(): string;

public function getRegulationsURL(): string;

/** Check if send an email about the new invoice to customer */
public function getInvoiceSendMail(): string;

Expand Down
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.0.8]
### Fixed
- Fixed admin scope config

## [2.0.7]
### Added
- Added regulations in english
Expand Down
63 changes: 40 additions & 23 deletions Controller/Tpay/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,32 +84,17 @@ public function executeNotification(): ?Response

public function executeCardNotification(): ?Response
{
try {
$notification = (new OriginJWSVerifiedPaymentNotification(
$this->tpayConfig->getSecurityCode(),
!$this->tpayConfig->useSandboxMode()
))->getNotification();

$orderId = base64_decode($notification['order_id']);

$this->tpayService->setCardOrderStatus($orderId, $notification, $this->tpayConfig);
$this->saveOriginCard($notification, $orderId);
$response = null;

return $this->response->setStatusCode(Response::STATUS_CODE_200)->setContent('TRUE');
} catch (Exception $e) {
Util::log(
'Notification exception',
sprintf(
'%s in file %s line: %d \n\n %s',
$e->getMessage(),
$e->getFile(),
$e->getLine(),
$e->getTraceAsString()
)
);
foreach ($this->storeManager->getStores() as $store) {
$response = $this->extractCardNotification($store);

return $this->response->setStatusCode(Response::STATUS_CODE_400)->setContent('FALSE');
if (Response::STATUS_CODE_200 === $response->getStatusCode()) {
break;
}
}

return $response;
}

public function createCsrfValidationException(RequestInterface $request): ?InvalidRequestException
Expand Down Expand Up @@ -213,4 +198,36 @@ private function extractNotification(StoreInterface $store): Response
return $this->response->setStatusCode(Response::STATUS_CODE_400)->setContent('FALSE');
}
}

private function extractCardNotification(StoreInterface $store): ?Response
{
$storeId = (int) $store->getStoreId();

try {
$notification = (new OriginJWSVerifiedPaymentNotification(
$this->tpayConfig->getSecurityCode($storeId),
!$this->tpayConfig->useSandboxMode($storeId)
))->getNotification();

$orderId = base64_decode($notification['order_id']);

$this->tpayService->setCardOrderStatus($orderId, $notification, $this->tpayConfig);
$this->saveOriginCard($notification, $orderId);

return $this->response->setStatusCode(Response::STATUS_CODE_200)->setContent('TRUE');
} catch (Exception $e) {
Util::log(
'Notification exception',
sprintf(
'%s in file %s line: %d \n\n %s',
$e->getMessage(),
$e->getFile(),
$e->getLine(),
$e->getTraceAsString()
)
);

return $this->response->setStatusCode(Response::STATUS_CODE_400)->setContent('FALSE');
}
}
}
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
18 changes: 10 additions & 8 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 @@ -17,17 +17,19 @@ class OpenApi

private $cache;

public function __construct(TpayConfigInterface $tpay, CacheInterface $cache)
public function __construct(TpayConfigInterface $tpay, CacheInterface $cache, ?int $storeId = null)
{
$this->cache = $cache;
$this->tpayApi = new TpayApi($tpay->getOpenApiClientId(), $tpay->getOpenApiPassword(), !$tpay->useSandboxMode());
$token = $this->cache->load($this->getAuthTokenCacheKey($tpay));
$this->tpayApi = new TpayApi($tpay->getOpenApiClientId($storeId), $tpay->getOpenApiPassword($storeId), !$tpay->useSandboxMode($storeId));
$token = $this->cache->load($this->getAuthTokenCacheKey($tpay, $storeId));
if ($token) {
$this->tpayApi->setCustomToken(unserialize($token));
}
$this->tpayApi->transactions()->setClientName($tpay->buildMagentoInfo());

$this->tpayApi->authorization();

if (!$token) {
$this->cache->save(serialize($this->tpayApi->getToken()), $this->getAuthTokenCacheKey($tpay));
$this->cache->save(serialize($this->tpayApi->getToken()), $this->getAuthTokenCacheKey($tpay, $storeId), [\Magento\Framework\App\Config::CACHE_TAG], 7100);
}
}

Expand Down Expand Up @@ -216,12 +218,12 @@ private function waitForBlikAccept(array $result): array
return $result;
}

private function getAuthTokenCacheKey(TpayConfigInterface $tpay)
private function getAuthTokenCacheKey(TpayConfigInterface $tpay, ?int $storeId = null)
{
return sprintf(
self::AUTH_TOKEN_CACHE_KEY,
md5(
join('|', [$tpay->getOpenApiClientId(), $tpay->getOpenApiPassword(), !$tpay->useSandboxMode()])
join('|', [$tpay->getOpenApiClientId($storeId), $tpay->getOpenApiPassword($storeId), !$tpay->useSandboxMode($storeId)])
)
);
}
Expand Down
14 changes: 11 additions & 3 deletions Model/ApiFacade/TpayConfig/ConfigOpen.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function getConfig(): array
'tpayCardsLogoUrl' => $this->generateURL('Tpay_Magento2::images/card.svg'),
'showPaymentChannels' => $this->showChannels(),
'getTerms' => $this->getTerms(),
'getRegulations' => $this->getRegulations(),
'addCSS' => $this->createCSS('Tpay_Magento2::css/tpay.css'),
'blikStatus' => $this->tpay->checkBlikLevel0Settings(),
'getBlikChannelID' => TransactionOriginApi::BLIK_CHANNEL,
Expand All @@ -83,7 +84,8 @@ public function showChannels(): ?string

public function createScript(string $script): string
{
return "
return <<<EOD
<script nonce='{$this->cspNonceProvider->generateNonce()}'>
require(['jquery'], function ($) {
let script = document.createElement('script');
Expand All @@ -92,14 +94,20 @@ public function createScript(string $script): string
document.head.appendChild(script);
});
</script>";
</script>
EOD;
}

public function getTerms(): ?string
{
return $this->tpayConfig->getTermsURL();
}

public function getRegulations(): ?string
{
return $this->tpayConfig->getRegulationsURL();
}

public function createCSS(string $css): string
{
return "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$this->generateURL($css)}\">";
Expand Down Expand Up @@ -134,6 +142,7 @@ public function getCardConfig()
'customerTokens' => $customerTokensData,
'isSavingEnabled' => $this->tpayConfig->getCardSaveEnabled(),
'getTerms' => $this->getTerms(),
'getRegulations' => $this->getRegulations(),
],
],
];
Expand All @@ -147,7 +156,6 @@ public function fetchJavaScripts()
$script[] = 'Tpay_Magento2::js/string_routines.js';
$script[] = 'Tpay_Magento2::js/tpayCards.js';
$script[] = 'Tpay_Magento2::js/renderSavedCards.js';
$script[] = 'Tpay_Magento2::js/tpayGeneric.js';
$scripts = '';

foreach ($script as $key => $value) {
Expand Down
Loading

0 comments on commit 8b4b8dd

Please sign in to comment.