Files
fewo-stommer/app/Http/Controllers/OfferController.php
T
LarsandClaude Sonnet 5.5 eafab8a2cb
Deploy FeWo mit PipelineManager / deploy (push) Failing after 3m38s
Buchungsprozess: Angebots-Snapshot, atomare Annahme, Auto-Angebot, Kanalfreigabe
- Angebotsbedingungen und Zahlungsdaten werden je Version eingefroren (offer_terms, offer_hash)
- Annahme in einer gesperrten Transaktion, idempotent, mit Nachweis; Mail- und Portalfehler
  machen eine gespeicherte Buchung nicht ungueltig (Postfach, Nachversand)
- Je Wohnung: manuelle/automatische Angebote, optionale Vorreservierung
- Automatische Freigabe abhaengig von aktuellen Importen und Feed-Abruf bei Sofortbuchungsportalen
- Deutsche Fehlerseiten, Buchungsseite zeigt Angebots- und Zustellstatus
- Dokumentation: BOOKING-E2E-*.md, BOOKING-COMPLIANCE-HANDOVER.md

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 12:01:02 +01:00

102 lines
4.0 KiB
PHP
Raw 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, function (int $version) use ($accept, $booking): string {
$concluded = $accept->handle($booking, $version);
$booking->refresh();
if (! $concluded) {
return 'Ihre Buchung ist bereits verbindlich bestätigt – Sie müssen nichts weiter tun.';
}
return $booking->confirmation_sent_at !== null
? 'Vielen Dank! Ihre Buchung ist verbindlich. Die Bestätigung mit dem Mietvertrag haben wir Ihnen per E-Mail gesendet.'
: 'Vielen Dank! Ihre Buchung ist verbindlich. Die Bestätigung mit dem Mietvertrag erhalten Sie in Kürze per E-Mail; kommt sie nicht an, melden wir uns bei Ihnen.';
});
}
public function reject(Request $request, Booking $booking, RejectOffer $reject): RedirectResponse
{
return $this->answer($request, $booking, function (int $version) use ($reject, $booking): string {
$reject->handle($booking, $version);
return 'Schade – wir haben Ihre Absage erhalten und den Zeitraum wieder freigegeben. Vielleicht ein anderes Mal!';
});
}
/**
* Runs the answer (it returns the success message) and returns to a freshly signed offer page with the result.
*
* @param callable(int): string $action
*/
private function answer(Request $request, Booking $booking, callable $action): RedirectResponse
{
$version = (int) $request->query('v');
$back = $this->signed($booking, 'offers.show', now()->addDays(30), $version);
try {
$success = $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);
}
}