Finalize contact form handling via API
This commit is contained in:
@@ -3,6 +3,8 @@
|
|||||||
namespace EP\EpTheme\Form;
|
namespace EP\EpTheme\Form;
|
||||||
|
|
||||||
use EP\EpTheme\Service\BookingApiService;
|
use EP\EpTheme\Service\BookingApiService;
|
||||||
|
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
use TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher;
|
use TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher;
|
||||||
|
|
||||||
class BpnApiFinisher extends AbstractFinisher
|
class BpnApiFinisher extends AbstractFinisher
|
||||||
@@ -26,16 +28,26 @@ class BpnApiFinisher extends AbstractFinisher
|
|||||||
protected function executeInternal()
|
protected function executeInternal()
|
||||||
{
|
{
|
||||||
$formValues = $this->finisherContext->getFormValues();
|
$formValues = $this->finisherContext->getFormValues();
|
||||||
|
$optionsResolver = new OptionsResolver();
|
||||||
|
$optionsResolver->setRequired(['lastName', 'firstName', 'gender', 'email']);
|
||||||
|
$optionsResolver->setDefined([
|
||||||
|
'lastName', 'firstName', 'gender', 'email', 'street', 'zipCode', 'city', 'phone'
|
||||||
|
]);
|
||||||
$addressData = [
|
$addressData = [
|
||||||
'lastName' => $formValues['name'],
|
'lastName' => $formValues['name'],
|
||||||
'firstName' => $formValues['vorname'],
|
'firstName' => $formValues['firstName'],
|
||||||
'gender' => $formValues['geschlecht'],
|
'gender' => $formValues['gender'],
|
||||||
'email' => $formValues['email'],
|
'email' => $formValues['email'],
|
||||||
'street' => $formValues['strasse'],
|
'street' => $formValues['street'],
|
||||||
'zipCode' => $formValues['plz'],
|
'zipCode' => $formValues['zipCode'],
|
||||||
'city' => $formValues['ort'],
|
'city' => $formValues['city'],
|
||||||
'phone' => $formValues['telefon'],
|
'phone' => $formValues['phone'],
|
||||||
];
|
];
|
||||||
$this->bookingApiService->registerAddress($addressData);
|
try {
|
||||||
|
$sanitizedFormData = $optionsResolver->resolve($addressData);
|
||||||
|
$this->bookingApiService->registerAddress($sanitizedFormData);
|
||||||
|
}
|
||||||
|
catch (MissingOptionsException $e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,15 +2,18 @@
|
|||||||
|
|
||||||
namespace EP\EpTheme\Service;
|
namespace EP\EpTheme\Service;
|
||||||
|
|
||||||
use Symfony\Component\HttpClient\Exception\ServerException;
|
use Psr\Log\LoggerAwareInterface;
|
||||||
|
use Psr\Log\LoggerAwareTrait;
|
||||||
use Symfony\Component\HttpClient\HttpClient;
|
use Symfony\Component\HttpClient\HttpClient;
|
||||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
use TYPO3\CMS\Core\SingletonInterface;
|
use TYPO3\CMS\Core\SingletonInterface;
|
||||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
||||||
|
|
||||||
class BookingApiService implements SingletonInterface
|
class BookingApiService implements SingletonInterface, LoggerAwareInterface
|
||||||
{
|
{
|
||||||
|
use LoggerAwareTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@@ -21,6 +24,11 @@ class BookingApiService implements SingletonInterface
|
|||||||
*/
|
*/
|
||||||
protected $apiEndpointUrl;
|
protected $apiEndpointUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $apiTimeout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ConfigurationManagerInterface $manager
|
* @param ConfigurationManagerInterface $manager
|
||||||
*/
|
*/
|
||||||
@@ -31,27 +39,31 @@ class BookingApiService implements SingletonInterface
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->apiToken = $settings['plugin']['tx_eptheme']['settings']['myEpApiToken'];
|
$this->apiToken = $settings['plugin']['tx_eptheme']['settings']['myEpApiToken'];
|
||||||
$this->apiEndpointUrl = $settings['plugin']['tx_eptheme']['settings']['myEpApiBaseUrl'];
|
$this->apiEndpointUrl = $settings['plugin']['tx_eptheme']['settings']['myEpApiEndpointUrl'];
|
||||||
|
$this->apiTimeout = $settings['plugin']['tx_eptheme']['settings']['myEpApiTimeout'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $addressData
|
* @param array $addressData
|
||||||
|
* @throws TransportExceptionInterface
|
||||||
*/
|
*/
|
||||||
public function registerAddress(array $addressData)
|
public function registerAddress(array $addressData)
|
||||||
{
|
{
|
||||||
$client = HttpClient::create();
|
$client = HttpClient::create();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$client->request('POST', $this->apiEndpointUrl . '/booking/address', [
|
$client->request('POST', $this->apiEndpointUrl, [
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'X-AUTH-TOKEN' => $this->apiToken,
|
'X-AUTH-TOKEN' => $this->apiToken,
|
||||||
|
'Content-type' => 'application/json',
|
||||||
],
|
],
|
||||||
'body' => $addressData,
|
'timeout' => $this->apiTimeout,
|
||||||
|
'body' => json_encode($addressData),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
catch (TransportExceptionInterface $e)
|
catch (\Exception $e)
|
||||||
{}
|
{
|
||||||
catch (ServerException $e)
|
$this->logger->error($e->getMessage());
|
||||||
{}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -156,10 +156,12 @@ plugin.tx_eptheme {
|
|||||||
# cat=eptheme.events; type=string; label=Partner ID selection label
|
# cat=eptheme.events; type=string; label=Partner ID selection label
|
||||||
partnerIdSelectLabel =
|
partnerIdSelectLabel =
|
||||||
|
|
||||||
# cat=eptheme/900/100; type=string; label=MyE&P API base url
|
# cat=eptheme/900/100; type=string; label=MyE&P API endpoint url for contactforms
|
||||||
myEpApiBaseUrl =
|
myEpApiEndpointUrl = https://myep.burn.dpn/api/contactform
|
||||||
# cat=eptheme/900/110; type=string; label=MyE&P API auth token
|
# cat=eptheme/900/110; type=string; label=MyE&P API timeout in seconds
|
||||||
myEpApiToken =
|
myEpApiTimeout = 10
|
||||||
|
# cat=eptheme/900/120; type=string; label=MyE&P API auth token
|
||||||
|
myEpApiToken = thisisnotsecretsochangeit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,8 +87,9 @@ plugin.tx_eptheme {
|
|||||||
germanPageUid = {$plugin.tx_eptheme.settings.germanPageUid}
|
germanPageUid = {$plugin.tx_eptheme.settings.germanPageUid}
|
||||||
conceptsPageUid = {$plugin.tx_eptheme.settings.conceptsPageUid}
|
conceptsPageUid = {$plugin.tx_eptheme.settings.conceptsPageUid}
|
||||||
myEpPageUid = {$plugin.tx_eptheme.settings.myEpPageUid}
|
myEpPageUid = {$plugin.tx_eptheme.settings.myEpPageUid}
|
||||||
myEpApiBaseUrl = {$plugin.tx_eptheme.settings.myEpApiBaseUrl}
|
myEpApiEndpointUrl = {$plugin.tx_eptheme.settings.myEpApiEndpointUrl}
|
||||||
myEpApiToken = {$plugin.tx_eptheme.settings.myEpApiToken}
|
myEpApiToken = {$plugin.tx_eptheme.settings.myEpApiToken}
|
||||||
|
myEpApiTimeout = {$plugin.tx_eptheme.settings.myEpApiTimeout}
|
||||||
facebookViewContentValues {
|
facebookViewContentValues {
|
||||||
productUid = {$plugin.tx_eptheme.settings.facebookViewContentProductUid}
|
productUid = {$plugin.tx_eptheme.settings.facebookViewContentProductUid}
|
||||||
nameInternal = {$plugin.tx_eptheme.settings.facebookViewContentNameInternal}
|
nameInternal = {$plugin.tx_eptheme.settings.facebookViewContentNameInternal}
|
||||||
|
|||||||
Reference in New Issue
Block a user