From 7ea7ef316df444923748c9d5375ae748cf9b7991 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Thu, 28 Jul 2022 14:42:22 -0600 Subject: [PATCH 1/2] PaypalIPN.php - Added missing "User-Agent" string + Added a "PHP-IPN-Verification-Script" User-Agent string to fix issues with Sandbox system --- src/PaypalIPN.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/PaypalIPN.php b/src/PaypalIPN.php index 7f510ed..836e155 100644 --- a/src/PaypalIPN.php +++ b/src/PaypalIPN.php @@ -112,7 +112,10 @@ function verifyIPN() } curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); - curl_setopt($ch, CURLOPT_HTTPHEADER, ['Connection: Close']); + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'User-Agent: PHP-IPN-Verification-Script', + 'Connection: Close', + )); $res = curl_exec($ch); $info = curl_getinfo($ch); $http_code = $info['http_code']; From 2c750f2fb981b2e51bcb0129a7e4dfc4867f6c1f Mon Sep 17 00:00:00 2001 From: Benjamin Blake Date: Mon, 7 Apr 2025 20:32:04 -0600 Subject: [PATCH 2/2] Updated to work with php version 8.3 --- .phpcs.xml | 19 +++++++++++++++++++ src/PaypalIPN.php | 20 ++++---------------- 2 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 .phpcs.xml diff --git a/.phpcs.xml b/.phpcs.xml new file mode 100644 index 0000000..31610f6 --- /dev/null +++ b/.phpcs.xml @@ -0,0 +1,19 @@ + + + CodeSniffer ruleset for SilverStripe coding conventions. + + src + + + + + + + + + + + + + + diff --git a/src/PaypalIPN.php b/src/PaypalIPN.php index 836e155..4583a46 100644 --- a/src/PaypalIPN.php +++ b/src/PaypalIPN.php @@ -22,7 +22,6 @@ class PaypalIPN /** Response from PayPal indicating validation failed */ const INVALID = 'INVALID'; - /** * Sets the IPN verification to sandbox mode (for use when testing, * should not be enabled in production). @@ -43,7 +42,6 @@ public function usePHPCerts() $this->useLocalCerts = false; } - /** * Determine endpoint to post the verification data to. * @return string @@ -57,7 +55,6 @@ public function getPaypalUri() } } - /** * Verification Function * Sends the incoming post data back to PayPal using the cURL library. @@ -65,7 +62,7 @@ public function getPaypalUri() * @return bool * @throws Exception */ - function verifyIPN() + public function verifyIPN() { if (!count($_POST)) { throw new Exception("Missing POST Data"); @@ -86,16 +83,8 @@ function verifyIPN() } } $req = 'cmd=_notify-validate'; - $get_magic_quotes_exists = false; - if (function_exists('get_magic_quotes_gpc')) { - $get_magic_quotes_exists = true; - } foreach ($myPost as $key => $value) { - if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { - $value = urlencode(stripslashes($value)); - } else { - $value = urlencode($value); - } + $value = urlencode($value); $req .= "&$key=$value"; } @@ -112,10 +101,10 @@ function verifyIPN() } curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); - curl_setopt($ch, CURLOPT_HTTPHEADER, array( + curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'User-Agent: PHP-IPN-Verification-Script', 'Connection: Close', - )); + ]); $res = curl_exec($ch); $info = curl_getinfo($ch); $http_code = $info['http_code']; @@ -138,4 +127,3 @@ function verifyIPN() } } } -