Files
famous-ly4-ev/app-modules/payment/src/Exceptions/PaymentInitiationNotAllowedException.php
T
Nyan Lin Paing fa908cdcaf
PHP Tests / php-tests (push) Has been cancelled
add notes/remark and refactor round-trip
2026-08-22 21:43:41 +07:00

40 lines
1.2 KiB
PHP

<?php
namespace Modules\Payment\Exceptions;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Modules\Booking\Models\Booking;
use RuntimeException;
class PaymentInitiationNotAllowedException extends RuntimeException
{
public static function notPendingPayment(Booking $booking): self
{
return new self(
"Booking [{$booking->booking_ref}] cannot have a payment initiated because its status is [{$booking->status->value}], not pending_payment."
);
}
/**
* A round trip's payment is combined on the outbound leg — the return
* leg is marked paid when the outbound leg's payment succeeds
* (MarkBookingPaid), never via its own Payment (domain.md §2b).
*/
public static function isReturnLeg(Booking $booking): self
{
return new self(
"Booking [{$booking->booking_ref}] is a round trip's return leg — initiate payment on its linked outbound booking instead."
);
}
public function render(Request $request): ?JsonResponse
{
if ($request->expectsJson()) {
return response()->json(['message' => $this->getMessage()], 422);
}
return null;
}
}