From 7ffb56c8a2a2525bb09966914c3277cbaddf45bd Mon Sep 17 00:00:00 2001 From: cmorenov1402 Date: Thu, 8 May 2025 10:39:09 +0200 Subject: [PATCH] Extract get webhook verification payload --- src/Gateway/Paypal/PaypalService.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Gateway/Paypal/PaypalService.php b/src/Gateway/Paypal/PaypalService.php index 3818f9f..b7c29e8 100644 --- a/src/Gateway/Paypal/PaypalService.php +++ b/src/Gateway/Paypal/PaypalService.php @@ -145,6 +145,19 @@ class PaypalService return \json_decode($request->getContent(), true); } + public function getWebhookVerificationPayload(mixed $headers, mixed $rawBody): string|false + { + return json_encode([ + 'auth_algo' => $headers->get('paypal-auth-algo'), + 'cert_url' => $headers->get('paypal-cert-url'), + 'transmission_id' => $headers->get('paypal-transmission-id'), + 'transmission_sig' => $headers->get('paypal-transmission-sig'), + 'transmission_time' => $headers->get('paypal-transmission-time'), + 'webhook_id' => $this->paypalWebhookId, + 'webhook_event' => json_decode($rawBody), + ]); + } + /** * Verifies a PayPal webhook request. * @@ -161,15 +174,7 @@ class PaypalService $headers = $request->headers; $rawBody = $request->getContent(); - $payload = json_encode([ - 'auth_algo' => $headers->get('paypal-auth-algo'), - 'cert_url' => $headers->get('paypal-cert-url'), - 'transmission_id' => $headers->get('paypal-transmission-id'), - 'transmission_sig' => $headers->get('paypal-transmission-sig'), - 'transmission_time' => $headers->get('paypal-transmission-time'), - 'webhook_id' => $this->paypalWebhookId, - 'webhook_event' => json_decode($rawBody), - ]); + $payload = $this->getWebhookVerificationPayload($headers, $rawBody); $response = $this->httpClient->request( 'POST',