getKey())->lockForUpdate()->first(); if (! $this->availability->isAvailable($property, $stay->arrival, $stay->departure)) { throw ReservationException::notAvailable(); } $quote = $this->calculator->calculate($property, $stay); $guest = Guest::firstOrNew(['email' => mb_strtolower($guestData['email'])]); $guest->fill($guestData)->fill(['email' => mb_strtolower($guestData['email'])])->save(); return $property->bookings()->create([ 'guest_id' => $guest->id, 'status' => BookingStatus::Reserved, 'source' => $source, 'arrival' => $stay->arrival->toDateString(), 'departure' => $stay->departure->toDateString(), 'guests' => $stay->guests, 'extras' => array_filter($stay->extras), 'promo_code' => $quote->promoCodeApplied ? $stay->promoCode : null, 'quote' => $quote->toArray(), 'total' => $quote->total(), 'deposit' => $quote->deposit(), 'balance_due_on' => $quote->balanceDueOn->toDateString(), 'hold_expires_at' => now()->addHours($property->hold_hours), 'message' => $message, ]); }); if ($sendMails) { $this->sendMails($booking); } return $booking; } /** * A failing mail server must not lose the reservation; failures are reported and visible in the log. */ private function sendMails(Booking $booking): void { try { Mail::to($booking->guest->email, $booking->guest->full_name)->send(new ReservationReceived($booking)); Mail::to(config('fewo.notification_email'))->send(new NewReservation($booking)); } catch (Throwable $exception) { report($exception); } } }