jim_bo
01-11-2008, 10:17 PM
Hi,
I have the following code for paypal ipn. Using the sandbox to test it. When the transaction goes thru successfully, it emails me saying it failed?
This is the php code direct from paypal un modified.
<?php
$req = 'cmd=_notify-validate';
$to = 'emailaddy';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
$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);
$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'];
if (!$fp) {
// Failed to connect
$subject = 'Failed to connect';
$to = "$to";
$body = "Failed to connect to paypal\n";
mail($to, $subject, $body);
}else{
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// Worked
$subject = 'Instant Payment Notification - Payment Worked';
$to = "$to";
$body = "An instant payment notification worked\n";
mail($to, $subject, $body);
}
else if (strcmp ($res, "INVALID") == 0) {
// Failed
$subject = 'Instant Payment Notification - Payment Failed';
$to = "$to";
$body = "An instant payment notification failed\n";
mail($to, $subject, $body);
}
}
fclose ($fp);
}
?>
Am I doing something wrong?
Thanks
I have the following code for paypal ipn. Using the sandbox to test it. When the transaction goes thru successfully, it emails me saying it failed?
This is the php code direct from paypal un modified.
<?php
$req = 'cmd=_notify-validate';
$to = 'emailaddy';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
$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);
$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'];
if (!$fp) {
// Failed to connect
$subject = 'Failed to connect';
$to = "$to";
$body = "Failed to connect to paypal\n";
mail($to, $subject, $body);
}else{
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// Worked
$subject = 'Instant Payment Notification - Payment Worked';
$to = "$to";
$body = "An instant payment notification worked\n";
mail($to, $subject, $body);
}
else if (strcmp ($res, "INVALID") == 0) {
// Failed
$subject = 'Instant Payment Notification - Payment Failed';
$to = "$to";
$body = "An instant payment notification failed\n";
mail($to, $subject, $body);
}
}
fclose ($fp);
}
?>
Am I doing something wrong?
Thanks