简体   繁体   English

贝宝IPN使用“立即购买”按钮返回“无效”,但已通过IPN Simulator验证

[英]Paypal IPN returns INVALID with buy now button But VERIFIED with IPN Simulator

I'm stuck at the problem with paypal IPN and it is getting always invalid when i use paypal buy now button, however it works perfectly with IPN simulator. 我被贝宝(Paypal)IPN困扰,当我使用贝宝(Paypal)立即购买按钮时,它总是无效,但是它与IPN模拟器完美配合。

I know there are many questions and answers at stackoverflow about this to help but i have tried lots of things from here and also from other sites, none of them worked. 我知道在stackoverflow上有很多关于此的问题和答案可以帮助您,但是我从这里以及从其他站点尝试了很多事情,但没有一个起作用。

Here is the button code i'm using, 这是我正在使用的按钮代码,

<form name="_xclick" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick"><input type="hidden" name="business" value="xxx-facilitator@gmail.com">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="item_name" value="Teddy Bear">
<input type="hidden" name="amount" value="12.99">
<input type="hidden" name="notify_url" value="http://mysite/ipn">
<input type="hidden" name="custom" value="2">
<input type="hidden" name="return" value="http://mysite/success">
<input type="hidden" name="cancel_return" value="http://mysite/cancel">
<input type="image" src="http://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>

And here is the IPN Listener Code, 这是IPN侦听器代码,

<?php
    $url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
    $postFields = 'cmd=_notify-validate';
    foreach($_POST as $key => $value){
        $value = urlencode(stripslashes($value));
        $postFields .= "&$key=".$value;
    }

    $ch = curl_init();
    curl_setopt_array($ch, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $postFields
    ));
    $result = curl_exec($ch);
    curl_close($ch);
    if($result == "VERIFIED"){
        $handle = fopen('ipn.txt','w');
        fwrite($handle,$result.'----'.$postFields);
        fclose($handle);
    }else{
        $handle = fopen('ipn.txt','w');
        fwrite($handle,$result.'----'.$postFields);
        fclose($handle);
    }

And here is the response i saved into ipn.txt from simulator, 这是我从模拟器保存到ipn.txt中的响应,

VERIFIED----cmd=_notify-validate&residence_country=US&invoice=abc1234&address_city=San+Jose&first_name=John&payer_id=TESTBUYERID01&shipping=3.04&mc_fee=0.44&txn_id=332239535&receiver_email=seller%40paypalsandbox.com&quantity=1&custom=xyz123&payment_date=17%3A48%3A59+9+Feb+2015+PST&address_country_code=US&address_zip=95131&tax=2.02&item_name=something&address_name=John+Smith&last_name=Smith&receiver_id=seller%40paypalsandbox.com&item_number=AK-1234&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31Aryx.id7DMD.5oDzhJYQOgjfGK2z&address_country=United+States&payment_status=Completed&address_status=confirmed&business=seller%40paypalsandbox.com&payer_email=buyer%40paypalsandbox.com&notify_version=2.1&txn_type=web_accept&test_ipn=1&payer_status=verified&mc_currency=USD&mc_gross=12.34&address_state=CA&mc_gross1=9.34&payment_type=instant&address_street=123%2C+any+street

And finally this response text by pressing button and after making payment through paypal sandbox account. 最后,通过按按钮并通过Paypal沙箱帐户付款后,此响应文本将生效。

INVALID----cmd=_notify-validate&mc_gross=12.99&protection_eligibility=Eligible&address_status=unconfirmed&payer_id=K95EGBDGNUN8S&tax=0.00&address_street=Flat+no.+507+Wing+A+Raheja+Residency%0AFilm+City+Road%2C+Goregaon+East&payment_date=17%3A53%3A25+Feb+09%2C+2015+PST&payment_status=Completed&charset=UTF-8&address_zip=400097&first_name=Test&mc_fee=0.81&address_country_code=IN&address_name=Test+Buyer&notify_version=3.8&custom=46&payer_status=verified&business=xxx-facilitator%40gmail.com&address_country=India&address_city=Mumbai&quantity=1&verify_sign=AlLjZyUxzvtq5pK4-AOSkTM98NV-AIiAPCkBL.N4R.UZINnl-aty.OZT&payer_email=xxx-buyer%40gmail.com&txn_id=4LG750650N267953C&payment_type=instant&last_name=Buyer&address_state=Maharashtra&receiver_email=xxx-facilitator%40gmail.com&payment_fee=0.81&receiver_id=HYW9VPL8HWUYA&txn_type=web_accept&item_name=Teddy+Bear&mc_currency=USD&item_number=&residence_country=IN&test_ipn=1&handling_amount=0.00&transaction_subject=46&payment_gross=12.99&shipping=0.00&ipn_track_id=a7a2c1d3e08a2

What I have done so far, 我到目前为止所做的

Made sure that i'm only working with sandbox and not with live things with paypal 确保我只使用沙箱,而不使用Paypal处理活物

Changed charset of both accounts (buyer and seller at sandbox) 更改了两个帐户的字符集(沙盒中的买方和卖方)

Changed listener code multiple times, but got same result 多次更改侦听器代码,但结果相同

searched stackoverflow and other sites with google with no luck. 没有运气,用Google搜索了stackoverflow和其他网站。

already have looked these ones, 已经看过这些了,

Paypal SandBox IPN always returns INVALID Paypal SandBox IPN始终返回INVALID

PayPal IPN returning INVALID PayPal IPN返回无效

I'm pretty sure it was just problem with order of post data. 我很确定这只是发布数据顺序的问题。

Used code from https://github.com/orderly/codeigniter-paypal-ipn and it works like charm! 来自https://github.com/orderly/codeigniter-paypal-ipn的使用代码,它就像魅力一样工作!

Hope this answer will help someone and will save time. 希望这个答案可以帮助某人并节省时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM