diff --git a/alma/exceptions/AlmaFormConfigurationException.php b/alma/exceptions/AlmaFormConfigurationException.php new file mode 100644 index 00000000..49836810 --- /dev/null +++ b/alma/exceptions/AlmaFormConfigurationException.php @@ -0,0 +1,33 @@ + + * @copyright 2018-2024 Alma SAS + * @license https://opensource.org/licenses/MIT The MIT License + */ + +namespace Alma\PrestaShop\Exceptions; + +if (!defined('_PS_VERSION_')) { + exit; +} + +class AlmaFormConfigurationException extends AlmaException +{ +} diff --git a/alma/lib/Services/AlmaConfigurationService.php b/alma/lib/Services/AlmaConfigurationService.php new file mode 100644 index 00000000..83e0c0b5 --- /dev/null +++ b/alma/lib/Services/AlmaConfigurationService.php @@ -0,0 +1,82 @@ + + * @copyright 2018-2024 Alma SAS + * @license https://opensource.org/licenses/MIT The MIT License + */ + +namespace Alma\Prestashop\Services; + +use Alma\PrestaShop\Exceptions\AlmaApiKeyException; +use Alma\PrestaShop\Factories\ClientFactory; +use Alma\PrestaShop\Forms\ApiAdminFormBuilder; +use Alma\PrestaShop\Logger; +use Alma\PrestaShop\Model\AlmaApiKeyModel; +use Alma\PrestaShop\Proxy\ToolsProxy; + +if (!defined('_PS_VERSION_')) { + exit; +} + +class AlmaConfigurationService +{ + /** + * @var \Alma\PrestaShop\Model\AlmaApiKeyModel + */ + private $almaApiKeyModel; + /** + * @var \Alma\PrestaShop\Proxy\ToolsProxy|mixed|null + */ + private $toolsProxy; + + public function __construct( + $almaApiKeyModel = null, + $toolsProxy = null, + $clientFactory = null + ) { + if (!$almaApiKeyModel) { + $almaApiKeyModel = new AlmaApiKeyModel(); + } + $this->almaApiKeyModel = $almaApiKeyModel; + + if (!$toolsProxy) { + $toolsProxy = new ToolsProxy(); + } + $this->toolsProxy = $toolsProxy; + + if (!$clientFactory) { + $clientFactory = new ClientFactory(); + } + } + + public function saveConfiguration() + { + try { + $currentMode = $this->toolsProxy->getValue(ApiAdminFormBuilder::ALMA_API_MODE); + $this->almaApiKeyModel->checkActiveApiKey($currentMode); + } catch (AlmaApiKeyException $e) { + Logger::instance()->error($e->getMessage()); + } + } + + public function getConfiguration() + { + } +} diff --git a/alma/tests/Unit/Services/AlmaConfigurationServiceTest.php b/alma/tests/Unit/Services/AlmaConfigurationServiceTest.php new file mode 100644 index 00000000..fa15fceb --- /dev/null +++ b/alma/tests/Unit/Services/AlmaConfigurationServiceTest.php @@ -0,0 +1,54 @@ + + * @copyright 2018-2024 Alma SAS + * @license https://opensource.org/licenses/MIT The MIT License + */ + +namespace Alma\PrestaShop\Tests\Unit\Services; + +use Alma\PrestaShop\Model\AlmaApiKeyModel; +use Alma\Prestashop\Services\AlmaConfigurationService; +use PHPUnit\Framework\TestCase; + +class AlmaConfigurationServiceTest extends TestCase +{ + /** + * @var AlmaConfigurationService + */ + protected $almaconfigurationService; + + public function setUp() + { + $this->almaApiKeyModel = $this->createMock(AlmaApiKeyModel::class); + $this->almaconfigurationService = new AlmaConfigurationService( + $this->almaApiKeyModel + ); + } + + public function tearDown() + { + $this->almaApiKeyModel = null; + } + + public function testSaveConfiguration() + { + } +}