Skip to content

Commit

Permalink
Merge branch 'master' into fix/CS-5639
Browse files Browse the repository at this point in the history
  • Loading branch information
m1k3lm authored Aug 22, 2024
2 parents 1ed7406 + bae6efe commit 4d1393d
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
# Exclude specific directories
.github export-ignore
docs export-ignore
docker export-ignore
docker export-ignore
bin export-ignore
268 changes: 268 additions & 0 deletions Console/Configure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
<?php
/**
* Copyright © 2017 SeQura Engineering. All rights reserved.
*/

namespace Sequra\Core\Console;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use SeQura\Core\BusinessLogic\Domain\Connection\Models\AuthorizationCredentials;
use SeQura\Core\BusinessLogic\Domain\Connection\Models\ConnectionData;
use SeQura\Core\BusinessLogic\Domain\Connection\Services\ConnectionService;
use SeQura\Core\BusinessLogic\Domain\CountryConfiguration\Exceptions\EmptyCountryConfigurationParameterException;
use SeQura\Core\BusinessLogic\Domain\CountryConfiguration\Exceptions\InvalidCountryCodeForConfigurationException;
use SeQura\Core\BusinessLogic\Domain\CountryConfiguration\Models\CountryConfiguration;
use SeQura\Core\BusinessLogic\Domain\CountryConfiguration\Models\SellingCountry;
use SeQura\Core\BusinessLogic\Domain\CountryConfiguration\Services\CountryConfigurationService;
use SeQura\Core\BusinessLogic\Domain\CountryConfiguration\Services\SellingCountriesService;
use SeQura\Core\BusinessLogic\Domain\GeneralSettings\Models\GeneralSettings;
use SeQura\Core\BusinessLogic\Domain\GeneralSettings\Services\GeneralSettingsService;
use SeQura\Core\BusinessLogic\Domain\PromotionalWidgets\Models\WidgetSettings;
use SeQura\Core\BusinessLogic\Domain\PromotionalWidgets\Services\WidgetSettingsService;
use SeQura\Core\BusinessLogic\SeQuraAPI\BaseProxy;
use SeQura\Core\Infrastructure\ServiceRegister;
use Sequra\Core\Services\Bootstrap;

/**
* Console command to trigger DR report
*/
class Configure extends Command
{
/**
* Command name
*/
const NAME = 'sequra:configure';
/**
* Names of input arguments or options
*/
const INPUT_KEY_MERCHANT_REF = 'merchant_ref';
/**
* Values of input arguments or options
*/
const INPUT_KEY_USERNAME = 'username';
/**
* Values of input arguments or options
*/
const INPUT_KEY_ASSETS_KEY = 'assets_key';
/**
* Values of input arguments or options
*/
const INPUT_KEY_ENDPOINT = 'endpoint';
/**
* Values of input arguments or options
*/
const INPUT_KEY_PASSWORD = 'password';

/**
* @var ConnectionService
*/
private $connectionService;
/**
* @var GeneralSettingsService
*/
private $generalSettingsService;
/**
* @var SellingCountriesService
*/
private $sellingCountriesService;
/**
* @var CountryConfigurationService
*/
private $countryConfigService;

/**
* @param Bootstrap $bootstrap
*/
public function __construct(
Bootstrap $bootstrap
)
{
parent::__construct();
$bootstrap->initInstance();
}
/**
* Initialize triggerreport command
*
* @return void
*/
protected function configure()
{
$inputOptions = [

];
$this->setName(self::NAME)
->setDescription('Quickly set sequra configuration')
->addOption(
self::INPUT_KEY_MERCHANT_REF,
null,
InputOption::VALUE_OPTIONAL,
'Merchant reference'
)
->addOption(
self::INPUT_KEY_USERNAME,
null,
InputOption::VALUE_OPTIONAL,
'Username'
)
->addOption(
self::INPUT_KEY_ASSETS_KEY,
null,
InputOption::VALUE_OPTIONAL,
'Assets key'
)
->addOption(
self::INPUT_KEY_ENDPOINT,
null,
InputOption::VALUE_OPTIONAL,
'Endpoint'
)
->addOption(
self::INPUT_KEY_PASSWORD,
null,
InputOption::VALUE_OPTIONAL,
'Password'
);
parent::configure();
}

/**
* Execute command.
*
* @param InputInterface $input InputInterface
* @param OutputInterface $output OutputInterface
*
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->saveConnectionData(
$input->getOption(self::INPUT_KEY_ENDPOINT),
$input->getOption(self::INPUT_KEY_USERNAME),
$input->getOption(self::INPUT_KEY_PASSWORD)
);
$this->saveCountriesConfig(
$this->getSellingCountriesService()->getSellingCountries(),
$input->getOption(self::INPUT_KEY_MERCHANT_REF)
);
$generalSettings = new GeneralSettings(
false,
true,
[],
[],
[]
);
$this->getGeneralSettingsService()->saveGeneralSettings($generalSettings);
$this->saveWidgetSettings($input->getOption(self::INPUT_KEY_ASSETS_KEY));
return 0;
}

/**
* @param string $endpoint
* @param string $username
* @param string $password
*
* @return void
*
* @throws InvalidEnvironmentException
*/
private function saveConnectionData(string $endpoint, string $username, string $password)
{
$connectionData = new ConnectionData(
$endpoint === 'https://sandbox.sequrapi.com/orders' ? BaseProxy::TEST_MODE : BaseProxy::LIVE_MODE,
'',
new AuthorizationCredentials($username, $password)
);
$this->getConnectionService()->saveConnectionData($connectionData);
}
/**
* @return ConnectionService
*/
private function getConnectionService(): ConnectionService
{
if ($this->connectionService === null) {
$this->connectionService = ServiceRegister::getService(ConnectionService::class);
}

return $this->connectionService;
}
/**
* @return GeneralSettingsService
*/
private function getGeneralSettingsService(): GeneralSettingsService
{
if ($this->generalSettingsService === null) {
$this->generalSettingsService = ServiceRegister::getService(GeneralSettingsService::class);
}

return $this->generalSettingsService;
}
/**
* @param SellingCountry[] $sellingCountries
* @param string $merchantId
*
* @return void
*
* @throws EmptyCountryConfigurationParameterException
* @throws InvalidCountryCodeForConfigurationException
*/
private function saveCountriesConfig(array $sellingCountries, string $merchantId)
{
$countryConfiguration = [];
foreach ($sellingCountries as $country) {
$countryConfiguration[] = new CountryConfiguration($country->getCode(), $merchantId);
}

$this->getCountryConfigService()->saveCountryConfiguration($countryConfiguration);
}
/**
* @return CountryConfigurationService
*/
private function getCountryConfigService(): CountryConfigurationService
{
if ($this->countryConfigService === null) {
$this->countryConfigService = ServiceRegister::getService(CountryConfigurationService::class);
}

return $this->countryConfigService;
}
/**
* @return SellingCountriesService
*/
private function getSellingCountriesService(): SellingCountriesService
{
if ($this->sellingCountriesService === null) {
$this->sellingCountriesService = ServiceRegister::getService(SellingCountriesService::class);
}

return $this->sellingCountriesService;
}

/**
* @param string $assetsKey
*
* @return void
*
* @throws HttpRequestException
* @throws Exception
*/
private function saveWidgetSettings(string $assetsKey)
{
if (!$this->getWidgetSettingsService()->isAssetsKeyValid($assetsKey)) {
return;
}

$widgetSettings = new WidgetSettings(false, $assetsKey);
$this->getWidgetSettingsService()->setWidgetSettings($widgetSettings);
}
/**
* @return WidgetSettingsService
*/
private function getWidgetSettingsService(): WidgetSettingsService
{
return ServiceRegister::getService(WidgetSettingsService::class);
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"pagos",
"magento2"
],
"version": "2.5.0.4",
"version": "2.5.1",
"license": "MIT",
"authors": [
{
Expand Down
8 changes: 3 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@
</arguments>
</type>

<!-- Commandline option to triggerrerport and update orders-->
<type name="Magento\Framework\Console\CommandList">
<arguments>
<argument name="commands" xsi:type="array">
<item name="Configure" xsi:type="object">Sequra\Core\Console\Configure</item>
</argument>
</arguments>
</type>

<!-- CSRF -->
<type name="Magento\Framework\App\Request\CsrfValidator">
<plugin name="sequra_disable_form_key_validation" type="Sequra\Core\Plugin\Framework\App\Request\CsrfValidator" />
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Sequra_Core" setup_version="2.5.0.4">
<module name="Sequra_Core" setup_version="2.5.1">
<sequence>
<module name="Magento_Catalog"/>
<module name="Magento_ConfigurableProduct"/>
Expand Down
3 changes: 3 additions & 0 deletions view/adminhtml/web/js/PaymentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ if (!window.SequraFE) {
* @returns {TableCell[][]}
*/
const getTableRows = () => {
if (!paymentMethods) {
return [];
}
return paymentMethods.map((method) => {
return [
{
Expand Down
2 changes: 1 addition & 1 deletion view/frontend/layout/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<body>
<referenceBlock name="head.components">
<block class="Sequra\Core\Block\WidgetInitializer" name="sequra.widget.initializer"
template="Sequra_Core::widget_initializer.phtml" cacheable="false"/>
template="Sequra_Core::widget_initializer.phtml" />
</referenceBlock>
</body>
</page>
2 changes: 1 addition & 1 deletion view/frontend/layout/sequra_hpp_index.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="empty" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<referenceContainer name="content">
<block class="Sequra\Core\Block\Hpp" name="sequra_hpp_index" template="Sequra_Core::hpp.phtml" cacheable="false" />
<block class="Sequra\Core\Block\Hpp" name="sequra_hpp_index" template="Sequra_Core::hpp.phtml"/>
</referenceContainer>
</page>

0 comments on commit 4d1393d

Please sign in to comment.