Finalize contact form handling via API

This commit is contained in:
Björn Fromme
2019-10-01 17:17:10 +02:00
parent 2bcc3108e4
commit f193fa9419
4 changed files with 48 additions and 21 deletions
@@ -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());
}
}
}