The code works until check number 3, then when I import them into the db I get a blank row or sometimes nothing. When I use
if ($_SERVER['REQUEST_METHOD'] != "POST") die ("No Post Variables");
code at the top, I get "No Post Variables" but I could use the post variables to check if there is something wrong. I see the item variable returned from ipn, because I can use them but when I import them into the db they do not appear.
Why can't I add them to the db?
I have been working on this IPN a week now without a result.
if ($_SERVER['REQUEST_METHOD'] != "POST") die ("No Post Variables");
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
$url = "https://sandbox.paypal.com/cgi-bin/webscr";
//$url = "https://www.paypal.com/cgi-bin/webscr";
$curl_result=$curl_err='';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_HTTPHEADER array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($req)));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
curl_setopt($ch, CURLOPT_HEADER , 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$curl_result = @curl_exec($ch);
$curl_err = curl_error($ch);
curl_close($ch);
$req = str_replace("&", "
", $req);
// Check Number 1 ------------------------------------------------------------------------------------------------------------
$receiver_email = $_POST['receiver_email'];
if ($receiver_email != "samuel_1347268213_biz@hotmail.com") {
$message = "Investigate why and how receiver email is wrong. Email = " . $_POST['receiver_email'] . "
$req";
mail("@hotmail.com", "Receiver Email is incorrect", $message, "From: samuel_1347268213_biz@hotmail.com" );
exit(); // exit script
}
// Check number 2 ------------------------------------------------------------------------------------------------------------
if ($_POST['payment_status'] != "Completed") {
// Handle how you think you should if a payment is not complete yet, a few scenarios can cause a transaction to be incomplete
mail("@hotmail.com", "payment_status", $message, "From: samuel_1347268213_biz@hotmail.com" );
}
// Connect to database ------------------------------------------------------------------------------------------------------
require_once 'connect_to_mysql.php';
// Check number 3 ------------------------------------------------------------------------------------------------------------
$payer_email = $_POST['payer_email'];
$sql = mysql_query("SELECT * FROM transactions WHERE payer_email= '".$payer_email."' LIMIT 1");
$numRows = mysql_num_rows($sql);
if ($numRows > 0) {
$message = "Duplicate transaction ID occured so we killed the IPN script.
$req";
mail("@hotmail.com", "Duplicate txn_id in the IPN system", $message, "From: samuel_1347268213_biz@hotmail.com" );
exit(); // exit script
$txn = $_POST['txn_id'];
$payer = $_POST['payer_email'];
$l = "INSERT INTO transactions (txn_id,payer_email)VALUES ('".$txd ."','".$payer ."')";
mysql_query($l)or die;
// Mail yourself the details
$req .= "
Dataverified from Paypal!";
mail("@hotmail.com", "NORMAL IPN+++ RESULT", $req, "From: samuel_1347268213_biz@hotmail.com");