Skip to content

Commit f37cd2f

Browse files
committed
indent fix
1 parent 5cd8be3 commit f37cd2f

File tree

1 file changed

+76
-62
lines changed

1 file changed

+76
-62
lines changed

PaypalIPN.php

+76-62
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
<?php
22

3-
class PaypalIPN {
3+
class PaypalIPN
4+
{
5+
6+
private $use_sandbox = false;
47

5-
private $use_sandbox = false;
68
private $use_local_certs = true;
79

810
/*
911
* PayPal IPN postback endpoints
1012
*/
1113

12-
const VERIFY_URI = 'https://ipnpb.paypal.com/cgi-bin/webscr';
14+
const VERIFY_URI = 'https://ipnpb.paypal.com/cgi-bin/webscr';
1315
const SANDBOX_VERIFY_URI = 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr';
1416

1517
/*
@@ -25,24 +27,25 @@ class PaypalIPN {
2527
* should not be enabled in production).
2628
* @return void
2729
*/
28-
public function useSandbox()
30+
public function useSandbox()
2931
{
30-
$this->use_sandbox = true;
32+
$this->use_sandbox = true;
3133
}
3234

3335

3436
/**
3537
* Determine endpoint to post the verification data to.
3638
* @return string
3739
*/
38-
public function getPaypalUri()
40+
public function getPaypalUri()
3941
{
40-
if ($this->use_sandbox)
41-
{
42-
return self::SANDBOX_VERIFY_URI;
43-
} else {
44-
return self::VERIFY_URI;
45-
}
42+
if ($this->use_sandbox)
43+
{
44+
return self::SANDBOX_VERIFY_URI;
45+
} else
46+
{
47+
return self::VERIFY_URI;
48+
}
4649
}
4750

4851

@@ -54,54 +57,63 @@ public function getPaypalUri()
5457
* @throws Exception
5558
*/
5659
function verifyIPN()
57-
{
58-
if (!count($_POST))
60+
{
61+
if ( ! count($_POST))
5962
{
6063
throw new Exception("Missing POST Data");
6164
}
6265

63-
$raw_post_data = file_get_contents('php://input');
64-
$raw_post_array = explode('&', $raw_post_data);
65-
$myPost = [];
66-
foreach ($raw_post_array as $keyval) {
67-
$keyval = explode('=', $keyval);
68-
if (count($keyval) == 2) {
69-
if ($keyval[0] === 'payment_date') {
70-
if (substr_count($keyval[1], '+') === 1)
71-
$keyval[1] = str_replace('+', '%2B', $keyval[1]);
72-
}
73-
$myPost[$keyval[0]] = urldecode($keyval[1]);
74-
}
75-
}
76-
$req = 'cmd=_notify-validate';
77-
$get_magic_quotes_exists = false;
78-
if (function_exists('get_magic_quotes_gpc')) {
79-
$get_magic_quotes_exists = true;
80-
}
81-
foreach ($myPost as $key => $value) {
82-
if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
83-
$value = urlencode(stripslashes($value));
84-
} else {
85-
$value = urlencode($value);
86-
}
87-
$req .= "&$key=$value";
88-
}
89-
90-
$ch = curl_init($this->getPaypalUri());
91-
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
92-
curl_setopt($ch, CURLOPT_POST, 1);
93-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
94-
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
95-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
96-
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
66+
$raw_post_data = file_get_contents('php://input');
67+
$raw_post_array = explode('&', $raw_post_data);
68+
$myPost = [];
69+
foreach ($raw_post_array as $keyval)
70+
{
71+
$keyval = explode('=', $keyval);
72+
if (count($keyval) == 2)
73+
{
74+
if ($keyval[0] === 'payment_date')
75+
{
76+
if (substr_count($keyval[1], '+') === 1)
77+
{
78+
$keyval[1] = str_replace('+', '%2B', $keyval[1]);
79+
}
80+
}
81+
$myPost[$keyval[0]] = urldecode($keyval[1]);
82+
}
83+
}
84+
$req = 'cmd=_notify-validate';
85+
$get_magic_quotes_exists = false;
86+
if (function_exists('get_magic_quotes_gpc'))
87+
{
88+
$get_magic_quotes_exists = true;
89+
}
90+
foreach ($myPost as $key => $value)
91+
{
92+
if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1)
93+
{
94+
$value = urlencode(stripslashes($value));
95+
} else
96+
{
97+
$value = urlencode($value);
98+
}
99+
$req .= "&$key=$value";
100+
}
101+
102+
$ch = curl_init($this->getPaypalUri());
103+
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
104+
curl_setopt($ch, CURLOPT_POST, 1);
105+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
106+
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
107+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
108+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
97109
if ($this->use_local_certs)
98110
{
99111
curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . "/cert/cacert.pem");
100112
}
101-
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
102-
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
103-
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Connection: Close']);
104-
$res = curl_exec($ch);
113+
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
114+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
115+
curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Connection: Close' ]);
116+
$res = curl_exec($ch);
105117
$info = curl_getinfo($ch);
106118
$http_code = $info['http_code'];
107119

@@ -110,19 +122,21 @@ function verifyIPN()
110122
throw new Exception("PayPal responded with http code $http_code");
111123
}
112124

113-
if (!($res)) {
125+
if ( ! ( $res ))
126+
{
114127
$errno = curl_errno($ch);
115128
$errstr = curl_error($ch);
116129
curl_close($ch);
117130
throw new Exception("cURL error: [$errno] $errstr");
118-
}
119-
curl_close($ch);
120-
if ($res == self::VALID)
121-
{
122-
return true;
123-
} else {
124-
return false;
125-
}
126-
}
131+
}
132+
curl_close($ch);
133+
if ($res == self::VALID)
134+
{
135+
return true;
136+
} else
137+
{
138+
return false;
139+
}
140+
}
127141
}
128142

0 commit comments

Comments
 (0)