I think I have tried everything, but obviously not. I have the issue narrowed to the fsocketopen part. When I use the ssl:// address in the tutorials, i get 400 bad request returned. when I use
www.sandbox.paypal.com, 80... It returns
Quote:
POST /cgi-bin/webscr HTTP/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 837
cmd=_notify-validate&test_ipn=1&payment_type=instant&payment_date=10%3A32%3A00+Oct+28%2C+2012+PDT&payment_status =Completed&address_status=confirmed&paye...
|
Never returns "verified", although verified is passed in the original $_POST data under payer_status.
Code never makes it past if (strcmp ($res, "VERIFIED") == 0) {
Here is the code I am using...
PHP Code:
<?PHP
require '../glob.inc.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);
// 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'];
$memnum = mysql_real_escape_string($_POST['custom']); //our users ID
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header.$req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
//the two lines below are only so I can see what is going on by logging to my database. I am not sure how to create an error log file.
$payer_email = $res;
$log_query = mysql_query("INSERT INTO ipn_log VALUES ('','".$memnum."','".$txn_id."','".$payer_email."','".$header.$req."')");
if (strcmp ($res, "VERIFIED") == 0) {
//code never makes it to this point.
if ($payment_status=='Completed'){
$txn_id_check = mysql_query("SELECT 'txn_id' FROM 'log' WHERE 'txn_id'='".$txn_id."'");
if (mysql_num_rows($txn_id_check)!=1){
if ($receiver_email == 'myemailaddress'){
//if ($payment_amount == '20.00' && $payment_currency == 'USD') {
//add txn_id to database log table
$log_query = mysql_query("INSERT INTO ipn_log VALUES ('','".$memnum."','".$txn_id."','".$payer_email."')");
//update paid field
$update_paid = mysql_query("UPDATE members SET cknum='".$txn_id."', Amount='".$payment_amount." WHERE 'memid'='".$memnum."'");
//}
}
}
}
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>
Any help you can give would certainly be appreciated.
Thanks in advance,
TB