Skip to content

Commit 635af4c

Browse files
committed
Formatting fixes + camelcase variables
1 parent 0b724ca commit 635af4c

File tree

1 file changed

+24
-43
lines changed

1 file changed

+24
-43
lines changed

src/PaypalIPN.php

+24-43
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1-
<?php
1+
<?php
22

33
namespace overint;
44

5-
use \Exception
5+
use \Exception;
66

77
class PaypalIPN
88
{
9-
10-
/**
11-
* @var bool $use_sandbox Indicates if the sandbox endpoint is used.
12-
*/
13-
private $use_sandbox = false;
14-
/**
15-
* @var bool $use_local_certs Indicates if the local certificates are used.
16-
*/
17-
private $use_local_certs = true;
9+
/** @var bool $useSandbox Indicates if the sandbox endpoint is used. */
10+
private $useSandbox = false;
11+
/** @var bool $useLocalCerts Indicates if the local certificates are used. */
12+
private $useLocalCerts = true;
1813

1914
/** Production Postback URL */
2015
const VERIFY_URI = 'https://ipnpb.paypal.com/cgi-bin/webscr';
@@ -35,7 +30,7 @@ class PaypalIPN
3530
*/
3631
public function useSandbox()
3732
{
38-
$this->use_sandbox = true;
33+
$this->useSandbox = true;
3934
}
4035

4136
/**
@@ -45,7 +40,7 @@ public function useSandbox()
4540
*/
4641
public function usePHPCerts()
4742
{
48-
$this->use_local_certs = false;
43+
$this->useLocalCerts = false;
4944
}
5045

5146

@@ -55,7 +50,7 @@ public function usePHPCerts()
5550
*/
5651
public function getPaypalUri()
5752
{
58-
if ($this->use_sandbox) {
53+
if ($this->useSandbox) {
5954
return self::SANDBOX_VERIFY_URI;
6055
} else {
6156
return self::VERIFY_URI;
@@ -72,23 +67,18 @@ public function getPaypalUri()
7267
*/
7368
function verifyIPN()
7469
{
75-
if ( ! count($_POST))
76-
{
70+
if (!count($_POST)) {
7771
throw new Exception("Missing POST Data");
7872
}
7973

8074
$raw_post_data = file_get_contents('php://input');
8175
$raw_post_array = explode('&', $raw_post_data);
8276
$myPost = [];
83-
foreach ($raw_post_array as $keyval)
84-
{
77+
foreach ($raw_post_array as $keyval) {
8578
$keyval = explode('=', $keyval);
86-
if (count($keyval) == 2)
87-
{
88-
if ($keyval[0] === 'payment_date')
89-
{
90-
if (substr_count($keyval[1], '+') === 1)
91-
{
79+
if (count($keyval) == 2) {
80+
if ($keyval[0] === 'payment_date') {
81+
if (substr_count($keyval[1], '+') === 1) {
9282
$keyval[1] = str_replace('+', '%2B', $keyval[1]);
9383
}
9484
}
@@ -97,17 +87,13 @@ function verifyIPN()
9787
}
9888
$req = 'cmd=_notify-validate';
9989
$get_magic_quotes_exists = false;
100-
if (function_exists('get_magic_quotes_gpc'))
101-
{
90+
if (function_exists('get_magic_quotes_gpc')) {
10291
$get_magic_quotes_exists = true;
10392
}
104-
foreach ($myPost as $key => $value)
105-
{
106-
if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1)
107-
{
93+
foreach ($myPost as $key => $value) {
94+
if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
10895
$value = urlencode(stripslashes($value));
109-
} else
110-
{
96+
} else {
11197
$value = urlencode($value);
11298
}
11399
$req .= "&$key=$value";
@@ -121,35 +107,30 @@ function verifyIPN()
121107
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
122108
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
123109
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
124-
if ($this->use_local_certs)
125-
{
110+
if ($this->useLocalCerts) {
126111
curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . "/cert/cacert.pem");
127112
}
128113
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
129114
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
130-
curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Connection: Close' ]);
115+
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Connection: Close']);
131116
$res = curl_exec($ch);
132117
$info = curl_getinfo($ch);
133118
$http_code = $info['http_code'];
134119

135-
if ($http_code != 200)
136-
{
120+
if ($http_code != 200) {
137121
throw new Exception("PayPal responded with http code $http_code");
138122
}
139123

140-
if ( ! ( $res ))
141-
{
124+
if (!($res)) {
142125
$errno = curl_errno($ch);
143126
$errstr = curl_error($ch);
144127
curl_close($ch);
145128
throw new Exception("cURL error: [$errno] $errstr");
146129
}
147130
curl_close($ch);
148-
if ($res == self::VALID)
149-
{
131+
if ($res == self::VALID) {
150132
return true;
151-
} else
152-
{
133+
} else {
153134
return false;
154135
}
155136
}

0 commit comments

Comments
 (0)