PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.18.0.1
GiveWP – Donation Plugin and Fundraising Platform v4.18.0.1
4.18.0.1 4.18.0 4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 All 258 releases
give / src / PaymentGateways / Gateways / PayPalStandard / Webhooks / WebhookValidator.php

WebhookValidator.php in GiveWP – Donation Plugin and Fundraising Platform 4.18.0.1, at src/PaymentGateways/Gateways/PayPalStandard/Webhooks/WebhookValidator.php

69 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\PaymentGateways\Gateways\PayPalStandard\Webhooks;
4
5 use Give\Log\Log;
6
7 /**
8 * This class use to validate PayPal Standard ipn.
9 * Validate the IPN: https://developer.paypal.com/docs/api-basics/notifications/ipn/IPNImplementation/
10 *
11 * @since 2.19.0
12 */
13 class WebhookValidator
14 {
15 /**
16 * @since 2.19.0
17 * @since 2.19.3 Update log message.
18 * @since 4.18.0.1 Always validate the IPN with PayPal and verify its SSL certificate.
19 *
20 * @param array $eventData PayPal ipn body data.
21 *
22 * @return bool
23 */
24 public function verifyEventSignature(array $eventData)
25 {
26 $eventData = array_merge( [ 'cmd' => '_notify-validate' ], $eventData );
27
28 $requestArgs = [
29 'method' => 'POST',
30 'timeout' => 45,
31 'redirection' => 5,
32 'httpversion' => '1.1',
33 'blocking' => true,
34 'headers' => [
35 'host' => give_is_test_mode() ? 'www.sandbox.paypal.com' : 'www.paypal.com',
36 'connection' => 'close',
37 'content-type' => 'application/x-www-form-urlencoded',
38 'post' => '/cgi-bin/webscr HTTP/1.1',
39 ],
40 'body' => $eventData,
41 ];
42
43 $apiResponse = wp_remote_post(give_get_paypal_redirect(), $requestArgs);
44
45 if (is_wp_error($apiResponse)) {
46 Log::error(
47 'PayPal Standard IPN Error',
48 ['IPN Data' => $apiResponse]
49 );
50
51 return false;
52 }
53
54 if ('VERIFIED' !== $apiResponse['body']) {
55 Log::warning(
56 'PayPal Standard IPN Error',
57 [
58 'Message' => 'This is not a verified IPN.',
59 'IPN Data' => $apiResponse
60 ]
61 );
62
63 return false;
64 }
65
66 return true;
67 }
68 }
69