Fix signature verification body format

This commit is contained in:
cmorenov1402
2025-05-08 10:25:23 +02:00
parent f719a676a9
commit 51c504d434
+17 -12
View File
@@ -148,6 +148,8 @@ class PaypalService
/**
* Verifies a PayPal webhook request.
*
* @see https://developer.paypal.com/community/blog/paypal-has-updated-its-webhook-verification-endpoint/
*
* @param Request $request The webhook request
*
* @return array The webhook event data
@@ -157,31 +159,34 @@ class PaypalService
public function verifyWebhook(Request $request): array
{
$headers = $request->headers;
$webhookData = \json_decode($request->getContent(), true);
$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),
]);
$response = $this->httpClient->request(
'POST',
'/v1/notifications/verify-webhook-signature',
[
'auth_bearer' => $this->getAuthToken()['access_token'],
'json' => [
'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' => $webhookData,
],
'headers' => ['Content-Type' => 'application/json'],
'body' => $payload,
]
);
$data = $response->toArray();
$data = $response->toArray(false);
if (($data['verification_status'] ?? '') !== 'SUCCESS') {
throw new \Exception('Could not verify PayPal webhook signature.');
}
return $webhookData;
return json_decode($rawBody, true);
}
}