feat: backport contact form api endpoint
This commit is contained in:
@@ -53,3 +53,19 @@ GET {{base_url}}/api/travels/DWWWE211125
|
|||||||
Accept: application/json
|
Accept: application/json
|
||||||
Authorization: Bearer {{$auth.token("oauth2_api")}}
|
Authorization: Bearer {{$auth.token("oauth2_api")}}
|
||||||
|
|
||||||
|
### API contact form
|
||||||
|
POST {{base_url}}/api/contactform
|
||||||
|
Accept: application/json
|
||||||
|
Content-Type: application/json
|
||||||
|
Authorization: Bearer {{$auth.token("oauth2_api")}}
|
||||||
|
|
||||||
|
{
|
||||||
|
"lastName": "Duschen",
|
||||||
|
"firstName": "Isolde",
|
||||||
|
"gender": "f",
|
||||||
|
"street": "Fooroad 1",
|
||||||
|
"zipCode": "12345",
|
||||||
|
"city": "Bartown",
|
||||||
|
"email": "[email protected]",
|
||||||
|
"phone": "12345"
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use App\BusProNet\Exception\ResponseParserException;
|
|||||||
use App\BusProNet\Model\BaseData;
|
use App\BusProNet\Model\BaseData;
|
||||||
use App\BusProNet\Model\Booking;
|
use App\BusProNet\Model\Booking;
|
||||||
use App\BusProNet\Model\BookingUpdate;
|
use App\BusProNet\Model\BookingUpdate;
|
||||||
|
use App\BusProNet\Model\ContactFormResponse;
|
||||||
use App\BusProNet\Model\CrmAttributes;
|
use App\BusProNet\Model\CrmAttributes;
|
||||||
use App\BusProNet\Model\Notification;
|
use App\BusProNet\Model\Notification;
|
||||||
use App\BusProNet\Model\PersonalData;
|
use App\BusProNet\Model\PersonalData;
|
||||||
@@ -62,6 +63,23 @@ class ApiClient
|
|||||||
return $this->sendRequest(static::TYPE_CUSTOMER_DATA, $data);
|
return $this->sendRequest(static::TYPE_CUSTOMER_DATA, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ApiClientException
|
||||||
|
*/
|
||||||
|
public function createAddress(PersonalData $personalData, bool $debug = false): ContactFormResponse|Notification
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'user' => $this->config['bpn_username'],
|
||||||
|
'key' => $this->createKey($this->config['bpn_username'], $this->config['bpn_password'], static::TYPE_CUSTOMER_DATA),
|
||||||
|
'satz' => ['@typ' => static::TYPE_CUSTOMER_DATA],
|
||||||
|
'art' => 'Adresse_Neu',
|
||||||
|
'adressdaten' => $personalData->toPayload(),
|
||||||
|
'ohnemailversand' => 'True',
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->sendRequest(static::TYPE_CUSTOMER_DATA, $data, [], $debug);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ApiClientException
|
* @throws ApiClientException
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\BusProNet\Model;
|
||||||
|
|
||||||
|
class ContactFormResponse
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public readonly int $addressId,
|
||||||
|
public readonly int $personId,
|
||||||
|
public readonly bool $isNewRecord,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\BusProNet\Model;
|
||||||
|
|
||||||
|
class ContactFormSubmission
|
||||||
|
{
|
||||||
|
public ?string $lastName = null;
|
||||||
|
public ?string $firstName = null;
|
||||||
|
public ?string $gender = null;
|
||||||
|
public ?string $street = null;
|
||||||
|
public ?string $zipCode = null;
|
||||||
|
public ?string $city = null;
|
||||||
|
public ?string $email = null;
|
||||||
|
public ?string $phone = null;
|
||||||
|
}
|
||||||
@@ -39,6 +39,25 @@ class PersonalData
|
|||||||
$this->communication = new Communication();
|
$this->communication = new Communication();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function fromContactFormSubmission(ContactFormSubmission $dto): self
|
||||||
|
{
|
||||||
|
$gender = null !== $dto->gender ? strtoupper($dto->gender) : null;
|
||||||
|
if ('F' === $gender) {
|
||||||
|
$gender = 'W';
|
||||||
|
}
|
||||||
|
$instance = new self();
|
||||||
|
$instance->name = $dto->lastName;
|
||||||
|
$instance->firstName = $dto->firstName;
|
||||||
|
$instance->gender = $gender;
|
||||||
|
$instance->address->street = $dto->street;
|
||||||
|
$instance->address->postCode = $dto->zipCode;
|
||||||
|
$instance->address->city = $dto->city;
|
||||||
|
$instance->communication->email = $dto->email;
|
||||||
|
$instance->communication->phone = $dto->phone;
|
||||||
|
|
||||||
|
return $instance;
|
||||||
|
}
|
||||||
|
|
||||||
public function toPayload(): array
|
public function toPayload(): array
|
||||||
{
|
{
|
||||||
// Ensure date of birth is populated
|
// Ensure date of birth is populated
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ class ApiResponseParser extends AbstractParser
|
|||||||
case 'Adressdaten_Ändern':
|
case 'Adressdaten_Ändern':
|
||||||
case 'Newsletter':
|
case 'Newsletter':
|
||||||
return (new PersonalDataParser())->parse($resultNode);
|
return (new PersonalDataParser())->parse($resultNode);
|
||||||
|
case 'Adresse_Neu':
|
||||||
|
return (new ContactFormResponseParser())->parse($resultNode);
|
||||||
case 'SelektionCRM':
|
case 'SelektionCRM':
|
||||||
case 'SelektionCRM_Ändern':
|
case 'SelektionCRM_Ändern':
|
||||||
return (new CrmAttributesResponseParser())->parse($resultNode);
|
return (new CrmAttributesResponseParser())->parse($resultNode);
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\BusProNet\XmlParser;
|
||||||
|
|
||||||
|
use App\BusProNet\Model\ContactFormResponse;
|
||||||
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
|
|
||||||
|
class ContactFormResponseParser extends AbstractParser
|
||||||
|
{
|
||||||
|
public function parse(Crawler $node): ContactFormResponse
|
||||||
|
{
|
||||||
|
$addressId = (int) $node->filterXPath('//idadresse')->text();
|
||||||
|
$personId = (int) $node->filterXPath('//idperson')->text();
|
||||||
|
$isNewRecord = $this->getBoolValue($node->filterXPath('//neuanlage'));
|
||||||
|
|
||||||
|
return new ContactFormResponse(
|
||||||
|
addressId: $addressId,
|
||||||
|
personId: $personId,
|
||||||
|
isNewRecord: $isNewRecord,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller\Api;
|
||||||
|
|
||||||
|
use App\BusProNet\ApiClient;
|
||||||
|
use App\BusProNet\Exception\ApiClientException;
|
||||||
|
use App\BusProNet\Model\ContactFormSubmission;
|
||||||
|
use App\BusProNet\Model\Notification;
|
||||||
|
use App\BusProNet\Model\PersonalData;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||||
|
|
||||||
|
#[Route('/api')]
|
||||||
|
#[IsGranted('ROLE_OAUTH2_API')]
|
||||||
|
class ContactFormController extends AbstractController
|
||||||
|
{
|
||||||
|
public function __construct(private readonly ApiClient $apiClient)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/contactform', name: 'api_contacform', methods: ['POST'])]
|
||||||
|
public function index(#[MapRequestPayload] ContactFormSubmission $dto): JsonResponse
|
||||||
|
{
|
||||||
|
$personalData = PersonalData::fromContactFormSubmission($dto);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$result = $this->apiClient->createAddress($personalData);
|
||||||
|
|
||||||
|
if ($result instanceof Notification) {
|
||||||
|
return new JsonResponse([
|
||||||
|
'success' => false,
|
||||||
|
'message' => $result->message,
|
||||||
|
], Response::HTTP_CONFLICT);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->json([
|
||||||
|
'success' => true,
|
||||||
|
'addressId' => $result->addressId,
|
||||||
|
'personId' => $result->personId,
|
||||||
|
'isNewRecord' => $result->isNewRecord,
|
||||||
|
], Response::HTTP_CREATED);
|
||||||
|
} catch (ApiClientException $e) {
|
||||||
|
return new JsonResponse([
|
||||||
|
'success' => false,
|
||||||
|
'message' => $e->getMessage(),
|
||||||
|
], Response::HTTP_BAD_REQUEST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user