feat: improved promotional and purchase vouchers
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -16,6 +16,9 @@ namespace App\BusProNet\Model;
|
||||
*/
|
||||
final readonly class PurchaseVoucher
|
||||
{
|
||||
public const TYPE_PURCHASE = 'Kauf';
|
||||
public const TYPE_GOODWILL = 'Kulanz';
|
||||
|
||||
public function __construct(
|
||||
public string $voucherNumber,
|
||||
public string $redemptionCode,
|
||||
@@ -24,4 +27,25 @@ final readonly class PurchaseVoucher
|
||||
public string $type,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this voucher is a purchase voucher.
|
||||
*
|
||||
* Purchase vouchers (Kauf) are aggregated into <gutscheine>.
|
||||
*/
|
||||
public function isPurchase(): bool
|
||||
{
|
||||
return self::TYPE_PURCHASE === $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this voucher is a goodwill voucher.
|
||||
*
|
||||
* Goodwill vouchers (Kulanz) must be treated as promo vouchers and added
|
||||
* per participant as <aktionscode>, not aggregated into <gutscheine>.
|
||||
*/
|
||||
public function isGoodwill(): bool
|
||||
{
|
||||
return self::TYPE_GOODWILL === $this->type;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user