fix: refuse implausible accommodation booking prices
This commit is contained in:
1 parent
773cd4f847
commit
56adf72d12
16 files changed
+628
-15
No files matched your search
@@ -8,6 +8,7 @@ use App\Entity\Groups\Accommodation;
|
||||
use App\Entity\Groups\AdditionalService;
|
||||
use App\Entity\Groups\BoardService;
|
||||
use App\Exception\AccommodationSessionNotFoundException;
|
||||
use App\Exception\ImplausibleBookingPriceException;
|
||||
use App\Form\AccommodationBookingConfirmationType;
|
||||
use App\Form\AccommodationInquiryConfirmationType;
|
||||
use App\Form\Model\AccommodationBookingDto;
|
||||
@@ -16,6 +17,7 @@ use App\Model\AccommodationBookingContext;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use App\Service\AccommodationSessionManager;
|
||||
use App\Service\AccommodationTermsUrlProvider;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
@@ -28,6 +30,7 @@ class Step4Controller extends AbstractController
|
||||
private readonly AccommodationBookingService $bookingService,
|
||||
private readonly AccommodationSessionManager $sessionManager,
|
||||
private readonly AccommodationTermsUrlProvider $termsUrlProvider,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -51,7 +54,9 @@ class Step4Controller extends AbstractController
|
||||
}
|
||||
|
||||
$dto->forceInquiry = true;
|
||||
$this->persistBooking($request, $dto, $accommodation, $services);
|
||||
if (null !== $failure = $this->persistBooking($request, $dto, $accommodation, $services)) {
|
||||
return $failure;
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('app_groups_booking_success');
|
||||
}
|
||||
@@ -102,7 +107,9 @@ class Step4Controller extends AbstractController
|
||||
|
||||
if ($confirmationForm->isSubmitted() && $confirmationForm->isValid()) {
|
||||
$services = $this->bookingService->loadAvailableServices($dto, $accommodation);
|
||||
$this->persistBooking($request, $dto, $accommodation, $services);
|
||||
if (null !== $failure = $this->persistBooking($request, $dto, $accommodation, $services)) {
|
||||
return $failure;
|
||||
}
|
||||
|
||||
return $this->htmxRedirect($request, $this->generateUrl('app_groups_booking_success'));
|
||||
}
|
||||
@@ -148,12 +155,35 @@ class Step4Controller extends AbstractController
|
||||
* groupedAdditionalServices: array<string, AdditionalService[]>,
|
||||
* ungroupedAdditionalServices: AdditionalService[]
|
||||
* } $services
|
||||
*
|
||||
* @return Response|null a response to return instead of the success redirect, or null when
|
||||
* the booking was stored
|
||||
*/
|
||||
private function persistBooking(Request $request, AccommodationBookingDto $dto, Accommodation $accommodation, array $services): void
|
||||
private function persistBooking(Request $request, AccommodationBookingDto $dto, Accommodation $accommodation, array $services): ?Response
|
||||
{
|
||||
$prices = $this->bookingService->loadPrices($dto, $accommodation);
|
||||
$booking = $this->bookingService->finalizeBooking($dto, $accommodation, $prices, $services);
|
||||
|
||||
try {
|
||||
$booking = $this->bookingService->finalizeBooking($dto, $accommodation, $prices, $services);
|
||||
} catch (ImplausibleBookingPriceException $e) {
|
||||
// The bounded inputs are already rejected in step 2, so what is left is a mistyped
|
||||
// catalog price for this house — nothing the customer can act on and nothing to show
|
||||
// them an error page over. The session survives so the desk can pick the inquiry up
|
||||
// by phone with the data still in hand.
|
||||
$this->logger->error('Refused to store an implausible accommodation booking total', [
|
||||
'exception' => $e,
|
||||
'accommodation' => $accommodation->getCalendarCode(),
|
||||
'paxCount' => $dto->paxCount,
|
||||
'nights' => $dto->getNights(),
|
||||
]);
|
||||
$this->addFlash('error', 'Die Anfrage konnte nicht abgeschlossen werden. Bitte wende dich direkt an uns — wir kümmern uns darum.');
|
||||
|
||||
return $this->htmxRedirect($request, $this->generateUrl('app_groups_booking_error'));
|
||||
}
|
||||
|
||||
$this->addFlash('groups_booking_result', $booking->getOrigin()->value);
|
||||
$this->sessionManager->clear($request);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user