dongqiu3709 2013-02-26 13:54
浏览 189

Paypal沙盒IPN模拟器 - 没有得到响应

I have used exactly same code from paypal and try to get response from IPN simulator from Payapl Sandbox. I have set up ipn.php file on my website where I will get IPN response and it has below code. Still I am not getting any mail for either VERIFIED or INVALID status as I stated in below code. So please let me know what is missing or what is wrong in my code so I can correct it.

<?php
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
$keyval = explode ('=', $keyval);
if (count($keyval) == 2)
    $myPost[$keyval[0]] = urldecode($keyval[1]);
}

$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
$get_magic_quotes_exists = true;
} 
foreach ($myPost as $key => $value) {        
if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { 
    $value = urlencode(stripslashes($value)); 
} else {
    $value = urlencode($value);
}
$req .= "&$key=$value"; 
}

$ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
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_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));

if( !($res = curl_exec($ch)) ) {
// error_log("Got " . curl_error($ch) . " when processing IPN data");
curl_close($ch);
exit;
}
curl_close($ch);

if (strcmp ($res, "VERIFIED") == 0) {
$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'];

mail('mymailid@yahoo.com', 'PayPal IPN', 'Working...');
} 
else if (strcmp ($res, "INVALID") == 0) 
{
// log for manual investigation
mail('kra_14_05@yahoo.co.in', 'PayPal IPN', 'NOT Working...');  
}
?>

I have tried to test using test merchant and buyer accounts in paypal sandbox. I can see IPN history under test merchant account. There I can see HTTP response code = 200 so I guess my ipn script is accessed by Paypal. $0.25 amount is debited from buyer account and deposited into merchant account so I guess that part is also working fine.

Now I have passed 2 values in single variable like.

<input type="hidden" name="custom" value="mem001::mempass001">

Then I am trying to receive values of "custom" variable on my ipn.php (ipn script is on this page) page. Using php functions I have separated both values and stored in different variables.

For testing purpose, I am trying to store above values in database but values are not stored into database.

So finally what wrong I am doing so far? And how can i make sure that I am really getting "VERIFIED" status from IPN after all above processes? Please help.

  • 写回答

1条回答 默认 最新

  • donglilian0061 2013-02-26 16:16
    关注

    I would first start by checking your access logs and error logs on your server. Make sure your access logs show that PayPal is actually attempting to POST the data to your script. If the access logs show PayPal posting to your script, then check your error logs to see if there are any errors being generated.

    Make sure your server, is configured to all inbound and out bound connections and that you don't have anything that would be blocking access to your system. Another option, would be to set this up on a test sandbox seller account and go through and make a purchase with a test sandbox seller account instead of using the simulator. The one plus side to this is that, when you go through the account and make a payment you will have a record of the IPN in your IPN history. You can then check to verify that PayPal was sending it out. It will also tell you if your server responded back with a 200ok response, or if your server returned a different status other than 200ok.

    I have used the same script example that you are which is based on the script at https://www.x.com/developers/PayPal/documentation-tools/code-sample/216623 and this has worked for me in the past. If this doesn't help, let me know and I can try testing it with your script and pulling up one of my PHP scripts that send out an email.

    评论

报告相同问题?

悬赏问题

  • ¥15 echarts动画效果失效的问题。官网下载的例子。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加