120 lines
3.5 KiB
PHP
120 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\BusProNet\Client;
|
|
|
|
use App\BusProNet\Exception\ApiClientException;
|
|
use App\BusProNet\MessageType;
|
|
use App\BusProNet\Model\CrmAttributes;
|
|
use App\BusProNet\Model\Notification;
|
|
use App\BusProNet\Model\PersonalData;
|
|
use App\BusProNet\Model\PersonalDataUpdateResponse;
|
|
use App\BusProNet\Model\RegistrationResponse;
|
|
use App\BusProNet\Transport\XmlChannel;
|
|
use App\Form\Model\RegistrationDto;
|
|
|
|
/**
|
|
* A customer's BusPro account: login, address data, newsletter, CRM selections.
|
|
*/
|
|
class AccountClient
|
|
{
|
|
public function __construct(
|
|
private readonly XmlChannel $channel,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @throws ApiClientException
|
|
*/
|
|
public function getPersonalData(string $email, string $password): Notification|PersonalData
|
|
{
|
|
return $this->channel->request(MessageType::CustomerData, [
|
|
'art' => 'Adressdaten',
|
|
'email' => $email,
|
|
'passwort' => $password,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @throws ApiClientException
|
|
*/
|
|
public function register(RegistrationDto $registrationData): Notification|RegistrationResponse
|
|
{
|
|
return $this->channel->request(MessageType::CustomerData, [
|
|
'art' => 'Adresse_Neu',
|
|
'adressdaten' => $registrationData->toPayload(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @throws ApiClientException
|
|
*/
|
|
public function resetPassword(string $email): Notification
|
|
{
|
|
return $this->channel->request(MessageType::CustomerData, [
|
|
'art' => 'Passwort_Anfrage',
|
|
'email' => $email,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @throws ApiClientException
|
|
*/
|
|
public function updatePersonalData(
|
|
string $email,
|
|
string $password,
|
|
PersonalData $personalData,
|
|
bool $debug = false,
|
|
): Notification|PersonalDataUpdateResponse {
|
|
return $this->channel->request(MessageType::CustomerData, [
|
|
'art' => 'Adressdaten_Ändern',
|
|
'email' => $email,
|
|
'passwort' => $password,
|
|
'idadresse' => $personalData->addressId,
|
|
'adressdaten' => $personalData->toPayload(),
|
|
], [], $debug);
|
|
}
|
|
|
|
/**
|
|
* @throws ApiClientException
|
|
*/
|
|
public function createAddress(
|
|
PersonalData $personalData,
|
|
bool $debug = false,
|
|
): RegistrationResponse|Notification {
|
|
return $this->channel->request(MessageType::CustomerData, [
|
|
'art' => 'Adresse_Neu',
|
|
'adressdaten' => $personalData->toPayload(false),
|
|
'ohnemailversand' => 'True',
|
|
], [], $debug);
|
|
}
|
|
|
|
/**
|
|
* @throws ApiClientException
|
|
*/
|
|
public function updateNewsletterRegistration(string $email, string $password, PersonalData $personalData): Notification|PersonalData
|
|
{
|
|
return $this->channel->request(MessageType::CustomerData, [
|
|
'art' => 'Newsletter',
|
|
'email' => $email,
|
|
'passwort' => $password,
|
|
'idadresse' => $personalData->addressId,
|
|
'newsletter' => [
|
|
'email' => $email,
|
|
'anmeldung' => $personalData->communication->newsletter ? 'True' : 'False',
|
|
],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @throws ApiClientException
|
|
*/
|
|
public function getCrmAttributes(string $email, string $password): Notification|CrmAttributes
|
|
{
|
|
return $this->channel->request(MessageType::CustomerData, [
|
|
'art' => 'SelektionCRM',
|
|
'email' => $email,
|
|
'passwort' => $password,
|
|
]);
|
|
}
|
|
}
|