Files
LarsandCursor 8ebc1a3878 Assign the existing site to one landlord so stommer.info can run tenancy.
Seebad 0.3 stays in this release. With a single landlord every host still reaches the default website.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-23 12:00:11 +02:00

85 lines
3.4 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Http\Controllers;
use App\Actions\AcceptOffer;
use App\Actions\RejectOffer;
use App\Enums\BookingStatus;
use App\Exceptions\ReservationException;
use App\Models\Booking;
use DateTimeInterface;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\URL;
/**
* The guest's offer page (no account): reached by the signed link in the offer e-mail. Shows the complete
* offer and lets the guest accept or decline it; the form actions are signed the same way.
*/
class OfferController extends Controller
{
public function show(Request $request, Booking $booking, AcceptOffer $accept): View
{
$booking->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' => $this->signed($booking, 'offers.accept', $expires, $version),
'rejectUrl' => $this->signed($booking, 'offers.reject', $expires, $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 = $this->signed($booking, 'offers.show', now()->addDays(30), $version);
try {
$action($version);
} catch (ReservationException $exception) {
return redirect()->to($back)->with('offer.error', $exception->getMessage());
}
return redirect()->to($back)->with('offer.success', $success);
}
private function signed(Booking $booking, string $name, DateTimeInterface $expiration, int $version): string
{
$parameters = ['booking' => $booking, 'v' => $version];
return $booking->website()?->temporarySignedRoute($name, $expiration, $parameters)
?? URL::temporarySignedRoute($name, $expiration, $parameters);
}
}