feat: voucher purchase flow
This commit is contained in:
1 parent
a628e96d06
commit
f3dd122678
70 files changed
+3672
-122
No files matched your search
@@ -0,0 +1,80 @@
|
||||
<?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' => '',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user