loadMissing(['guest', 'property']); $version = (int) $request->query('v'); $problem = null; if ($booking->status === BookingStatus::OfferSent) { try { $accept->ensureAcceptable($booking, $version); } catch (ReservationException $exception) { $problem = $exception->getMessage(); } } $expires = $booking->hold_expires_at?->isFuture() ? $booking->hold_expires_at : now()->addHour(); return view('offer', [ 'booking' => $booking, 'problem' => $problem, 'canAnswer' => $booking->status === BookingStatus::OfferSent && $problem === null, 'acceptUrl' => URL::temporarySignedRoute('offers.accept', $expires, ['booking' => $booking, 'v' => $version]), 'rejectUrl' => URL::temporarySignedRoute('offers.reject', $expires, ['booking' => $booking, 'v' => $version]), 'title' => 'Ihr Angebot', ]); } public function accept(Request $request, Booking $booking, AcceptOffer $accept): RedirectResponse { $request->validate(['terms' => ['accepted']], ['terms.accepted' => 'Bitte bestätigen Sie, dass Sie die Bedingungen gelesen haben.']); return $this->answer($request, $booking, fn (int $version) => $accept->handle($booking, $version), 'Vielen Dank! Ihre Buchung ist verbindlich. Die Bestätigung mit dem Mietvertrag haben wir Ihnen per E-Mail gesendet.'); } public function reject(Request $request, Booking $booking, RejectOffer $reject): RedirectResponse { return $this->answer($request, $booking, fn (int $version) => $reject->handle($booking, $version), 'Schade – wir haben Ihre Absage erhalten und den Zeitraum wieder freigegeben. Vielleicht ein anderes Mal!'); } /** * Runs the answer and returns to a freshly signed offer page with the result. */ private function answer(Request $request, Booking $booking, callable $action, string $success): RedirectResponse { $version = (int) $request->query('v'); $back = URL::temporarySignedRoute('offers.show', now()->addDays(30), ['booking' => $booking, 'v' => $version]); try { $action($version); } catch (ReservationException $exception) { return redirect()->to($back)->with('offer.error', $exception->getMessage()); } return redirect()->to($back)->with('offer.success', $success); } }