I have an adaptive payment processed with embedded payments. Everything works fine (the purchase gets processed), but my IPN listener is never notified. I have used the IPN testing tools PayPal provides and the listener picks up calls from that, but not from the embed payment.
This is the info being sent in the paykey:
$bodyparams = array (
"requestEnvelope.errorLanguage" => \"en_US",
"actionType" => "PAY",
"cancelUrl" => "http://mysite.com/cancel",
"returnUrl" => "http://mysite.com/buying",
"currencyCode" => "USD",
"paymentType" => "DIGITALGOODS",
"ipnNotificationUrl" => 'http://mysite.com/listener.php',
"trackingId" => $rows['key'],
"memo" => 'You are buying ' . $title . ' from ' . $paypal . '',
"receiverList.receiver.email" => $paypal,
"receiverList.receiver.amount" => $price
);
And this is my listener code (taken from the PayPal website):
<?php
$req = 'cmd=' . urlencode('_notify-validate');
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.sandbox.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: https://www.sandbox.paypal.com'));
$res = curl_exec($ch);
curl_close($ch);
$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 (strcmp ($res, "VERIFIED") == 0) {
$myFile = "log.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "logged ' . $txn_id . '\n";
fwrite($fh, $stringData);
fclose($fh);
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
?>
Again, the PayPal IPN testing tool proves that the listener works, but then why does the actual payment not notify the listener?