28 lines
825 B
PHP
28 lines
825 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Modules\Booking\Actions;
|
||
|
|
|
||
|
|
use Modules\Booking\Enums\BookingStatus;
|
||
|
|
use Modules\Booking\Exceptions\BookingCannotBeCancelledException;
|
||
|
|
use Modules\Booking\Models\Booking;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Unpaid path only — a pending_payment booking has no money moved yet, so
|
||
|
|
* it can be cancelled directly. A confirmed (paid) booking must go through
|
||
|
|
* a refund first; this action explicitly guards against bypassing that
|
||
|
|
* (domain.md §5). Wired into that refund path in T5.12.
|
||
|
|
*/
|
||
|
|
class CancelBookingAction
|
||
|
|
{
|
||
|
|
public function handle(Booking $booking): Booking
|
||
|
|
{
|
||
|
|
if ($booking->status !== BookingStatus::PendingPayment) {
|
||
|
|
throw BookingCannotBeCancelledException::notPendingPayment($booking);
|
||
|
|
}
|
||
|
|
|
||
|
|
$booking->update(['status' => BookingStatus::Cancelled]);
|
||
|
|
|
||
|
|
return $booking;
|
||
|
|
}
|
||
|
|
}
|