Skip to content

Commit

Permalink
Merge pull request #7 from OXID-eSales/TC-14_APIOptions
Browse files Browse the repository at this point in the history
Tc 14 api options
  • Loading branch information
HonkDerHase authored Oct 2, 2024
2 parents ee9b9ee + 014da15 commit a59da1b
Show file tree
Hide file tree
Showing 24 changed files with 1,480 additions and 46 deletions.
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"prefer-dist": true,
"require": {
"php": "^8.1",
"symfony/filesystem": "^6.0"
"symfony/filesystem": "^6.0",
"symfony/http-foundation": "^6.0"
},
"minimum-stability": "dev",
"require-dev": {
Expand All @@ -30,11 +31,11 @@
"oxid-esales/oxideshop-ce": "^7.1",
"phpunit/phpunit": "^9.6",
"mikey179/vfsstream": "~1.6.8",
"codeception/codeception": "*",
"codeception/module-asserts": "*",
"codeception/module-db": "*",
"codeception/module-filesystem": "*",
"codeception/module-webdriver": "*",
"codeception/codeception": "^5.1",
"codeception/module-asserts": "^3.0",
"codeception/module-db": "^3.1",
"codeception/module-filesystem": "^3.0",
"codeception/module-webdriver": "^3.2",
"oxid-esales/codeception-modules": "dev-b-7.1.x",
"oxid-esales/codeception-page-objects": "dev-b-7.1.x",
"oxid-esales/developer-tools": "dev-b-7.1.x"
Expand Down
77 changes: 70 additions & 7 deletions metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
* See LICENSE file for license details.
*/

use OxidEsales\Eshop\Application\Controller\Admin\ModuleConfiguration as oxModuleConfiguration;
use OxidSolutionCatalysts\TeleCash\Core\Module;
use OxidSolutionCatalysts\TeleCash\Extension\Application\Controller\Admin\ModuleConfiguration;
use OxidSolutionCatalysts\TeleCash\Settings\Service\ModuleFileSettingsServiceInterface;
use OxidSolutionCatalysts\TeleCash\Settings\Service\ModuleSettingsServiceInterface;

/**
Expand All @@ -18,30 +21,90 @@
*/
$aModule = [
'id' => Module::MODULE_ID,
'title' => 'Payment-Module for Payment-Provider Telecash',
'description' => 'This module provides the integration of the payment provider Telecash.',
'title' => [
'de' => 'Zahlungs-Module für Zahlungsdienstleisters Telecash',
'en' => 'Payment-Module for Payment-Provider Telecash',
],
'description' => [
'de' => 'Dieses Modul ermöglicht die Integration des Zahlungsdienstleisters Telecash.',
'en' => 'This module provides the integration of the payment provider Telecash.',
],
'thumbnail' => 'pictures/logo.png',
'version' => '1.0.0',
'author' => 'OXID eSales AG',
'url' => '',
'email' => '',
'extend' => [
],
'controllers' => [
],
'events' => [
'onActivate' => '\OxidSolutionCatalysts\TeleCash\Core\ModuleEvents::onActivate',
'onDeactivate' => '\OxidSolutionCatalysts\TeleCash\Core\ModuleEvents::onDeactivate'
],
'extend' => [
oxModuleConfiguration::class => ModuleConfiguration::class,
],
'settings' => [
//TODO: add help texts for settings to explain possibilities and point out which ones only serve as example
/** Main */
[
'group' => 'osctelecash_api',
'group' => ModuleSettingsServiceInterface::MODULE_CONFIG_API_VARGROUP,
'name' => ModuleSettingsServiceInterface::API_MODE,
'type' => 'select',
'constraints' => ModuleSettingsServiceInterface::API_MODE_SANDBOX . '|' . ModuleSettingsServiceInterface::API_MODE_LIVE,
'value' => ModuleSettingsServiceInterface::API_MODE_SANDBOX
],
[
'group' => ModuleSettingsServiceInterface::MODULE_CONFIG_API_VARGROUP,
'name' => ModuleSettingsServiceInterface::STORE_ID,
'type' => 'str',
'value' => '',
],
[
'group' => ModuleSettingsServiceInterface::MODULE_CONFIG_API_VARGROUP,
'name' => ModuleSettingsServiceInterface::USER_ID,
'type' => 'str',
'value' => '',
],
[
'group' => ModuleSettingsServiceInterface::MODULE_CONFIG_API_VARGROUP,
'name' => ModuleSettingsServiceInterface::BASIC_AUTH_PASSWORD,
'type' => 'str',
'value' => '',
],
[
'group' => ModuleSettingsServiceInterface::MODULE_CONFIG_API_VARGROUP,
'name' => ModuleSettingsServiceInterface::CLIENT_CERT_INSTALL_PASSWORD,
'type' => 'str',
'value' => '',
],
[
'group' => ModuleSettingsServiceInterface::MODULE_CONFIG_API_VARGROUP,
'name' => ModuleSettingsServiceInterface::CLIENT_CERT_PRIVATEKEY_PASSWORD,
'type' => 'str',
'value' => '',
],
// these options are hidden, so the group is null
[
'group' => null,
'name' => ModuleFileSettingsServiceInterface::CLIENT_CERT_P12_FILE,
'type' => 'str',
'value' => '',
],
[
'group' => null,
'name' => ModuleFileSettingsServiceInterface::CLIENT_CERT_PRIVATEKEY_FILE,
'type' => 'str',
'value' => '',
],
[
'group' => null,
'name' => ModuleFileSettingsServiceInterface::CLIENT_CERT_PEM_FILE,
'type' => 'str',
'value' => '',
],
[
'group' => null,
'name' => ModuleFileSettingsServiceInterface::TRUST_ANCHOR_PEM_FILE,
'type' => 'str',
'value' => '',
],
]
];
2 changes: 1 addition & 1 deletion services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ parameters:

imports:
- { resource: src/Settings/services.yaml }

- { resource: src/Core/services.yaml }
services:

_defaults:
Expand Down
25 changes: 25 additions & 0 deletions src/Core/Service/OxNewService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

namespace OxidSolutionCatalysts\TeleCash\Core\Service;

/**
* use this service as an alternative to oxid core oxNew, for writing more readable code and better unit tests
*/
class OxNewService
{
/**
* @template T of object
* @param class-string<T> $fqcn
* @param array<int|string, mixed> $constructorArgs
* @return T
*/
public function oxNew(string $fqcn, array $constructorArgs = []): object
{
return oxNew($fqcn, ...$constructorArgs);
}
}
53 changes: 53 additions & 0 deletions src/Core/Service/RegistryService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

namespace OxidSolutionCatalysts\TeleCash\Core\Service;

use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Language;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Request;
use OxidEsales\Eshop\Core\UtilsView;

class RegistryService
{
/**
* for better testing and to avoid "'static' methods cannot be mocked"
* @SuppressWarnings(PHPMD.StaticAccess)
*/
public function getConfig(): Config
{
return Registry::getConfig();
}

/**
* for better testing and to avoid "'static' methods cannot be mocked"
* @SuppressWarnings(PHPMD.StaticAccess)
*/
public function getLang(): Language
{
return Registry::getLang();
}

/**
* for better testing and to avoid "'static' methods cannot be mocked"
* @SuppressWarnings(PHPMD.StaticAccess)
*/
public function getRequest(): Request
{
return Registry::getRequest();
}

/**
* for better testing and to avoid "'static' methods cannot be mocked"
* @SuppressWarnings(PHPMD.StaticAccess)
*/
public function getUtilsView(): UtilsView
{
return Registry::getUtilsView();
}
}
12 changes: 12 additions & 0 deletions src/Core/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
_defaults:
public: false
autowire: true

OxidSolutionCatalysts\TeleCash\Core\Service\OxNewService:
class: OxidSolutionCatalysts\TeleCash\Core\Service\OxNewService
public: true

OxidSolutionCatalysts\TeleCash\Core\Service\RegistryService:
class: OxidSolutionCatalysts\TeleCash\Core\Service\RegistryService
public: true
140 changes: 140 additions & 0 deletions src/Extension/Application/Controller/Admin/ModuleConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidSolutionCatalysts\TeleCash\Extension\Application\Controller\Admin;

use Exception;
use OxidSolutionCatalysts\TeleCash\Core\Module;
use OxidSolutionCatalysts\TeleCash\Core\Service\RegistryService;
use OxidSolutionCatalysts\TeleCash\Settings\Service\ModuleFileSettingsService;
use OxidSolutionCatalysts\TeleCash\Settings\Service\ModuleFileSettingsServiceInterface;
use OxidSolutionCatalysts\TeleCash\Settings\Service\ModuleSettingsServiceInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class ModuleConfiguration extends ModuleConfiguration_parent
{
protected RegistryService $registryService;
protected ModuleFileSettingsServiceInterface $fileSettingsService;

public function __construct()
{
parent::__construct();
$this->fileSettingsService = $this->getService(ModuleFileSettingsServiceInterface::class);
$this->registryService = $this->getService(RegistryService::class);
}

/**
* OXID-Core
* @inheritDoc
* @return string
*/
public function render()
{
$result = parent::render();

$this->_aViewData['sTeleCashModuleId'] = Module::MODULE_ID;
$this->_aViewData['sTeleCashVarGroupAPI'] = ModuleSettingsServiceInterface::MODULE_CONFIG_API_VARGROUP;
$this->_aViewData['sTeleCashOptionTrigger'] = ModuleSettingsServiceInterface::CLIENT_CERT_PRIVATEKEY_PASSWORD;

// collect setted options for template
$fileSettingsService = $this->getService(ModuleFileSettingsServiceInterface::class);
$aTeleCashFiles = [];
foreach (ModuleFileSettingsService::TELECASH_GET_FILENAME_METHODS as $teleCashFile => $teleCashGetMethod) {
$aTeleCashFiles[$teleCashFile] = $fileSettingsService->$teleCashGetMethod($teleCashFile);
}
$this->_aViewData['aTeleCashFiles'] = $aTeleCashFiles;

return $result;
}

/**
* OXID-Core
* @inheritDoc
* @return void
*/
public function saveConfVars()
{
parent::saveConfVars();
$this->storeTeleCashFiles();
$this->deleteTeleCashFiles();
}


/**
* store the necessary telecash files
*
* @return void
*/
protected function storeTeleCashFiles(): void
{
$lang = $this->registryService->getLang();
$config = $this->registryService->getConfig();
$utilsView = $this->registryService->getUtilsView();

foreach (ModuleFileSettingsService::TELECASH_STORE_METHODS as $teleCashFile => $teleCashStoreMethod) {
/** @var array<string, mixed> $aFile */
$aFile = $config->getUploadedFile($teleCashFile);
if ($aFile !== null && !empty($aFile['name'])) {
$sTmpName = $aFile['tmp_name'] ?? '';
$sName = $aFile['name'];
$iError = $aFile['error'] ?? UPLOAD_ERR_NO_FILE;

if ($iError === UPLOAD_ERR_OK && is_uploaded_file($sTmpName)) {
try {
$uploadedFile = new UploadedFile(
$sTmpName,
$sName,
$aFile['type'],
$aFile['error'],
true
);

$this->fileSettingsService->$teleCashStoreMethod($uploadedFile);
/** @var string $translate */
$translate = $lang->translateString('TELECASH_FILE_UPLOAD_SUCCESSFUL');
$utilsView->addErrorToDisplay(sprintf(
$translate,
$sName
));
} catch (Exception $e) {
/** @var string $translate */
$translate = $lang->translateString('TELECASH_FILE_UPLOAD_ERROR');
$utilsView->addErrorToDisplay(sprintf(
$translate,
$e->getMessage()
));
}
} else {
/** @var string $translate */
$translate = $lang->translateString('TELECASH_FILE_UPLOAD_NOTVALID');
$utilsView->addErrorToDisplay(sprintf(
$translate,
$sName
));
}
}
}
}

/**
* delete the unnecessary telecash files
*
* @return void
*/
protected function deleteTeleCashFiles(): void
{
$request = $this->registryService->getRequest();

foreach (ModuleFileSettingsService::TELECASH_DELETE_METHODS as $teleCashFile => $teleCashDeleteMethod) {
if ($request->getRequestParameter($teleCashFile . '_delete')) {
$this->fileSettingsService->$teleCashDeleteMethod();
}
}
}
}
Loading

0 comments on commit a59da1b

Please sign in to comment.