diff --git a/src/PaypalIPN.php b/src/PaypalIPN.php index b4f1561..7f510ed 100644 --- a/src/PaypalIPN.php +++ b/src/PaypalIPN.php @@ -1,20 +1,15 @@ -use_sandbox = true; + $this->useSandbox = true; } /** @@ -45,7 +40,7 @@ public function useSandbox() */ public function usePHPCerts() { - $this->use_local_certs = false; + $this->useLocalCerts = false; } @@ -55,7 +50,7 @@ public function usePHPCerts() */ public function getPaypalUri() { - if ($this->use_sandbox) { + if ($this->useSandbox) { return self::SANDBOX_VERIFY_URI; } else { return self::VERIFY_URI; @@ -72,23 +67,18 @@ public function getPaypalUri() */ function verifyIPN() { - if ( ! count($_POST)) - { + if (!count($_POST)) { throw new Exception("Missing POST Data"); } $raw_post_data = file_get_contents('php://input'); $raw_post_array = explode('&', $raw_post_data); $myPost = []; - foreach ($raw_post_array as $keyval) - { + foreach ($raw_post_array as $keyval) { $keyval = explode('=', $keyval); - if (count($keyval) == 2) - { - if ($keyval[0] === 'payment_date') - { - if (substr_count($keyval[1], '+') === 1) - { + if (count($keyval) == 2) { + if ($keyval[0] === 'payment_date') { + if (substr_count($keyval[1], '+') === 1) { $keyval[1] = str_replace('+', '%2B', $keyval[1]); } } @@ -97,17 +87,13 @@ function verifyIPN() } $req = 'cmd=_notify-validate'; $get_magic_quotes_exists = false; - if (function_exists('get_magic_quotes_gpc')) - { + 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) - { + foreach ($myPost as $key => $value) { + if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { $value = urlencode(stripslashes($value)); - } else - { + } else { $value = urlencode($value); } $req .= "&$key=$value"; @@ -121,35 +107,30 @@ function verifyIPN() curl_setopt($ch, CURLOPT_SSLVERSION, 6); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); - if ($this->use_local_certs) - { + if ($this->useLocalCerts) { curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . "/cert/cacert.pem"); } 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, ['Connection: Close']); $res = curl_exec($ch); $info = curl_getinfo($ch); $http_code = $info['http_code']; - if ($http_code != 200) - { + if ($http_code != 200) { throw new Exception("PayPal responded with http code $http_code"); } - if ( ! ( $res )) - { + if (!($res)) { $errno = curl_errno($ch); $errstr = curl_error($ch); curl_close($ch); throw new Exception("cURL error: [$errno] $errstr"); } curl_close($ch); - if ($res == self::VALID) - { + if ($res == self::VALID) { return true; - } else - { + } else { return false; } }