PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.15.4
GiveWP – Donation Plugin and Fundraising Platform v4.15.4
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 2.3.1 All 257 releases
give / src / PaymentGateways / Gateways / PayPalStandard / Webhooks / WebhookValidator.php

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

74 lines 2.0 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 *
19 * @param array $eventData PayPal ipn body data.
20 *
21 * @return bool
22 */
23 public function verifyEventSignature(array $eventData)
24 {
25 $eventData = array_merge( [ 'cmd' => '_notify-validate' ], $eventData );
26
27 // Validate IPN request w/ PayPal if user hasn't disabled this security measure.
28 if (! give_is_setting_enabled(give_get_option('paypal_verification', 'enabled'))) {
29 return true;
30 }
31
32 $requestArgs = [
33 'method' => 'POST',
34 'timeout' => 45,
35 'redirection' => 5,
36 'httpversion' => '1.1',
37 'blocking' => true,
38 'headers' => [
39 'host' => give_is_test_mode() ? 'www.sandbox.paypal.com' : 'www.paypal.com',
40 'connection' => 'close',
41 'content-type' => 'application/x-www-form-urlencoded',
42 'post' => '/cgi-bin/webscr HTTP/1.1',
43 ],
44 'sslverify' => false,
45 'body' => $eventData,
46 ];
47
48 $apiResponse = wp_remote_post(give_get_paypal_redirect(), $requestArgs);
49
50 if (is_wp_error($apiResponse)) {
51 Log::error(
52 'PayPal Standard IPN Error',
53 ['IPN Data' => $apiResponse]
54 );
55
56 return false;
57 }
58
59 if ('VERIFIED' !== $apiResponse['body']) {
60 Log::warning(
61 'PayPal Standard IPN Error',
62 [
63 'Message' => 'This is not a verified IPN.',
64 'IPN Data' => $apiResponse
65 ]
66 );
67
68 return false;
69 }
70
71 return true;
72 }
73 }
74