81 lines
2.6 KiB
PHP
81 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\BusProNet\DataProcessor;
|
|
|
|
use App\Form\Model\VoucherPurchaseDto;
|
|
|
|
/**
|
|
* Builds the GUTSCHEINBUCHUNG and GUTSCHEINVORSCHAU payloads from the voucher purchase DTO.
|
|
*
|
|
* The buyer goes into <rechnungsempfänger> and nothing else: linking the purchase to a customer
|
|
* record is BusPro's business. The <zahlung> attributes are echoed from GUTSCHEINZAHLUNGSARTEN.
|
|
*/
|
|
class VoucherSalePayloadBuilder
|
|
{
|
|
/**
|
|
* @param string $saleType Constants::BOOKING_TYPE_INQUIRY for the dry run, Constants::BOOKING_TYPE_BOOKING for the purchase
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function buildSalePayload(VoucherPurchaseDto $dto, string $saleType): array
|
|
{
|
|
if (null === $dto->template || null === $dto->paymentMethod) {
|
|
throw new \LogicException('A voucher sale needs a template and a payment method.');
|
|
}
|
|
|
|
$communication = [
|
|
'telefonprivat' => $dto->phone,
|
|
'email' => $dto->email,
|
|
];
|
|
// Not in the vendor's GUTSCHEINBUCHUNG example; the element name is the one BUCHUNG uses.
|
|
if (null !== $dto->mobile && '' !== trim($dto->mobile)) {
|
|
$communication['telefonmobil'] = $dto->mobile;
|
|
}
|
|
|
|
return [
|
|
'buchungsart' => $saleType,
|
|
'gutscheinart' => $dto->template->type,
|
|
'idgutscheinvorlage' => $dto->template->id,
|
|
'kaeufer' => $dto->from,
|
|
'empfaenger' => $dto->to,
|
|
'kaufpreis' => $dto->amount,
|
|
'text' => '',
|
|
'rechnungsempfänger' => [
|
|
'name' => $dto->lastName,
|
|
'vorname' => $dto->firstName,
|
|
'anrede' => $dto->salutation,
|
|
'titel' => $dto->title,
|
|
'geschlecht' => '',
|
|
'geburtsdatum' => '',
|
|
'anschrift' => $dto->address->toPayload(),
|
|
'kommunikation' => $communication,
|
|
],
|
|
'zahlung' => [
|
|
'@idzahlungsart' => $dto->paymentMethod->id,
|
|
'@bezeichnung' => $dto->paymentMethod->label,
|
|
'@art' => $dto->paymentMethod->type,
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function buildPreviewPayload(VoucherPurchaseDto $dto): array
|
|
{
|
|
if (null === $dto->template) {
|
|
throw new \LogicException('A voucher preview needs a template.');
|
|
}
|
|
|
|
return [
|
|
'idgutscheinvorlage' => $dto->template->id,
|
|
'kaeufer' => $dto->from,
|
|
'empfaenger' => $dto->to,
|
|
'kaufpreis' => $dto->amount,
|
|
'text' => '',
|
|
];
|
|
}
|
|
}
|