feat: correct determination of inquiry status and conditional voucher field display
This commit is contained in:
@@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace App\Controller\Booking\Create;
|
||||
|
||||
use App\BusProNet\XmlLoader\AgencyLoader;
|
||||
use App\Exception\BookingNotPossibleException;
|
||||
use App\Exception\HotelNotFoundException;
|
||||
use App\Exception\HotelNotInTravelException;
|
||||
use App\Exception\NoRoomsAvailableException;
|
||||
@@ -70,8 +69,6 @@ class IndexController extends AbstractController
|
||||
throw $this->createNotFoundException(sprintf('Hotel ID %d is not available for travel ID %d', $hotelId, $dateId));
|
||||
} catch (NoRoomsAvailableException) {
|
||||
throw $this->createNotFoundException('No rooms available for this travel.');
|
||||
} catch (BookingNotPossibleException) {
|
||||
throw $this->createNotFoundException('Booking is not possible for this travel (Buchungsstop).');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,9 @@ class Step1Controller extends AbstractController
|
||||
$this->bookingService->resetParticipantAssignments($bookingCreateDto);
|
||||
}
|
||||
|
||||
// Check if room selection forces inquiry mode
|
||||
$this->bookingService->updateBookingStatusFromRoomSelection($bookingCreateDto);
|
||||
|
||||
$bookingCreateDto->currentStep = 2;
|
||||
$this->bookingService->saveBookingCreateDto($request, $bookingCreateDto);
|
||||
|
||||
|
||||
@@ -88,6 +88,24 @@ class Step3Controller extends AbstractController
|
||||
}
|
||||
|
||||
if (false === $inquiryResponse->isInquiryValid()) {
|
||||
// Check if API suggests inquiry booking instead of showing error
|
||||
if ($this->shouldFallbackToInquiryMode($inquiryResponse)) {
|
||||
// Auto-switch to inquiry mode
|
||||
$bookingCreateDto->bookingStatus = 'A';
|
||||
$bookingCreateDto->currentStep = 4;
|
||||
$this->bookingService->saveBookingCreateDto($request, $bookingCreateDto);
|
||||
|
||||
$message = 'Buchung konnte nicht validiert werden.';
|
||||
if (null !== $inquiryResponse->message && '' !== trim($inquiryResponse->message)) {
|
||||
$message = $inquiryResponse->message;
|
||||
}
|
||||
|
||||
$this->addFlash('info', $message);
|
||||
|
||||
return $this->hxRedirect($request, $this->generateUrl('app_booking_create_step_4'));
|
||||
}
|
||||
|
||||
// Not a fallback scenario - show validation error
|
||||
$errorMessage = 'Buchung konnte nicht validiert werden.';
|
||||
if (null !== $inquiryResponse->message && '' !== trim($inquiryResponse->message)) {
|
||||
$errorMessage .= ' '.$inquiryResponse->message;
|
||||
@@ -199,4 +217,31 @@ class Step3Controller extends AbstractController
|
||||
'groupedSelectedRooms' => $groupedSelectedRooms,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if validation failure should trigger inquiry mode fallback.
|
||||
*
|
||||
* Checks if the API response indicates that the booking should proceed as
|
||||
* an inquiry rather than showing an error. This handles scenarios where
|
||||
* availability changes between booking initialization and validation.
|
||||
*
|
||||
* @param \App\BusProNet\Model\BookingResponse $response The API response
|
||||
*
|
||||
* @return bool True if should fallback to inquiry mode, false if should show error
|
||||
*/
|
||||
private function shouldFallbackToInquiryMode(\App\BusProNet\Model\BookingResponse $response): bool
|
||||
{
|
||||
// Check for "nicht möglich" status + inquiry suggestion in message
|
||||
if ('nicht möglich' !== $response->status) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$message = $response->message ?? '';
|
||||
if ('' === $message) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if message suggests inquiry booking (case-insensitive)
|
||||
return 1 === preg_match('/anfrage/i', $message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
|
||||
/**
|
||||
* Handles the fourth step of the booking creation process (confirmation).
|
||||
@@ -36,6 +37,7 @@ class Step4Controller extends AbstractController
|
||||
private readonly BookingSummaryDataService $summaryDataService,
|
||||
private readonly BookingPriceCalculatorService $priceCalculator,
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly CacheInterface $cache,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
@@ -99,6 +101,7 @@ class Step4Controller extends AbstractController
|
||||
|
||||
// Success: Store booking number in flash and clear session
|
||||
$this->addFlash('booking_number', $bookingResponse->transactionNumber);
|
||||
$this->clearTravelDataCache($bookingCreateDto);
|
||||
$this->bookingService->clearBookingCreateDto($request);
|
||||
|
||||
return $this->hxRedirect($request, $this->generateUrl('app_booking_create_success'));
|
||||
@@ -151,4 +154,25 @@ class Step4Controller extends AbstractController
|
||||
'participantPrices' => $this->priceCalculator->calculateAllParticipantIndividualPrices($bookingCreateDto),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears travel data and availability cache after successful booking.
|
||||
*/
|
||||
private function clearTravelDataCache(BookingDto $bookingDto): void
|
||||
{
|
||||
$dateId = $bookingDto->travel->id;
|
||||
$hotelId = $bookingDto->hotelId;
|
||||
|
||||
// Clear availability cache
|
||||
$this->cache->delete(sprintf('availability_%d', $dateId));
|
||||
|
||||
// Clear travel data cache (both local and remote variants)
|
||||
$this->cache->delete(sprintf('travel_unified_%d_%d_local', $dateId, $hotelId));
|
||||
$this->cache->delete(sprintf('travel_unified_%d_%d_remote', $dateId, $hotelId));
|
||||
|
||||
$this->logger->info('Cleared travel data cache after successful booking', [
|
||||
'dateId' => $dateId,
|
||||
'hotelId' => $hotelId,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user