fix: consider booking status O correctly

This commit is contained in:
Björn Fromme
2026-03-16 12:02:28 +01:00
parent f849d67a79
commit cef9be92f3
2 changed files with 31 additions and 14 deletions
+1 -1
View File
@@ -57,7 +57,7 @@ final class Constants
// Booking status codes from buchungstatusmoeglich attribute
public const BOOKING_STATUS_FREE = 'F';
public const BOOKING_STATUS_INQUIRY = 'A';
public const BOOKING_STATUS_OPEN = 'O'; // Optionsbuchung - not relevant for current implementation
public const BOOKING_STATUS_OPEN = 'O'; // Optionsbuchung
// Payment methods
public const PAYMENT_METHOD_TRANSFER = 'transfer';
+30 -13
View File
@@ -527,32 +527,49 @@ class BookingService
}
/**
* Determines the initial booking status based on travel configuration.
* Determines the initial booking status based on travel configuration and API restrictions.
*
* This method implements a multi-stage check to determine if a booking
* should start as inquiry ('A') or use the configured default status:
* 1. Checks if final bookings are allowed via buchungstatusmoeglich attribute from API
* This method implements a multi-stage check to determine the appropriate booking status:
* 1. Checks API restrictions via buchungstatusmoeglich attribute
* 2. Checks if only inquiry rooms are available (no Frei rooms with available > 0)
*
* When API provides allowed status restrictions, the method respects them by selecting
* the best available status in order of preference: configured default → 'F' → 'O' → 'A'.
*
* The default status is configured via DEFAULT_BOOKING_STATUS env variable.
* Use 'O' (Option) during beta for agency confirmation, 'F' (Final) for production.
*
* @param Travel $travelData The travel data to evaluate
*
* @return string 'A' for inquiry booking, or the configured default status
* @return string The appropriate booking status code ('F', 'O', or 'A')
*/
private function determineInitialBookingStatus(Travel $travelData): string
{
// Check 1: Allowed booking status from buchungstatusmoeglich attribute (from availability API)
// Only applies if the API provided status restrictions
if ([] !== $travelData->allowedBookingStatus
&& false === $travelData->isBookingStatusAllowed(Constants::BOOKING_STATUS_FREE)) {
return 'A';
// Check 1: Only inquiry rooms available (all rooms with available > 0 have status 'Anfrage')
// This takes precedence as it's a business rule independent of API restrictions
if ($travelData->requiresInquiryBooking()) {
return Constants::BOOKING_STATUS_INQUIRY;
}
// Check 2: Only inquiry rooms available (all rooms with available > 0 have status 'Anfrage')
if ($travelData->requiresInquiryBooking()) {
return 'A';
// Check 2: If API provided allowed status restrictions, respect them
if ([] !== $travelData->allowedBookingStatus) {
// Prefer configured default status if allowed
if ($travelData->isBookingStatusAllowed($this->defaultBookingStatus)) {
return $this->defaultBookingStatus;
}
// Fall back to allowed statuses in order of preference: F → O → A
if ($travelData->isBookingStatusAllowed(Constants::BOOKING_STATUS_FREE)) {
return Constants::BOOKING_STATUS_FREE;
}
if ($travelData->isBookingStatusAllowed(Constants::BOOKING_STATUS_OPEN)) {
return Constants::BOOKING_STATUS_OPEN;
}
if ($travelData->isBookingStatusAllowed(Constants::BOOKING_STATUS_INQUIRY)) {
return Constants::BOOKING_STATUS_INQUIRY;
}
}
return $this->defaultBookingStatus;