Jump to content

paypal ipn script not editing database after payment


dolcezza

Recommended Posts

This is the page that paypal returns to after payment

it's supposed to change the database foeld "verified" to 1

I am pretty new at this and would appreciate any help.

 

<?php
require_once("db_connect.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 ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
//$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);

// assign posted variables to local variables
$item_name = $_POST['item_name'];
$caregivers_id = $_POST['custom'];
$payment_status = $_POST['payment_status'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// check the payment_status is Completed
 if (strcmp ($payment_status, "Completed") == 0) {
	// check that txn_id has not been previously processed
 	// check that receiver_email is your Primary PayPal email
	  if (strcmp($receiver_email,"[email protected]")!=0)
	     {
	     $bad_txn = 1;
	     $reason .= "Invalid receiver email address<br>";
	     }
// check that payment_amount/payment_currency are correct
		if ($bad_txn == 1) {
			//send email error message
			mail($payer_email, "An Error Occurred...", "Dear Customer,\n an error occurred while PayPal was processing your order. It will be investigated by a human at the earliest opportunity.\n\nWe apologise for any inconvenience.", "From: [email protected]\nReply-To: [email protected]");

				mail($receiver_email, "Invalid PayPal TX...", "An invalid transaction requires your attention. $reason");
} else {
	//change verified value
$update = mysql_query("UPDATE caregivers SET verified = 1 WHERE caregivers_id = '$caregivers_id' LIMIT 1") or die(mysql_error());

 $message .= "Dear Customer,\n Thankyou for your order.\n\nYour listing will be posted shortly.  If you have any problems, please contact us: \n\nsales\@caregivingsocal.com";

mail($payer_email, "Thank You...", $message, "From: [email protected]\nReply-To: [email protected]");
} else if {
	 $message .= "Dear Customer,\n Thankyou for your order.\n\nYour listing will be posted as soon as the funds have cleared.\n\nThankyou \n\nsales\@caregivingsocal.com";

	mail($payer_email, "Thank You...", $message, "From: [email protected]\nReply-To: [email protected]");

	mail($receiver_email, "Incomplete PayPal TX...", "An incomplete transaction requires your attention.");

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


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.