Jump to content

PayPal IPN help needed Urgently


denno020

Recommended Posts

I have set up my PayPal IPN and it works perfectly when sending test IPN's using the IPN Simulator on the PayPal developer website.

 

When I change the ssl in this line

$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

to

www.paypal.com

 

It no longer works. It comes back as INVALID, not VERIFIED.

 

Anyone know what the problem could be?

 

My IPN is below. You'll see there is entries into the log table, this is just for testing purposes, and how I found out that it's coming back as INVALID and not VERIFIED.

 

Thanks

Denno

 

<?php

//connect to the database here
include "../scripts/connect_to_mysql.php";
//-------------------------------


// PHP 4.1

// 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
$team_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'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$associated_club = $_POST['custom'];
$contact_number = $_POST['invoice'];

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);


if (strcmp ($res, "VERIFIED") == 0) {
//User code is added below here
$dateField=date("Y-m-d H:i:s");
$sqlCommand = "INSERT INTO log VALUES('','$dateField','$payment_status','$payment_amount','$payment_currency','1','0')";
$update = mysql_query($sqlCommand, $myConnection);
if($payment_status == "Completed"){
	if($payment_amount == '40.00' && $payment_currency == "AUD"){
		//process payment and enter information into database			
		$sqlCommand = "INSERT INTO teams VALUES ('','$first_name','$last_name','$associated_club','$team_name','$contact_number','1')";
		$update = mysql_query($sqlCommand, $myConnection);
	}
}
//User code is added above here

}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
$dateField=date("Y-m-d H:i:s");
$sqlCommand = "INSERT INTO log VALUES('','$dateField','$payment_status','$payment_amount','$payment_currency','0','1')";
$update = mysql_query($sqlCommand, $myConnection);
}
}
fclose ($fp);
}
echo "$sqlCommand";
?>

 

 

Link to comment
Share on other sites

I believe I found code on a forum and manipulated it... they also have a really good script generator you could use...this is my working code:

 

 

include("includes/db_connect.php");

$txn_id = $_POST['txn_id'];

$r1 = mysql_query("SELECT * FROM orders WHERE txn_id='$txn_id' ")
or die(mysql_error());

if(mysql_num_rows($r1) == 1) exit();




// 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.paypal.com', 80, $errno, $errstr, 30);
// If possible, securely post back to paypal using HTTPS
// Your PHP server will need to be SSL enabled
// $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);





if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);




if (strcmp ($res, "VERIFIED") == 0) {

//////
//////do stuff here
/////

} //close if
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
} ///close else if

}
}
fclose ($fp);

 

  Check out this link for the script generator...

https://www.paypaltech.com/sg2/

 

What hosting do you have? I DID have godaddy and had major problems with godaddy allowing POST data to be sent to my server.  I was on a shared hosting plan.  The only way I could fix it was to buy a dedicated IP address.. I just switched hosting providors and everything is fine now.

 

Link to comment
Share on other sites

I'm with JustHost for the web hosting..

 

I'm not sure about the ins and outs with their SSL and receiving POST data..

I'm actually creating this website for a client, so this is the host that they've got.

And thankyou harristweed, I'm pretty sure I already said that I have changed the POST destination..

 

The weird thing is, when I first set up the button, I put it with a price of $0.01, and made a payment using my paypal account (a normal buyers account), and the IPN worked fine. I then changed the price to the correct amount, and the 5 payments that have occurred since then, the IPN didn't work properly. I set up another button with a price of $0.01 on a different page in the site, and tested it again myself, and again, it worked perfectly. So I don't know why it would work perfectly when I'm paying, but not when other people are paying?

 

Denno

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.