Jump to content

Paypal IPN help


princeofpersia

Recommended Posts

Hi guys, my code below works with sanbox for paypal IPN but since it has gone live it doesnt do anything, so i made emails to send me where the issue is and it keep sending me $req = 'cmd=_notify-validate';

 

could you please tell me what im doing wrong here? my db connection should be fine as it does update the users on sanbox.

 

the account im paying with in paypal keep saying payment status unclaimed. it means the reciever has not recieved the money. I checked the paypal account where i recieve the moeny and looked into my ipn history, nothing there.

 

the same ipn address is used for my account when i tested it on sanbox,

 

thanks

 

<?php
$email="princeofpersia@hotmail.co.uk";

include 'global.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);
//$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);//Live
// assign posted variables to local variables

if (!$fp)// failed to connect to url
{
//write to file
$fh = fopen("logipn.txt", 'a');//open file and create if does not exist
fwrite($fh, "\r\n/////////////////////////////////////////\r\n HTTP ERROR \r\n");//Just for spacing in log file
fwrite($fh, $errstr);//write data
fclose($fh);//close file

//email
$mail_From = "From: IPN@tester.com";
$mail_To = $email;
$mail_Subject = "HTTP ERROR";
$mail_Body = $errstr;//error string from fsockopen
mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
} 
else//successful connect to url
{
fputs ($fp, $header . $req);//send request
while (!feof($fp)) //while not end of file
{
  $res = fgets ($fp, 1024);//get response
  if (strcmp ($res, "VERIFIED") == 0) 
  {
   //write to file
   $fh = fopen("logipn.txt", 'a');//open file and create if does not exist
   fwrite($fh, "\r\n/////////////////////////////////////////\r\n Verified \r\n");//Just for spacing in log file
   fwrite($fh, $req);//write data
   fclose($fh);//close file

   //email
   $mail_From = "From: IPN@tester.com";
   $mail_To = $email;
   $mail_Subject = "VERIFIED IPN";
   $mail_Body = $req;
   mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
  }
    else if (strcmp ($res, "INVALID") == 0) 
  {
   //write to file
   $fh = fopen("logipn.txt", 'a');//open file and create if does not exist
   fwrite($fh, "\r\n/////////////////////////////////////////\r\n Invalid \r\n");//Just for spacing in log file
   fwrite($fh, $req);//write data
   fclose($fh);//close file

   //email
   $mail_From = "From: IPN@tester.com";
   $mail_To = $email;
   $mail_Subject = "INVALID IPN";
   $mail_Body = $req;
   mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
  }
}
fclose ($fp);//close file pointer
}

$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'];
//$username=$_POST['username'];
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {

if (strtolower($payment_status)=="completed")

{

if ($payment_amount==0.01&&$payment_currency=="GBP") 
{

$update = mysql_query("UPDATE users SET credit= credit+5  WHERE email='$payer_email'");

}











}


// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment


}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>



Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.