php paypal ipn membership error
- by aleksander haugas
hello I integrated the membership subscription in the website,
but I fail to insert data to the database.
checking out all the function I make a txt file with php with data and generates me correctly.
but I can not verify any data and less insert.
<?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value)
{
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// Post back to PayPal system to validate
$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 ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
// Assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$user_id = $_POST['custom'];
//Here i make the txt file and it works correctly
//but after this does not work or make a txt file
//Insert and update data
if (!$fp)
{
// HTTP ERROR
}
else
{
fputs ($fp, $header . $req);
while (!feof($fp))
{
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0)
{
//Verificamos el estado del pedido
if ($payment_status == 'Completed')
{
$txn_id_check = mysql_query("SELECT Transaction_ID FROM ".$db_table_prefix."Users_Payments WHERE Transaction_ID='".$txn_id."'");
if (mysql_num_rows($txn_id_check) !=1)
{
//Si el pago se ha realizado al dueño especificado y coincide con el dueño
if ($receiver_email == $website_Payment_Email)
{
//Tipo de cuenta segun pagado
if ($payment_amount == '10.00' && $payment_currency == 'EUR')
{
//add txn_id to database
$log_query = mysql_query("INSERT INTO `".$db_table_prefix."Users_Payments` VALUES ('','".$txn_id."','".$payer_email."')");
//update premium to 3
$update_premium = mysql_query("UPDATE ".$db_table_prefix."Users SET Group_ID='3' WHERE User_ID='".$user_id."'");
}
}
}
}
}
else if (strcmp ($res, "INVALID") == 0)
{
// log for manual investigation
}
}
fclose ($fp);
}
?>
I call this file with require_once () with the connection to the database
any ideas?
thanks