Paypal IPN使用现在购买按钮返回INVALID但是使用IPN Simulator验证

时间:2015-02-10 02:04:07

标签: php paypal paypal-ipn

我遇到了PayPal IPN的问题,当我使用paypal立即购买按钮时它总是无效,但它与IPN模拟器完美配合。

我知道stackoverflow上有很多问题和答案可以帮助我,但我从这里和其他网站尝试过很多东西,但都没有。

以下是我正在使用的按钮代码,

<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>

这是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);
    }

这是我从模拟器保存到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

最后通过按下按钮并通过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

到目前为止我做了什么,

确保我只使用沙盒,而不是使用paypal生活的东西

更改了两个帐户的charset(沙箱中的买方和卖方)

多次更改了侦听器代码,但结果相同

使用谷歌搜索stackoverflow和其他网站但没有运气。

已经看过这些了,

Paypal SandBox IPN always returns INVALID

PayPal IPN returning INVALID

1 个答案:

答案 0 :(得分:0)

我很确定这只是发布数据顺序的问题。

来自https://github.com/orderly/codeigniter-paypal-ipn的已使用代码,它就像魅力一样!

希望这个答案对某人有所帮助并节省时间。