-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to configure sequra from command line
- Loading branch information
Showing
5 changed files
with
250 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
<?php | ||
/** | ||
* Copyright © 2017 SeQura Engineering. All rights reserved. | ||
*/ | ||
|
||
namespace Sequra\Core\Console; | ||
|
||
use Sequra\Core\Model\ConfigFactory; | ||
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\SeQuraAPI\BaseProxy; | ||
use SeQura\Core\Infrastructure\ServiceRegister; | ||
|
||
/** | ||
* 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'; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param ConfigFactory $configFactory configFactory | ||
* @param \Sequra\Core\Model\ReporterFactory $reporterFactory reporteFactory | ||
* @param \Magento\Framework\App\State $state | ||
*/ | ||
public function __construct( | ||
ConfigFactory $configFactory, | ||
\Sequra\Core\Model\ReporterFactory $reporterFactory, | ||
\Magento\Framework\App\State $state | ||
) { | ||
$this->config = $configFactory->create(); | ||
$this->reporter = $reporterFactory->create(); | ||
$this->state = $state; | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Initialize triggerreport command | ||
* | ||
* @return void | ||
*/ | ||
protected function configure() | ||
{ | ||
$inputOptions = [ | ||
new InputOption( | ||
self::INPUT_KEY_MERCHANT_REF, | ||
null, | ||
InputOption::VALUE_NONE, | ||
'Merchant reference' | ||
), | ||
new InputOption( | ||
self::INPUT_KEY_USERNAME, | ||
null, | ||
InputOption::VALUE_NONE, | ||
'Username' | ||
), | ||
new InputOption( | ||
self::INPUT_KEY_ASSETS_KEY, | ||
null, | ||
InputOption::VALUE_NONE, | ||
'Assets key' | ||
), | ||
new InputOption( | ||
self::INPUT_KEY_ENDPOINT, | ||
null, | ||
InputOption::VALUE_NONE, | ||
'Endpoint' | ||
), | ||
new InputOption( | ||
self::INPUT_KEY_PASSWORD, | ||
null, | ||
InputOption::VALUE_NONE, | ||
'Password' | ||
), | ||
]; | ||
$this->setName(self::NAME) | ||
->setDescription('Quickly set sequra configuration') | ||
->setDefinition($inputOptions); | ||
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->state->setAreaCode(\Magento\Framework\App\Area::AREA_GLOBAL); | ||
$this->saveConnectionData( | ||
$input->getOption(self::INPUT_KEY_ENDPOINT), | ||
$input->getOption(self::INPUT_KEY_USERNAME), | ||
$input->getOption(self::INPUT_KEY_PASSWORD) | ||
); | ||
$this->saveCountriesConfig( | ||
'ES', | ||
$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)); | ||
} | ||
|
||
/** | ||
* @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; | ||
} | ||
|
||
/** | ||
* @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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
"pagos", | ||
"magento2" | ||
], | ||
"version": "2.5.0.4", | ||
"version": "2.5.1", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
|
Oops, something went wrong.