Merge branch 'feature/bpn-api' into develop

This commit is contained in:
Björn Fromme
2019-10-02 16:25:48 +02:00
40 changed files with 1323 additions and 1095 deletions
@@ -26,6 +26,7 @@ namespace EP\EpTheme\Controller;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use EP\EpTheme\Service\BookingApiService;
use EP\EpTheme\Service\EmailService;
use EP\EpTheme\Domain\Model\Dto\ContactForm;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
@@ -40,12 +41,20 @@ class AjaxFormController extends ActionController
protected $emailService;
/**
* @param EmailService $emailService
* @var BookingApiService
*/
public function __construct(EmailService $emailService)
protected $bookingApiService;
/**
* @param EmailService $emailService
* @param BookingApiService $bookingApiService
*/
public function __construct(EmailService $emailService, BookingApiService $bookingApiService)
{
parent::__construct();
$this->emailService = $emailService;
$this->bookingApiService = $bookingApiService;
}
/**
@@ -63,6 +72,15 @@ class AjaxFormController extends ActionController
[ 'contactForm' => $contactForm ]
);
$addressData = [
'lastName' => $contactForm->getName(),
'firstName' => $contactForm->getFirstName(),
'email' => $contactForm->getEmail(),
'gender' => $contactForm->getGender(),
];
$this->bookingApiService->registerAddress($addressData);
return json_encode($response);
}
@@ -42,6 +42,18 @@ class ContactForm
*/
protected $name;
/**
* @var string
* @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty")
*/
protected $firstName;
/**
* @var string
* @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty")
*/
protected $gender;
/**
* @var string
*/
@@ -121,6 +133,38 @@ class ContactForm
$this->name = $name;
}
/**
* @return string
*/
public function getFirstName()
{
return $this->firstName;
}
/**
* @param string $firstName
*/
public function setFirstName($firstName)
{
$this->firstName = $firstName;
}
/**
* @return string
*/
public function getGender()
{
return $this->gender;
}
/**
* @param string $gender
*/
public function setGender($gender)
{
$this->gender = $gender;
}
/**
* @return string
*/
@@ -0,0 +1,52 @@
<?php
namespace EP\EpTheme\Form;
/***************************************************************
*
* Copyright notice
*
* (c) 2019 Björn Fromme <[email protected]>, dreipunktnull
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use EP\EpTheme\Service\BookingApiService;
use TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher;
class BpnApiFinisher extends AbstractFinisher
{
/**
* @var BookingApiService
*/
protected $bookingApiService;
/**
* @param BookingApiService $bookingApiService
*/
public function injectBookingApiService(BookingApiService $bookingApiService)
{
$this->bookingApiService = $bookingApiService;
}
protected function executeInternal()
{
$formValues = $this->finisherContext->getFormValues();
$this->bookingApiService->registerAddress($formValues);
}
}
@@ -0,0 +1,91 @@
<?php
namespace EP\EpTheme\Service;
/***************************************************************
*
* Copyright notice
*
* (c) 2019 Björn Fromme <[email protected]>, dreipunktnull
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
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, LoggerAwareInterface
{
use LoggerAwareTrait;
/**
* @var string
*/
protected $apiToken;
/**
* @var string
*/
protected $apiEndpointUrl;
/**
* @var int
*/
protected $apiTimeout;
/**
* @param ConfigurationManagerInterface $manager
*/
public function __construct(ConfigurationManagerInterface $manager)
{
$settings = GeneralUtility::removeDotsFromTS(
$manager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT)
);
$this->apiToken = $settings['plugin']['tx_eptheme']['settings']['myEpApiToken'];
$this->apiEndpointUrl = $settings['plugin']['tx_eptheme']['settings']['myEpApiEndpointUrl'];
$this->apiTimeout = $settings['plugin']['tx_eptheme']['settings']['myEpApiTimeout'];
}
/**
* @param array $addressData
*/
public function registerAddress(array $addressData)
{
$client = HttpClient::create();
try {
$client->request('POST', $this->apiEndpointUrl . '/api/contactform', [
'headers' => [
'X-AUTH-TOKEN' => $this->apiToken,
'Content-type' => 'application/json',
],
'timeout' => $this->apiTimeout,
'body' => json_encode($addressData),
]);
}
catch (TransportExceptionInterface $e) {
$this->logger->error($e->getMessage());
}
}
}