Buchungsprozess: Angebots-Snapshot, atomare Annahme, Auto-Angebot, Kanalfreigabe
Deploy FeWo mit PipelineManager / deploy (push) Failing after 3m38s
Deploy FeWo mit PipelineManager / deploy (push) Failing after 3m38s
- 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>
This commit is contained in:
1 parent
e7cc37a15b
commit
eafab8a2cb
47 files changed
+2099
-104
No files matched your search
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Availability\AvailabilityChecker;
|
||||
use App\Availability\CalendarClearance;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\OfferMode;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Models\Booking;
|
||||
use App\Pricing\QuoteException;
|
||||
use App\Support\Content;
|
||||
use App\Support\Settings;
|
||||
|
||||
/**
|
||||
* Automatic offer processing (property setting "Automatisch"): sends the offer without the landlord when every
|
||||
* release rule is met, otherwise leaves the request untouched for manual processing and says why.
|
||||
*
|
||||
* Rules: pre-reservation active (the dates are really blocked), guest e-mail known, dates still free, contract
|
||||
* texts released by the landlord (not the sample text; skipped while mails only go to the test recipient),
|
||||
* and the calendar clearance of {@see CalendarClearance} (fresh imports, instant-booking portals fetched our feed).
|
||||
*/
|
||||
class AutoOffer
|
||||
{
|
||||
public function __construct(
|
||||
private SendOffer $sendOffer,
|
||||
private CalendarClearance $clearance,
|
||||
private AvailabilityChecker $availability,
|
||||
) {}
|
||||
|
||||
public function applies(Booking $booking): bool
|
||||
{
|
||||
return $booking->property->offer_mode === OfferMode::Automatic;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string> reasons why the offer cannot be sent automatically (empty = may be sent)
|
||||
*/
|
||||
public function blockers(Booking $booking): array
|
||||
{
|
||||
$property = $booking->property;
|
||||
$reasons = [];
|
||||
|
||||
if (! $property->pre_reservation_enabled) {
|
||||
$reasons[] = 'Die Vorreservierung ist für diese Wohnung ausgeschaltet; ohne Sperre im Kalender wird kein Angebot automatisch erteilt.';
|
||||
}
|
||||
if ($booking->status !== BookingStatus::Reserved || ! $booking->isHoldActive()) {
|
||||
$reasons[] = 'Die Anfrage ist nicht mehr vorgemerkt (Frist abgelaufen oder bereits bearbeitet).';
|
||||
}
|
||||
if (blank($booking->guest?->email)) {
|
||||
$reasons[] = 'Die E-Mail-Adresse des Gastes fehlt.';
|
||||
}
|
||||
if (! $this->availability->isAvailable($property, $booking->arrival, $booking->departure, ignore: $booking)) {
|
||||
$reasons[] = 'Der Zeitraum ist inzwischen belegt.';
|
||||
}
|
||||
if (! $this->contractTextsReleased()) {
|
||||
$reasons[] = 'Mietbedingungen, Stornobedingungen oder Bankverbindung sind noch nicht vom Betreiber freigegeben (leer oder Mustertext).';
|
||||
}
|
||||
|
||||
return [...$reasons, ...$this->clearance->reasons($property, $booking->created_at)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to send the offer. Imports of stale channels are refreshed first (network access, outside transactions).
|
||||
*
|
||||
* @return list<string> reasons for the manual fallback; empty when the offer was sent
|
||||
*/
|
||||
public function handle(Booking $booking): array
|
||||
{
|
||||
$booking->loadMissing(['property', 'guest']);
|
||||
|
||||
if ($booking->property->pre_reservation_enabled) {
|
||||
$this->clearance->refresh($booking->property);
|
||||
}
|
||||
|
||||
$reasons = $this->blockers($booking);
|
||||
if ($reasons !== []) {
|
||||
return $reasons;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->sendOffer->handle($booking->fresh());
|
||||
} catch (QuoteException|ReservationException $exception) {
|
||||
// A mail failure keeps the saved offer (SendOffer reports it in the inbox); the landlord can resend the link.
|
||||
return [$exception->getMessage()];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
private function contractTextsReleased(): bool
|
||||
{
|
||||
if (! Settings::isLive()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$terms = (string) Content::get('contract.terms');
|
||||
|
||||
return filled($terms) && ! str_contains($terms, '[MUSTER')
|
||||
&& filled(Content::get('stay.cancellation'))
|
||||
&& filled(config('fewo.bank.iban'));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user