107 lines
3.3 KiB
PHP
107 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\BusProNet\Client;
|
|
|
|
use App\BusProNet\Constants;
|
|
use App\BusProNet\DataProcessor\BookingDataProcessor;
|
|
use App\BusProNet\Exception\ApiClientException;
|
|
use App\BusProNet\MessageType;
|
|
use App\BusProNet\Model\BaseData;
|
|
use App\BusProNet\Model\Booking;
|
|
use App\BusProNet\Model\BookingResponse;
|
|
use App\BusProNet\Model\BookingUpdate;
|
|
use App\BusProNet\Model\Notification;
|
|
use App\BusProNet\Transport\XmlChannel;
|
|
use App\Form\Model\BookingDto;
|
|
|
|
/**
|
|
* A customer's bookings: listing, details and documents, creating and changing them.
|
|
*/
|
|
class BookingClient
|
|
{
|
|
public function __construct(
|
|
private readonly XmlChannel $channel,
|
|
private readonly BookingDataProcessor $bookingDataProcessor,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @throws ApiClientException
|
|
*/
|
|
public function getBookings(string $email, string $password): Notification|BaseData
|
|
{
|
|
return $this->channel->request(MessageType::CustomerData, [
|
|
'art' => 'Vorgänge',
|
|
'email' => $email,
|
|
'passwort' => $password,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @throws ApiClientException
|
|
*/
|
|
public function getBooking(string $email, string $password, int $id): Notification|Booking
|
|
{
|
|
return $this->channel->request(MessageType::CustomerData, [
|
|
'art' => 'Vorgang_Details',
|
|
'email' => $email,
|
|
'passwort' => $password,
|
|
'idbuchung' => $id,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @throws ApiClientException
|
|
*/
|
|
public function getDocuments(string $email, string $password, int $bookingId, string $type): mixed
|
|
{
|
|
return $this->channel->request(MessageType::CustomerData, [
|
|
'art' => $type,
|
|
'email' => $email,
|
|
'passwort' => $password,
|
|
'idbuchung' => $bookingId,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @throws ApiClientException
|
|
*/
|
|
public function updateBooking(BookingDto $formData, bool $debug = false): Notification|BookingUpdate
|
|
{
|
|
return $this->channel->request(MessageType::BookingUpdate, [
|
|
'buchungsart' => Constants::BOOKING_TYPE_BOOKING,
|
|
...$this->bookingDataProcessor->createUpdateRequestPayload($formData),
|
|
], [], $debug);
|
|
}
|
|
|
|
/**
|
|
* First phase of the two-phase booking process: validates the booking and returns the
|
|
* prices without creating it.
|
|
*
|
|
* @throws ApiClientException
|
|
*/
|
|
public function createBookingInquiry(BookingDto $bookingDto, bool $debug = false): Notification|BookingResponse
|
|
{
|
|
return $this->sendBooking($bookingDto, Constants::BOOKING_TYPE_INQUIRY, $debug);
|
|
}
|
|
|
|
/**
|
|
* Second phase of the two-phase booking process: creates the booking after a successful
|
|
* inquiry.
|
|
*
|
|
* @throws ApiClientException
|
|
*/
|
|
public function createBooking(BookingDto $bookingDto, bool $debug = false): Notification|BookingResponse
|
|
{
|
|
return $this->sendBooking($bookingDto, Constants::BOOKING_TYPE_BOOKING, $debug);
|
|
}
|
|
|
|
/**
|
|
* @throws ApiClientException
|
|
*/
|
|
private function sendBooking(BookingDto $bookingDto, string $bookingType, bool $debug): Notification|BookingResponse
|
|
{
|
|
return $this->channel->request(MessageType::Booking, $this->bookingDataProcessor->createBookingRequestPayload($bookingDto, $bookingType), [], $debug);
|
|
}
|
|
}
|