diff --git a/public/typo3conf/ext/ep_theme/Classes/Form/BpnApiFinisher.php b/public/typo3conf/ext/ep_theme/Classes/Form/BpnApiFinisher.php index fa93c3ba..93195475 100644 --- a/public/typo3conf/ext/ep_theme/Classes/Form/BpnApiFinisher.php +++ b/public/typo3conf/ext/ep_theme/Classes/Form/BpnApiFinisher.php @@ -3,6 +3,8 @@ namespace EP\EpTheme\Form; use EP\EpTheme\Service\BookingApiService; +use Symfony\Component\OptionsResolver\Exception\MissingOptionsException; +use Symfony\Component\OptionsResolver\OptionsResolver; use TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher; class BpnApiFinisher extends AbstractFinisher @@ -26,16 +28,26 @@ class BpnApiFinisher extends AbstractFinisher protected function executeInternal() { $formValues = $this->finisherContext->getFormValues(); + $optionsResolver = new OptionsResolver(); + $optionsResolver->setRequired(['lastName', 'firstName', 'gender', 'email']); + $optionsResolver->setDefined([ + 'lastName', 'firstName', 'gender', 'email', 'street', 'zipCode', 'city', 'phone' + ]); $addressData = [ 'lastName' => $formValues['name'], - 'firstName' => $formValues['vorname'], - 'gender' => $formValues['geschlecht'], + 'firstName' => $formValues['firstName'], + 'gender' => $formValues['gender'], 'email' => $formValues['email'], - 'street' => $formValues['strasse'], - 'zipCode' => $formValues['plz'], - 'city' => $formValues['ort'], - 'phone' => $formValues['telefon'], + 'street' => $formValues['street'], + 'zipCode' => $formValues['zipCode'], + 'city' => $formValues['city'], + 'phone' => $formValues['phone'], ]; - $this->bookingApiService->registerAddress($addressData); + try { + $sanitizedFormData = $optionsResolver->resolve($addressData); + $this->bookingApiService->registerAddress($sanitizedFormData); + } + catch (MissingOptionsException $e) { + } } } \ No newline at end of file diff --git a/public/typo3conf/ext/ep_theme/Classes/Service/BookingApiService.php b/public/typo3conf/ext/ep_theme/Classes/Service/BookingApiService.php index d24809b4..a2133cf6 100644 --- a/public/typo3conf/ext/ep_theme/Classes/Service/BookingApiService.php +++ b/public/typo3conf/ext/ep_theme/Classes/Service/BookingApiService.php @@ -2,15 +2,18 @@ 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\Contracts\HttpClient\Exception\TransportExceptionInterface; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; -class BookingApiService implements SingletonInterface +class BookingApiService implements SingletonInterface, LoggerAwareInterface { + use LoggerAwareTrait; + /** * @var string */ @@ -21,6 +24,11 @@ class BookingApiService implements SingletonInterface */ protected $apiEndpointUrl; + /** + * @var int + */ + protected $apiTimeout; + /** * @param ConfigurationManagerInterface $manager */ @@ -31,27 +39,31 @@ class BookingApiService implements SingletonInterface ); $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 + * @throws TransportExceptionInterface */ public function registerAddress(array $addressData) { $client = HttpClient::create(); try { - $client->request('POST', $this->apiEndpointUrl . '/booking/address', [ + $client->request('POST', $this->apiEndpointUrl, [ 'headers' => [ 'X-AUTH-TOKEN' => $this->apiToken, + 'Content-type' => 'application/json', ], - 'body' => $addressData, + 'timeout' => $this->apiTimeout, + 'body' => json_encode($addressData), ]); } - catch (TransportExceptionInterface $e) - {} - catch (ServerException $e) - {} + catch (\Exception $e) + { + $this->logger->error($e->getMessage()); + } } } \ No newline at end of file diff --git a/public/typo3conf/ext/ep_theme/Configuration/TypoScript/constants.typoscript b/public/typo3conf/ext/ep_theme/Configuration/TypoScript/constants.typoscript index 948691ec..114b9ba5 100644 --- a/public/typo3conf/ext/ep_theme/Configuration/TypoScript/constants.typoscript +++ b/public/typo3conf/ext/ep_theme/Configuration/TypoScript/constants.typoscript @@ -156,10 +156,12 @@ plugin.tx_eptheme { # cat=eptheme.events; type=string; label=Partner ID selection label partnerIdSelectLabel = - # cat=eptheme/900/100; type=string; label=MyE&P API base url - myEpApiBaseUrl = - # cat=eptheme/900/110; type=string; label=MyE&P API auth token - myEpApiToken = + # cat=eptheme/900/100; type=string; label=MyE&P API endpoint url for contactforms + myEpApiEndpointUrl = https://myep.burn.dpn/api/contactform + # cat=eptheme/900/110; type=string; label=MyE&P API timeout in seconds + myEpApiTimeout = 10 + # cat=eptheme/900/120; type=string; label=MyE&P API auth token + myEpApiToken = thisisnotsecretsochangeit } } diff --git a/public/typo3conf/ext/ep_theme/Configuration/TypoScript/setup.typoscript b/public/typo3conf/ext/ep_theme/Configuration/TypoScript/setup.typoscript index 9779a299..5d7df14c 100644 --- a/public/typo3conf/ext/ep_theme/Configuration/TypoScript/setup.typoscript +++ b/public/typo3conf/ext/ep_theme/Configuration/TypoScript/setup.typoscript @@ -87,8 +87,9 @@ plugin.tx_eptheme { germanPageUid = {$plugin.tx_eptheme.settings.germanPageUid} conceptsPageUid = {$plugin.tx_eptheme.settings.conceptsPageUid} myEpPageUid = {$plugin.tx_eptheme.settings.myEpPageUid} - myEpApiBaseUrl = {$plugin.tx_eptheme.settings.myEpApiBaseUrl} + myEpApiEndpointUrl = {$plugin.tx_eptheme.settings.myEpApiEndpointUrl} myEpApiToken = {$plugin.tx_eptheme.settings.myEpApiToken} + myEpApiTimeout = {$plugin.tx_eptheme.settings.myEpApiTimeout} facebookViewContentValues { productUid = {$plugin.tx_eptheme.settings.facebookViewContentProductUid} nameInternal = {$plugin.tx_eptheme.settings.facebookViewContentNameInternal}