44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Actions;
|
|
|
|
use App\Enums\BookingStatus;
|
|
use App\Exceptions\ReservationException;
|
|
use App\Mail\OfferAnswered;
|
|
use App\Models\Booking;
|
|
use App\Support\Settings;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Throwable;
|
|
|
|
/**
|
|
* The guest declines the offer on the offer page: the dates are released and the landlord is informed.
|
|
*/
|
|
class RejectOffer
|
|
{
|
|
/**
|
|
* @throws ReservationException
|
|
*/
|
|
public function handle(Booking $booking, int $offerVersion): void
|
|
{
|
|
if ($offerVersion !== $booking->offer_version) {
|
|
throw ReservationException::offerOutdated();
|
|
}
|
|
|
|
if ($booking->status !== BookingStatus::OfferSent) {
|
|
throw ReservationException::invalidTransition($booking->status->getLabel(), 'abgelehnt');
|
|
}
|
|
|
|
$booking->update([
|
|
'status' => BookingStatus::Declined,
|
|
'declined_by' => 'guest',
|
|
'hold_expires_at' => null,
|
|
]);
|
|
|
|
try {
|
|
Mail::to(Settings::notificationRecipients())->send(new OfferAnswered($booking, accepted: false));
|
|
} catch (Throwable $exception) {
|
|
report($exception);
|
|
}
|
|
}
|
|
}
|