28 lines
731 B
PHP
28 lines
731 B
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."
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function render(Request $request): ?JsonResponse
|
||
|
|
{
|
||
|
|
if ($request->expectsJson()) {
|
||
|
|
return response()->json(['message' => $this->getMessage()], 422);
|
||
|
|
}
|
||
|
|
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|