View Full Version : Paypal IPN

01-13-2008, 12:10 AM

I have script setup via sandbox testing IPN, some countrys work fine but AUD and USD seem to fail with a retry notice.

Does the sandbox have issues with those countrys?

If I use NZD among a few others it works ..

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="redirect_cmd" value="_xclick">
<input type="hidden" name="cmd" value="_ext-enter">
<input type="hidden" name="first_name" value="'.$firstname.'">
<input type="hidden" name="last_name" value="'.$lastname.'">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="email" value="'.$customer_email.'">
<input type="hidden" name="business" value="'.$business_email.'">
<input type="hidden" name="item_name" value="Cart Contents">
<input type="hidden" name="currency_code" value="AUD">
<input type="hidden" name="cancel_return" value="http://www.bla.com/paypal.php?canceled">
<input type="hidden" name="return" value="http://www.bla.com/paypal.php?success">
<input type="hidden" name="amount" value="'.$total.'">
<input type="hidden" name="notify_url" value="'.$url.'/paypal.php?action=ipn">
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payment with PayPal">

$req = 'cmd=_notify-validate';

// Email address to email ipn success/fail
$to = '####';

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.sandbox.paypal.com', 80, $errno, $errstr, 30);

// Dont alter these 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'];

if(!$fp) {

// Failed connection to paypal
$subject = 'Failed to connect';
$to = "$to";
$body = "Failed to connect to paypal\n";
mail($to, $subject, $body);


fputs($fp, $header . $req);
while(!feof($fp)) {
$res = fgets ($fp, 1024);

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

// Mysql_query here to update database

// Email admin (success)
$subject = 'Instant Payment Notification - Payment Worked';
$to = "$to";
$body = "An instant payment notification worked\n";
mail($to, $subject, $body);

// Payment failed
}elseif(strcmp ($res, "INVALID") == 0) {

// Email admin (failed)
$subject = 'Instant Payment Notification - Payment Failed';
$to = "$to";
$body = "An instant payment notification failed\n";
mail($to, $subject, $body);

fclose ($fp);