feat: backport contact form api endpoint
This commit is contained in:
@@ -8,6 +8,7 @@ use App\BusProNet\Exception\ResponseParserException;
|
||||
use App\BusProNet\Model\BaseData;
|
||||
use App\BusProNet\Model\Booking;
|
||||
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;
|
||||
@@ -62,6 +63,23 @@ class ApiClient
|
||||
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
|
||||
*/
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
// Ensure date of birth is populated
|
||||
|
||||
@@ -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