property->offer_mode === OfferMode::Automatic; } /** * @return list 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 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')); } }