From efacbf64cb37e98879d8ce1db319cd980f40b58e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Tue, 13 Jan 2026 14:42:51 +0100 Subject: [PATCH] fix: consider booking status O correctly --- src/BusProNet/Constants.php | 2 +- src/Service/BookingService.php | 43 ++++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/BusProNet/Constants.php b/src/BusProNet/Constants.php index 0614052..c106e98 100644 --- a/src/BusProNet/Constants.php +++ b/src/BusProNet/Constants.php @@ -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'; diff --git a/src/Service/BookingService.php b/src/Service/BookingService.php index c9933e4..9f4748e 100644 --- a/src/Service/BookingService.php +++ b/src/Service/BookingService.php @@ -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;