I have been trying to integrate paypal processing into my website and have only gotten one feature to work. Now, nothing works What have I done wrong?
The processing file :
<?
$item = $_GET['cm'];
$status = $_GET['st'];
if($status == "Completed") {
if($item == "1dso"){
header("Location: complete_shoutout.php?tx=".$_GET['tx']);
exit;
}
if($item == "10000000points" || $item == "1000000points" || $item == "100000points"){
header("Location: actions.php?do_this=givepoints&tx=".$_GET['tx']);
exit;
}
if($item == "lifemembership"){
header("Location: actions.php?do_this=upme&tx=".$_GET['tx']);
exit;
}
if($item == "grudonation"){
header("Location: actions.php?do_this=makedonation&tx=".$_GET['tx']);
exit;
}
header("Location: index.php");
exit;
} else {
header("Location: index.php");
exit;
}
?>
the action file for "upme":
$req = 'cmd=_notify-synch';
$tx_token = $_GET['tx'];
if(empty($tx_token)) $tx_token = $_POST['tx'];
$auth_token = "tLyaEDztMYKOGSTHw34d2QaFJrNJ3KJlDlXmAT0JMUD9d6p3O5WsYn2eJru";
$req .= "&tx=$tx_token&at=$auth_token";
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
if(!$fp){
} else {
fputs ($fp, $header . $req);
$res = '';
$headerdone = false;
while (!feof($fp)) {
$line = fgets ($fp, 1024);
if (strcmp($line, "\r\n") == 0) {
// read the header
$headerdone = true;
} else if ($headerdone) {
$res .= $line;
}
}
$lines = explode("\n", $res);
$keyarray = array();
if (strcmp ($lines[0], "SUCCESS") == 0) {
for ($i=1; $i<count($lines);$i++){
list($key,$val) = explode("=", $lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}
$amount = $keyarray['payment_gross'];
$give = 0;
if($amount == "20.00"){
$isok = 1;
$give = 10000000;
$uptype = 1;
} else {
$isok = 0;
}
} else if (strcmp ($lines[0], "FAIL") == 0) {
$isok = 0;
}
}
fclose ($fp);
include "_db.connect.php";
$thedate = time();
$sql = mysql_query("INSERT INTO inbox (mid, fid, subject, message, thedate) VALUES ('1', '$mid', 'Member Upgraded', '$mid Upgraded - $isok - $tx_token', '$thedate')");
mysql_close($db);
if($isok == 1 && $give != 0 && isset($uptype)) {
$thedate = date("m-d-y");
include "_db.connect.php";
$sql = mysql_query("UPDATE members SET rpoints = rpoints + $give, paid_status=1, upgraded='$thedate', uptype='$uptype' WHERE id='$mid'") or die(mysql_error());
$thedate=time();
$sql = mysql_query("INSERT INTO budget (mid, amount, thedate, type) VALUES ('$mid', '$amount', '$thedate', '1')");
mysql_close($db);
header("Location: upgradecomplete.php?token=good");
exit;
} else {
header("Location: upgradecomplete.php?token=bad");
exit;
}
}
For some reason, the automatic upgrade is not working at all. I have the IPN set up in paypal and it is to return the information to the paypal processing file, then it is sent to the action file to update the database. I have 3 area's that all used paypal to automatically process the payment and allow the user access to the area. Is there anything in the code above that may cause paypal not to process the IPN data correctly?