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,"digita_1197353879_biz@gmail.com")!=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: ipn@caregivingsocal.com\nReply-To: sales@caregivingsocal.com");

				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: ipn@caregivingsocal.com\nReply-To: sales@caregivingsocal.com");
} 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: ipn@caregivingsocal.com\nReply-To: sales@caregivingsocal.com");

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

}
}
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.