From 5ef8c1a51d9daf01a3d08e5286ad0539ff0a2bd8 Mon Sep 17 00:00:00 2001 From: Damilola Olowookere Date: Wed, 24 Jul 2024 10:59:20 +0100 Subject: [PATCH] Refactor PaymentNotFoundException constructor parameters --- src/Exceptions/PaymentNotFoundException.php | 8 ++++++++ src/Webhooks/Paystack/ChargeSuccess.php | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Exceptions/PaymentNotFoundException.php b/src/Exceptions/PaymentNotFoundException.php index ddb82f2..a6c547e 100644 --- a/src/Exceptions/PaymentNotFoundException.php +++ b/src/Exceptions/PaymentNotFoundException.php @@ -6,4 +6,12 @@ class PaymentNotFoundException extends Exception { + public function __construct( + public \Illuminate\Http\Request $webhookRequest, + ?string $message = null, + ) { + $message = $message ?? 'Payment not found in Paystack\'s charge.success event. Payload: ' . json_encode($webhookRequest->all()); + + parent::__construct($message); + } } diff --git a/src/Webhooks/Paystack/ChargeSuccess.php b/src/Webhooks/Paystack/ChargeSuccess.php index 976e0c5..9177929 100644 --- a/src/Webhooks/Paystack/ChargeSuccess.php +++ b/src/Webhooks/Paystack/ChargeSuccess.php @@ -30,7 +30,7 @@ public function handle(Request $webhookRequest): Payment ->first(); if (!$payment) { - throw new PaymentNotFoundException(get_class(app(PaymentHandlerInterface::class)) . ' - Payment not found in Paystack\'s charge.success event. Payload: ' . json_encode($webhookRequest->all())); + throw new PaymentNotFoundException($webhookRequest, get_class(app(PaymentHandlerInterface::class)) . ' - Payment not found in Paystack\'s charge.success event. Payload: ' . json_encode($webhookRequest->all())); } $metadata = [...$payment->metadata ?? []];