feat: re-implement contact form submissions api endpoint for website
This commit is contained in:
@@ -9,6 +9,7 @@ use App\BusProNet\Model\BaseData;
|
||||
use App\BusProNet\Model\Booking;
|
||||
use App\BusProNet\Model\BookingResponse;
|
||||
use App\BusProNet\Model\BookingUpdate;
|
||||
use App\BusProNet\Model\ContactFormResponse;
|
||||
use App\BusProNet\Model\CrmAttributes;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use App\BusProNet\Model\PersonalData;
|
||||
@@ -137,6 +138,25 @@ class ApiClient
|
||||
return $this->sendRequest(static::TYPE_CUSTOMER_DATA, $data, [], $debug);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
class ContactFormResponse
|
||||
{
|
||||
public function __construct(
|
||||
public readonly int $addressId,
|
||||
public readonly int $personId,
|
||||
public readonly bool $isNewRecord,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -94,6 +94,25 @@ class PersonalData
|
||||
];
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts user claims for authentication and profile information.
|
||||
*
|
||||
|
||||
@@ -48,6 +48,9 @@ class HotelLoader extends AbstractLoader
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws HotelNotFoundException
|
||||
*/
|
||||
public function loadById(int $id, ?string $filename = 'hotel.xml'): Hotel
|
||||
{
|
||||
$hotels = $this->loadAll($filename);
|
||||
|
||||
@@ -36,6 +36,8 @@ class ApiResponseParser extends AbstractParser
|
||||
case 'Adressdaten_Ändern':
|
||||
case 'Newsletter':
|
||||
return (new PersonalDataParser())->parse($resultNode);
|
||||
case 'Adresse_Neu':
|
||||
return (new ContactFormResponseParser())->parse($resultNode);
|
||||
case 'SelektionCRM':
|
||||
case 'SelektionCRM_Ändern':
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user