Skip to content

Commit

Permalink
Merge branch 'develop' into feature/PLUG-129
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandanaita authored Oct 28, 2024
2 parents 68d9a89 + 6a2ea8e commit bf70c14
Show file tree
Hide file tree
Showing 40 changed files with 713 additions and 139 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ jobs:
- name: Create branch for Composer and remove version from composer.json
run: git checkout -b continuous-integration-test-branch && sed -i '/version/d' ./composer.json

- name: Remove PHPStan duplicate include
run: sed -i '/vendor\/bitexpert/d' ./phpstan.neon

- name: Upload our code into the docker container
run: docker cp $(pwd) magento-project-community-edition:/data/extensions/

- name: Set minimum-stability for composer (temp)
run: docker exec magento-project-community-edition composer config minimum-stability dev

- name: Configure composer to mirror repository
run: docker exec magento-project-community-edition composer config repositories.truelayer \{\"type\":\"path\",\"url\":\"/data/extensions/$(basename $(pwd))\",\"options\":\{\"symlink\":false\}\}

- name: Install the extensions in Magento
run: docker exec magento-project-community-edition composer require truelayer/magento2:@dev --no-plugins --with-all-dependencies

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/setup-di-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v2

- name: Start Docker
run: PHP_VERSION=${{ matrix.PHP_VERSION }} MAGENTO_VERSION=magento${{ matrix.MAGENTO_VERSION }} docker-compose -f .github/workflows/templates/docker-compose.yml up -d
run: PHP_VERSION=${{ matrix.PHP_VERSION }} MAGENTO_VERSION=magento${{ matrix.MAGENTO_VERSION }} docker compose -f .github/workflows/templates/docker-compose.yml up -d

- name: Create branch for Composer and remove version from composer.json
run: git checkout -b continuous-integration-test-branch && sed -i '/version/d' ./composer.json
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.DS_Store
docker
.vscode
.php-cs-fixer.cache
56 changes: 56 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = Finder::create()
->in(__DIR__)
->exclude(['.github', '.vscode', 'docker', 'vendor'])
->ignoreDotFiles(false);

$rules = [
'@PSR1' => true,
'@PSR2' => true,
'@PSR12' => true,
'ordered_imports' => [
'sort_algorithm' => 'alpha',
'imports_order' => [
'class',
'function',
'const'
]
],
'single_line_empty_body' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'no_whitespace_in_blank_line' => true,
'whitespace_after_comma_in_array' => [
'ensure_single_space' => true
],
'no_multiline_whitespace_around_double_arrow' => true,
'no_trailing_comma_in_singleline_array' => true,
'normalize_index_brace' => true,
'trim_array_spaces' => true,
'single_class_element_per_statement' => [
'elements' => [
'const',
'property'
]
],
'visibility_required' => [
'elements' => [
'property',
'method',
'const'
]
],
'align_multiline_comment' => true
];

$config = new Config();
$config->setFinder($finder);
$config->setRules($rules);
$config->setIndent(' ');
$config->setLineEnding("\n");

return $config;
1 change: 1 addition & 0 deletions Api/Config/System/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface ConnectionInterface extends DebugInterface
public const XML_PATH_PRODUCTION_CLIENT_SECRET = 'payment/truelayer/production_client_secret';
public const XML_PATH_PRODUCTION_PRIVATE_KEY = 'payment/truelayer/production_private_key';
public const XML_PATH_PRODUCTION_KEY_ID = 'payment/truelayer/production_key_id';
public const XML_PATH_CACHE_ENCRYPTION_KEY = 'payment/truelayer/cache_encryption_key';

/**
* Get Merchant Account Name
Expand Down
10 changes: 10 additions & 0 deletions Api/Config/System/SettingInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface SettingInterface
public const XML_PATH_SEND_ORDER_EMAIL = 'payment/truelayer/send_order_email';
public const XML_PATH_SEND_INVOICE_EMAIL = 'payment/truelayer/send_invoice_email';
public const XML_PATH_BANKING_PROVIDERS = 'payment/truelayer/banking_providers';
public const XML_PATH_RELEASE_CHANNEL = 'payment/truelayer/release_channel';
public const XML_PATH_PAYMENT_PAGE_PRIMARY_COLOR = 'payment/truelayer/payment_page_primary_color';
public const XML_PATH_PAYMENT_PAGE_SECONDARY_COLOR = 'payment/truelayer/payment_page_secondary_color';
public const XML_PATH_PAYMENT_PAGE_TERTIARY_COLOR = 'payment/truelayer/payment_page_tertiary_color';
Expand Down Expand Up @@ -48,6 +49,15 @@ public function getMaximumOrderTotal(): float;
*/
public function getBankingProviders(?int $storeId = null): array;

/**
* Get associated array of credentials
*
* @param int|null $storeId
*
* @return string
*/
public function getReleaseChannel(?int $storeId = null): string;

/**
* Get payment page primary color
*
Expand Down
4 changes: 2 additions & 2 deletions Api/Log/LogServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ interface LogServiceInterface
* @param string $type
* @param mixed $data
*/
public function error(string $type, $data): LogServiceInterface;
public function error(string $type, $data = ''): LogServiceInterface;

/**
* Add record to debug log
*
* @param string $type
* @param mixed $data
*/
public function debug(string $type, $data): LogServiceInterface;
public function debug(string $type, $data = ''): LogServiceInterface;

/**
* @param string|int $prefix
Expand Down
8 changes: 4 additions & 4 deletions Block/Adminhtml/System/Config/Button/Credentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ public function getApiCheckUrl(): string
public function getButtonHtml(): string
{
try {
return $this->getLayout()
->createBlock(Button::class)
->setData(['id' => 'truelayer-button_credentials', 'label' => __('Check Credentials')])
->toHtml();
/** @var \Magento\Framework\View\Element\AbstractBlock $block */
$block = $this->getLayout()->createBlock(Button::class);
$block->setData(['id' => 'truelayer-button_credentials', 'label' => __('Check Credentials')]);
return $block->toHtml();
} catch (Exception $e) {
$this->logger->error('Credentials check', $e->getMessage());
return '';
Expand Down
13 changes: 7 additions & 6 deletions Block/Adminhtml/System/Config/Button/DebugCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ public function getDebugCheckUrl(): string
public function getButtonHtml(): string
{
try {
return $this->getLayout()
->createBlock(Button::class)
->setData([
'id' => 'truelayer-button_debug',
'label' => __('Check last 100 debug log records')
])->toHtml();
/** @var \Magento\Framework\View\Element\AbstractBlock $block */
$block = $this->getLayout()->createBlock(Button::class);
$block->setData([
'id' => 'truelayer-button_debug',
'label' => __('Check last 100 debug log records')
]);
return $block->toHtml();
} catch (Exception $e) {
return '';
}
Expand Down
13 changes: 7 additions & 6 deletions Block/Adminhtml/System/Config/Button/ErrorCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ public function getErrorCheckUrl(): string
public function getButtonHtml(): string
{
try {
return $this->getLayout()
->createBlock(Button::class)
->setData([
'id' => 'truelayer-button_error',
'label' => __('Check last 100 error log records')
])->toHtml();
/** @var \Magento\Framework\View\Element\AbstractBlock $block */
$block = $this->getLayout()->createBlock(Button::class);
$block->setData([
'id' => 'truelayer-button_error',
'label' => __('Check last 100 error log records')
]);
return $block->toHtml();
} catch (Exception $e) {
return '';
}
Expand Down
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@ 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).

## [v2.3.0] - 2024-09-27

### Added

- Release channel configuration option
- Fix settings visibility based on scopes

### Changed

- Stricter PHPStan rules

## [v2.2.0] - 2024-09-02

### Added

- Test validity of private key file when testing credentials.
- Store transaction ID in sales_order_payment table last_trans_id column.

### Fixed

- Check credentials button will correctly use unsaved values from the form fields.
- View logs button will show the end of the log file instead of the beginning.

## [v2.1.0] - 2024-07-17

### Added
Expand Down
59 changes: 49 additions & 10 deletions Controller/Adminhtml/Credentials/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
use Magento\Framework\Filesystem\DirectoryList;
use Magento\Framework\Filesystem\Io\File;
use TrueLayer\Connect\Api\Config\RepositoryInterface as ConfigRepository;
use TrueLayer\Connect\Model\Config\Source\Mode;
use TrueLayer\Connect\Service\Client\ClientFactory;
use TrueLayer\Exceptions\ApiResponseUnsuccessfulException;
use TrueLayer\Exceptions\SignerException;
use TrueLayer\Interfaces\Client\ClientInterface;

/**
Expand Down Expand Up @@ -62,16 +65,43 @@ public function __construct(
*/
public function execute(): Json
{
$message = '';
try {
$this->testCredentials()->getMerchantAccounts();
$client = $this->testCredentials();
$client->getMerchantAccounts();
$client->getApiClient()->request()->uri('/test-signature')->post();

return $this->resultJson->setData(
['success' => true, 'msg' => __('Credentials correct!')->render()]
);
} catch (\Exception $exception) {
return $this->resultJson->setData(
['success' => false, 'msg' => 'Credentials are not correct']
);
} catch (ApiResponseUnsuccessfulException $e) {
if ($e->getMessage() === 'invalid_client') {
$message = __('Invalid Client Id or Secret');
}
elseif ($e->getMessage() === 'Unauthenticated') {
$message = __('Incorrect Private Key or KID');
}
} catch (SignerException $e) {
$m = $e->getMessage();
if (!!$m) {
if (strpos($m, 'is not private') !== false) {
$message = __('Private Key contains Public Key');
} elseif (strpos($m, 'Unable to load') !== false) {
$message = __('Malformed Private Key');
}
}
unset($m);
} catch (LocalizedException $e) {
$message = $e->getMessage();
} catch (\Exception $e) {
//leave default message
}
if (!$message) {
$message = __('Credentials are not correct.');
}
return $this->resultJson->setData(
['success' => false, 'msg' => $message]
);
}

/**
Expand All @@ -81,18 +111,26 @@ public function execute(): Json
private function testCredentials(): ?ClientInterface
{
$config = $this->getCredentials();
$mode = $this->getRequest()->getParam('mode');

if (!$config['credentials']['client_id']) {
throw new LocalizedException(__('No Client ID set!'));
throw new LocalizedException(__('Client Id is missing'));
}

if (!$config['credentials']['client_secret']) {
throw new LocalizedException(__('No Client Secret set!'));
throw new LocalizedException(__('Client Secret is missing'));
}

if (!$config['credentials']['private_key'] || $this->getRequest()->getParam('delete_private_key') === 'true') {
throw new LocalizedException(__('Private Key file is missing'));
}

$result = $this->clientFactory->create(
(int)$config['store_id'],
['credentials' => $config['credentials']]
[
'credentials' => $config['credentials'],
'force_sandbox' => $mode === Mode::SANDBOX,
]
);

$this->cleanSavedTemporaryPrivateKey();
Expand Down Expand Up @@ -122,7 +160,7 @@ private function getCredentials(): array
$keyId = $this->getRequest()->getParam('production_key_id');
}

$configCredentials = $this->configProvider->getCredentials($storeId);
$configCredentials = $this->configProvider->getCredentials($storeId, $mode === Mode::SANDBOX);
if ($clientSecret == '******') {
$clientSecret = $configCredentials['client_secret'];
}
Expand All @@ -133,7 +171,8 @@ private function getCredentials(): array
'client_id' => $clientId,
'client_secret' => $clientSecret,
'private_key' => $this->getPrivateKeyPath($configCredentials),
'key_id' => $keyId
'key_id' => $keyId,
'cache_encryption_key' => $configCredentials['cache_encryption_key']
]
];
}
Expand Down
Loading

0 comments on commit bf70c14

Please sign in to comment.