-
Notifications
You must be signed in to change notification settings - Fork 3
/
notify_paypal.php
329 lines (296 loc) · 9.63 KB
/
notify_paypal.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<?php
include_once('init.php');
include_once('config.php');
include_once(DOC_ROOT.'/libraries.php');
if (!isset($_SESSION))
{
session_start();
}
ini_set("display_errors", "1");
error_reporting(E_ALL ^ E_NOTICE);
// ------------------------------------------- SETUP THE APPLICATION ------------------------------------------------------
//----------**********************----------------------************************-----------------------********************
$hostname_greekConn = "localhost";
$database_greekConn = "iapchiap_cbta";
$username_greekConn = "iapchiap_iap";
$password_greekConn = "febe1645D";
$greekConn = mysql_connect($hostname_greekConn, $username_greekConn, $password_greekConn) or die(mysql_error());
mysql_select_db($database_greekConn, $greekConn);
$yfditemnam = "Colegiatura"; // name of the items they are buying as set in the paypal form
$specitemnam = 'points';
$yfdrecemail = "[email protected]";
$table = "players";
$idFieldName = "id";
function getdatawhere($id,$fields,$table,$field){
$sql="select $fields from ".$table." where ".$field."='$id' ";
$query=mysql_query($sql);
$rows=mysql_num_rows($query);
if($rows==0){return;}
$rs=mysql_fetch_assoc($query);
return $rs;
}
function updateuserdata($id, $str)
{
$str2 = "update `".$table."` set $str WHERE ".$idFieldName."='$id' ";
$str3 = "update `".$table."` set $str, debug = ".$str." WHERE ".$idFieldName."='$id' ";
$q = @mysql_query($str3);
if (!$q) {
print ('Query failed: '.mysql_error());
return;
}
return $q;
}
$postmode=1;
$debugger=0;
if (phpversion() <= '4.0.6')
{
$_SERVER = ($HTTP_SERVER_VARS);
$_POST = ($HTTP_POST_VARS);
}
// No ipn post means this script does not exist
if (!@$_POST['txn_type'])
{
@header("Status: 404 Not Found"); exit;
}
else
{
@header("Status: 200 OK"); // Prevents ipn reposts on some servers
$postipn = 'cmd=_notify-validate'; // Notify validate
foreach ($_POST as $ipnkey => $ipnval)
{
if (get_magic_quotes_gpc())
$ipnval = stripslashes ($ipnval); // Fix issue with magic quotes
if (!preg_match("/^[_0-9a-z-]{1,30}$/i",$ipnkey) || !strcasecmp ($ipnkey, 'cmd'))
{ // ^ Antidote to potential variable injection and poisoning
unset ($ipnkey); unset ($ipnval);
} // Eliminate the above
if (@$ipnkey != '')
{ // Remove empty keys (not values)
@$_PAYPAL[$ipnkey] = $ipnval; // Assign data to new global array
//unset ($_POST); // Destroy the original ipn post array, sniff...
$postipn.='&'.@$ipnkey.'='.urlencode(@$ipnval);
}
} // Notify string
$postipn .= '&'.http_build_query($_POST);
$error=0; // No errors let's hope it's going to stays like this!
if ($postmode == 1)
{
$domain = "www.paypal.com";
}
elseif ($postmode == 2)
{
$domain = "www.eliteweaver.co.uk";
}
else
{
$error=1;
$bmode=1;
}
@set_time_limit(60); // Attempt to double default time limit incase we switch to Get
// Post back the reconstructed instant payment notification
$socket = @fsockopen($domain,80,$errno,$errstr,30);
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header.= "User-Agent: PHP/".phpversion()."\r\n";
$header.= "Referer: ".$_SERVER['HTTP_HOST'].
$_SERVER['PHP_SELF'].@$_SERVER['QUERY_STRING']."\r\n";
$header.= "Server: ".$_SERVER['SERVER_SOFTWARE']."\r\n";
$header.= "Host: ".$domain.":80\r\n";
$header.= "Content-Type: application/x-www-form-urlencoded\r\n";
$header.= "Content-Length: ".strlen($postipn)."\r\n";
$header.= "Accept: */*\r\n\r\n";
//* Note: "Connection: Close" is not required using HTTP/1.0
// Problem: Now is this your firewall or your ports?
if (!$socket && !$error)
{
// Switch to a Get request for a last ditch attempt!
$getrq=1;
if (phpversion() >= '4.3.0' && function_exists('file_get_contents'))
{
} // Checking for a new function
else
{ // No? We'll create it instead
function file_get_contents($ipnget)
{
$ipnget = @file($ipnget);
return $ipnget[0];
}
}
$response = @file_get_contents('http://'.$domain.':80/cgi-bin/webscr?'.$postipn);
if (!$response)
{
$error=1;
$getrq=0;
}
}
// If no problems have occured then we proceed with the processing
else
{
@fputs ($socket,$header.$postipn."\r\n\r\n"); // Required on some environments
while (!feof($socket))
{
$response = fgets ($socket,1024);
}
}
$response = trim ($response);
$amount = $_PAYPAL['amount'];
$receiver_email = $_PAYPAL['receiver_email'];
$receiver_id = $_PAYPAL['receiver_id'];
$business = $_PAYPAL['business'];
$item_name = $_PAYPAL['item_name'];
$item_number = $_PAYPAL['item_number'];
$quantity = $_PAYPAL['quantity'];
$invoice = $_PAYPAL['invoice'];
$custom = $_PAYPAL['custom'];
$option_name1 = $_PAYPAL['option_name1'];
$option_selection1 = $_PAYPAL['option_selection1'];
$option_name2 = $_PAYPAL['option_name2'];
$option_selection2 = $_PAYPAL['option_selection2'];
$num_cart_items = $_PAYPAL['num_cart_items'];
$payment_status = $_PAYPAL['payment_status'];
$pending_reason = $_PAYPAL['pending_reason'];
$payment_date = $_PAYPAL['payment_date'];
$settle_amount = $_PAYPAL['settle_amount'];
$settle_currency = $_PAYPAL['settle_currency'];
$exchange_rate = $_PAYPAL['exchange_rate'];
$payment_gross = $_PAYPAL['payment_gross'];
$payment_fee = $_PAYPAL['payment_fee'];
$mc_gross = $_PAYPAL['mc_gross'];
$mc_fee = $_PAYPAL['mc_fee'];
$mc_currency = $_PAYPAL['mc_currency'];
$tax = $_PAYPAL['tax'];
$txn_id = $_PAYPAL['txn_id'];
$txn_type = $_PAYPAL['txn_type'];
$reason_code = $_PAYPAL['reason_code'];
$for_auction = $_PAYPAL['for_auction'];
$auction_buyer_id = $_PAYPAL['auction_buyer_id'];
$auction_close_date = $_PAYPAL['auction_close_date'];
$auction_multi_item = $_PAYPAL['auction_multi_item'];
$memo = $_PAYPAL['memo'];
$first_name = $_PAYPAL['first_name'];
$last_name = $_PAYPAL['last_name'];
$address_street = $_PAYPAL['address_street'];
$address_city = $_PAYPAL['address_city'];
$address_state = $_PAYPAL['address_state'];
$address_zip = $_PAYPAL['address_zip'];
$address_country = $_PAYPAL['address_country'];
$address_status = $_PAYPAL['address_status'];
$payer_email = $_PAYPAL['payer_email'];
$payer_id = $_PAYPAL['payer_id'];
$payer_business_name = $_PAYPAL['payer_business_name'];
$payer_status = $_PAYPAL['payer_status'];
$payment_type = $_PAYPAL['payment_type'];
$notify_version = $_PAYPAL['notify_version'];
$verify_sign = $_PAYPAL['verify_sign'];
$userid = $option_name1;
$username = $option_name2;
$d=date("d");
$m=date("M");
$y=date("y");
$date="$d/$m/$y";
// IPN was confirmed as both genuine and VERIFIED
if (!strcmp ($response, "VERIFIED"))
{
if($receiver_email==$yfdrecemail OR $receiver_email==$yfdrecemail)
{
$query = mysql_query("SELECT ipnid FROM ipn WHERE trans='$txn_id'");
$txn_check = mysql_fetch_array($query);
if($txn_check[id]=="")
{
if(($payment_gross / $quantity) < 0)
{
}
elseif($item_name==$yfditemnam)
{
$sql="SELECT * FROM ipn WHERE trans='".$txn_id."' AND verified='Completed'";
$query=mysql_query($sql);
$rows=mysql_num_rows($query);
if($rows==0)
{
$points = $item_name;
/*
$sale=0; // if a sale is on then set the bonus amount below note 20 = 20% bonus
if($sale==1 && $quantity >= 20)
{
$points = $points + ceil($points * 0.2);
}
$detailuser= getdatawhere($userid,'*',$table,$idFieldName);
$before = $detailuser[$specitemnam];
$after = 0;
*/ $now=time();
$str = "INSERT INTO `ipn` ( `ipnid` , `name` , `user` , `points` , `trans` , `before` , `after`, `ipnstatus`, `verified`, `time`) VALUES (NULL , '$item_number', '$userid', '$points', '$txn_id', '$before', '0', '0', '$payment_status', '$now')";
// echo "$str<br>";
$q = @mysql_query($str);
if($payment_status == 'Completed')
{
$sql = "
INSERT INTO `payment` (
`date` ,
`invoiceId` ,
`amount` ,
`paymentMethod` ,
`comments` ,
`credit` ,
`amountApplied` ,
`account` ,
`anticipo`
)
VALUES (
'".date("Y-m-d")."',
'".$item_number."',
'".$payment_gross."',
'Transferencia',
'Pago a traves de Paypal',
'0',
'".$payment_gross."',
'' ,
'0')";
mysql_query($sql) or die(mysql_error());
//updateuserdata($userid, $specitemnam." = ".$specitemnam." + '".$points."' ");
$payments = new Payments;
$payments->setInvoiceId($item_number);
$invoice = $payments->InvoiceInfo();
error_log($invoice["status"]);
if($invoice["status"] == "Pagada")
{
$db->setQuery("
UPDATE user_subject SET status = 'activo'
WHERE alumnoId = '".$invoice["userId"]."' AND courseId = '".$invoice["courseId"]."'");
$db->UpdateData();
}
}
//$detailuser2=getdatawhere($userid,'*',$table,$idFieldName);
$after = $detailuser2[$specitemnam];
$str = "update `ipn` set after = '$after', ipnstatus = '1' where trans = '$txn_id' ";
// echo "$str<br>";
$q = @mysql_query($str);
if (!$q)
{
print ('Query failed: '.mysql_error());
return;
}
}
}
}// txn exists
}// is shadowops / modern-war-generals
else
{ // was not me, they tried to cheat!
echo "cheater";
}
}
// IPN was not validated as genuine and is INVALID
elseif (!strcmp ($response, "INVALID"))
{
}
else
{ // Just incase something serious should happen!
}
}
function variableAudit($v,$c)
{
global $_PAYPAL;
if (!strcasecmp($_PAYPAL[$v],$c))
{ return 1; } else { return 0; }
}
// Terminate the socket connection (if open) and exit
@fclose ($socket); exit;
?>