möglich = inquiry validation successful * - erfolgt = booking creation successful * * Error responses return Notification objects instead (typ="HINWEIS"). */ class BookingResponse { /** * @param string $status Booking status (möglich|erfolgt) * @param string|null $transactionNumber Transaction number (vorgang) * @param array $priceItems Individual price items from response * @param float|null $totalPrice Total price (gesamtpreis) * @param PaymentTerms|null $paymentTerms Payment terms (anzahlung/restzahlung) */ public function __construct( public readonly string $status, public readonly ?string $transactionNumber = null, public readonly array $priceItems = [], public readonly ?float $totalPrice = null, public readonly ?PaymentTerms $paymentTerms = null, public readonly ?string $message = null, ) { } /** * Returns true if the inquiry validation was successful. */ public function isInquiryValid(): bool { return 'möglich' === $this->status; } /** * Returns true if the booking was successfully created. */ public function isBookingSuccessful(): bool { return 'erfolgt' === $this->status; } /** * Gets voucher discounts from price items (AKTION and KULANZGUTSCHEIN types). * * Promotional vouchers appear as negative price items with art="AKTION". * Goodwill vouchers appear as negative price items with art="KULANZGUTSCHEIN". * * @return array Price items representing voucher discounts */ public function getVoucherDiscountsFromPrices(): array { return array_filter( $this->priceItems, fn (PriceItem $item) => \in_array($item->type, ['AKTION', 'KULANZGUTSCHEIN'], true) ); } /** * Gets total discount from price-based vouchers (promotional and goodwill). * * Returns the absolute sum of negative price items with AKTION or KULANZGUTSCHEIN types. */ public function getVoucherDiscountFromPrices(): float { $discount = 0.0; foreach ($this->getVoucherDiscountsFromPrices() as $item) { // Price items for vouchers are negative, so we take absolute value $discount += abs($item->totalPrice); } return round($discount, 2); } /** * Gets total discount from purchase vouchers in payment terms. */ public function getPurchaseVoucherDiscount(): float { return $this->paymentTerms?->getPurchaseVoucherDiscount() ?? 0.0; } /** * Gets total voucher discount from all sources. * * Combines discounts from: * - Price items (art="AKTION" for promotional, art="KULANZGUTSCHEIN" for goodwill) * - Payment terms (kaufgutschein elements for purchase vouchers) */ public function getTotalVoucherDiscount(): float { return round( $this->getVoucherDiscountFromPrices() + $this->getPurchaseVoucherDiscount(), 2 ); } }