feat: promotional and purchase vouchers

This commit is contained in:
Björn Fromme
2025-11-20 18:41:46 +01:00
parent 26681e5c62
commit aaa7e9f4c3
21 changed files with 847 additions and 6 deletions
@@ -274,6 +274,17 @@ class BookingDataProcessor
$this->buildServicesPayload($payload, $bookingData);
$this->buildPickupPayload($payload, $bookingData);
// Add purchase vouchers if any exist
$purchaseVouchers = $this->collectPurchaseVouchers($formData);
if (false === empty($purchaseVouchers)) {
$payload['gutscheine']['gutschein'] = [];
foreach ($purchaseVouchers as $code) {
$payload['gutscheine']['gutschein'][] = [
'@einloesecode' => $code,
];
}
}
return $payload;
}
@@ -676,6 +687,11 @@ class BookingDataProcessor
$participantPayload['wünsche'] = $wishes;
}
}
// Add promo voucher if present
if (null !== $dto->promoVoucherCode && '' !== trim($dto->promoVoucherCode)) {
$participantPayload['aktionscode'] = trim($dto->promoVoucherCode);
}
}
$payload['teilnehmerliste']['teilnehmer'][] = $participantPayload;
@@ -867,6 +883,11 @@ class BookingDataProcessor
}
}
// Add promo voucher if present
if (null !== $participant->promoVoucherCode && '' !== trim($participant->promoVoucherCode)) {
$participantData['aktionscode'] = trim($participant->promoVoucherCode);
}
$payload['teilnehmerliste']['teilnehmer'][] = $participantData;
}
@@ -884,6 +905,17 @@ class BookingDataProcessor
$this->addServicesFromMap($payload, 'zustiege', 'zustieg', '@idzustieg', $pickupMap);
$this->addServicesFromMap($payload, 'versicherungen', 'versicherung', '@idversicherung', $insuranceMap);
// Add purchase vouchers if any exist
$purchaseVouchers = $this->collectPurchaseVouchers($bookingDto);
if (false === empty($purchaseVouchers)) {
$payload['gutscheine']['gutschein'] = [];
foreach ($purchaseVouchers as $code) {
$payload['gutscheine']['gutschein'][] = [
'@einloesecode' => $code,
];
}
}
// Add payment information
$payload['zahlung'] = [
'@idzahlungsart' => Constants::PAYMENT_METHOD_DEBIT === $bookingDto->paymentMethod
@@ -1131,6 +1163,28 @@ class BookingDataProcessor
return $insuranceMap;
}
/**
* Collects all purchase vouchers from participants.
*
* Removes duplicates and empty values, returning unique redemption codes
* for aggregation into the <gutscheine> collection in the booking payload.
*
* @return string[] Array of unique redemption codes
*/
private function collectPurchaseVouchers(BookingDto $bookingDto): array
{
$vouchers = [];
foreach ($bookingDto->participants as $participant) {
if (null !== $participant->purchaseVoucherCode && '' !== trim($participant->purchaseVoucherCode)) {
$vouchers[] = trim($participant->purchaseVoucherCode);
}
}
// Remove duplicates (in case multiple participants enter same code)
return array_unique($vouchers);
}
/**
* Applies bulk insurance assignment if the applicant has enabled it.
*