feat: improved promotional and purchase vouchers

This commit is contained in:
Björn Fromme
2026-03-16 11:59:11 +01:00
parent 7df99521c4
commit fb983f23dd
15 changed files with 357 additions and 137 deletions
@@ -688,9 +688,11 @@ class BookingDataProcessor
}
}
// Add promo voucher if present
if (null !== $dto->promoVoucherCode && '' !== trim($dto->promoVoucherCode)) {
$participantPayload['aktionscode'] = trim($dto->promoVoucherCode);
// Add promo voucher or goodwill voucher as aktionscode
// Goodwill vouchers (Kulanz) take precedence over promo vouchers
$aktionscode = $this->getPromoVoucherCodeForParticipant($dto);
if (null !== $aktionscode) {
$participantPayload['aktionscode'] = $aktionscode;
}
}
@@ -883,9 +885,11 @@ class BookingDataProcessor
}
}
// Add promo voucher if present
if (null !== $participant->promoVoucherCode && '' !== trim($participant->promoVoucherCode)) {
$participantData['aktionscode'] = trim($participant->promoVoucherCode);
// Add promo voucher or goodwill voucher as aktionscode
// Goodwill vouchers (Kulanz) take precedence over promo vouchers
$aktionscode = $this->getPromoVoucherCodeForParticipant($participant);
if (null !== $aktionscode) {
$participantData['aktionscode'] = $aktionscode;
}
$payload['teilnehmerliste']['teilnehmer'][] = $participantData;
@@ -1169,7 +1173,10 @@ class BookingDataProcessor
* 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
* IMPORTANT: Goodwill vouchers (Kulanz) are excluded from this collection.
* They are added per participant as <aktionscode> instead.
*
* @return string[] Array of unique redemption codes (excluding Kulanz)
*/
private function collectPurchaseVouchers(BookingDto $bookingDto): array
{
@@ -1177,7 +1184,10 @@ class BookingDataProcessor
foreach ($bookingDto->participants as $participant) {
if (null !== $participant->purchaseVoucherCode && '' !== trim($participant->purchaseVoucherCode)) {
$vouchers[] = trim($participant->purchaseVoucherCode);
// Exclude goodwill vouchers (flagged by field handler)
if (false === $participant->hasGoodwillVoucher) {
$vouchers[] = trim($participant->purchaseVoucherCode);
}
}
}
@@ -1185,6 +1195,30 @@ class BookingDataProcessor
return array_unique($vouchers);
}
/**
* Gets the aktionscode for a participant.
*
* Checks if the participant has a goodwill (Kulanz) purchase voucher first.
* If yes, returns that code (goodwill vouchers override promo vouchers).
* Otherwise, returns the promo voucher code if present.
*
* @return string|null The aktionscode to use, or null if none
*/
private function getPromoVoucherCodeForParticipant(ParticipantDto $participant): ?string
{
// Check for goodwill voucher first (takes precedence)
if (true === $participant->hasGoodwillVoucher && null !== $participant->purchaseVoucherCode && '' !== trim($participant->purchaseVoucherCode)) {
return trim($participant->purchaseVoucherCode);
}
// Fall back to promo voucher if present
if (null !== $participant->promoVoucherCode && '' !== trim($participant->promoVoucherCode)) {
return trim($participant->promoVoucherCode);
}
return null;
}
/**
* Applies bulk insurance assignment if the applicant has enabled it.
*