【问题标题】:Paypal IPN Simulator always returns INVALID despite postback being correct尽管回发正确,Paypal IPN Simulator 始终返回 INVALID
【发布时间】:2016-09-20 01:49:09
【问题描述】:

我们正在升级我们的 IPN 以使用 TLS,并且在使用 IPN 模拟器时不断收到 INVALID 回复

就在请求进入侦听器时,它被记录下来。就在数据返回贝宝之前,URL 和数据被记录下来。此信息如下。

数据似乎没有问题。我什至使用 diffmerge 来确定除了 cmd=_notify-validate& 之外没有任何区别

只是IPN Simulator 永远不会返回有效吗?


请求前的 URL 是:

https://www.sandbox.paypal.com/cgi-bin/webscr

发布的数据是

cmd=_notify-validate&payment_type=instant&payment_date=Mon May 23 2016 17:41:16 GMT 1000 (E. Australia Standard Time)&payment_status=Completed&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&payer_email=jimmyred99@gmail.com&payer_id=TESTBUYERID01&address_name=John Smith&address_country=United States&address_country_code=US&address_zip=95131&address_state=CA&address_city=San Jose&address_street=123 any street&business=seller@paypalsandbox.com&receiver_email=paypaltest@akturatech.com&receiver_id=paypaltest@akturatech.com&residence_country=US&item_name=something&item_number=CHIMPREWRITER-LIFE&quantity=1&shipping=3.04&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=139&mc_gross_1=139&txn_type=web_accept&txn_id=928133899&notify_version=2.1&custom=xyz123&invoice=abc1234&test_ipn=1&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AU-9VToMcj-IcSKMfmb8nz2kgIe.

Paypal 的数据是

payment_type=instant&payment_date=Mon May 23 2016 17:41:16 GMT 1000 (E. Australia Standard Time)&payment_status=Completed&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&payer_email=jimmyred99@gmail.com&payer_id=TESTBUYERID01&address_name=John Smith&address_country=United States&address_country_code=US&address_zip=95131&address_state=CA&address_city=San Jose&address_street=123 any street&business=seller@paypalsandbox.com&receiver_email=paypaltest@akturatech.com&receiver_id=paypaltest@akturatech.com&residence_country=US&item_name=something&item_number=CHIMPREWRITER-LIFE&quantity=1&shipping=3.04&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=139&mc_gross_1=139&txn_type=web_accept&txn_id=928133899&notify_version=2.1&custom=xyz123&invoice=abc1234&test_ipn=1&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AU-9VToMcj-IcSKMfmb8nz2kgIe.

供参考,代码为:

// This was legacy code I was trying in case there were formatting problems. The code "cmd=_notify-validate&" + _request.Form; does some URL encoding which I thought might be causing problems. Either way, we still get INVALID
string s = "cmd=_notify-validate";
foreach (string paramName in _request.Form)
{
    string paramValue = LicServiceTools.Encode(_request.Form[paramName]);
    //s = s + string.Format("&{0}={1}", paramName, paramValue);
    s = s + string.Format("&{0}={1}", paramName, _request.Form[paramName]);
}

string address = "https://www.paypal.com/cgi-bin/webscr";
if (this.useSandBox)
{
    address = "https://www.sandbox.paypal.com/cgi-bin/webscr";
}
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(address);
req.ProtocolVersion = HttpVersion.Version11;
//Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";

// ALSO DOESNT WORK
//string strRequest = "cmd=_notify-validate&" + _request.Form;
//req.ContentLength = strRequest.Length;

errorLogger.Info(s);
errorLogger.Info(address);

//Send the request to PayPal and get the response
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(s);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();

// at this point, strResponse = INVALID

【问题讨论】:

    标签: c# asp.net paypal


    【解决方案1】:

    原来新的 IPN 模拟器 payment_date 搞砸了,因为时区中的“+”。似乎没有一个实时通知会像这样列出时区,所以之前的代码可以正常工作。

    这个帖子拯救了一天:https://github.com/paypal/ipn-code-samples/issues/51

    【讨论】:

    • 感谢您为我解决了这个绝对是 HIV 阳性的问题。浪费了几个小时,直到我终于找到了你的帖子。传奇!!!
    • 别担心亚伦 :)
    • 非常感谢您分享此信息,詹姆斯。我已经花了 2 天时间修改了很多代码,以为是我的代码坏了。再次感谢。
    猜你喜欢
    • 2015-08-14
    • 2016-03-12
    • 2016-10-10
    • 2012-07-29
    • 1970-01-01
    • 2019-02-20
    • 2017-04-24
    • 2013-09-06
    • 2016-11-28
    相关资源
    最近更新 更多