Paypal 沙盒 IPN 返回 INVALID [英] Paypal sandbox IPN return INVALID
问题描述
我正在尝试使用 servlet 进行 IPN 回调.我使用的代码是由 paypal 提供的,用于验证 ipn 数据.但每次我收到无效回复.
I am trying IPN callback, using servlet. The code I am using is provided by paypal for verifying the ipn data. But every time i getting a INVALID response.
代码如下:
Enumeration en = req.getParameterNames();
String str = "cmd=_notify-validate";
while (en.hasMoreElements()) {
String paramName = (String) en.nextElement();
String paramValue = req.getParameter(paramName);
//str = str + "&" + paramName + "=" + URLEncoder.encode(paramValue,"UTF-8"); // for UTF-8 i set the encode format in my account as UTF-8
//str = str + "&" + paramName + "=" + URLEncoder.encode(paramValue,"ISO-8859-1");// for ISO-8859-1 i set the encode format in my account as ISO-8859-1
str = str + "&" + paramName + "=" + URLEncoder.encode(paramValue); //default as provided by paypal
}
URL u = new URL("http://www.sandbox.paypal.com/cgi-bin/webscr");
URLConnection uc = u.openConnection();
uc.setDoOutput(true);
uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
PrintWriter pw = new PrintWriter(uc.getOutputStream());
pw.println(str);
pw.close();
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
String res = in.readLine();
in.close();
if (res.equals("VERIFIED") || !res.equals("VERIFIED")) {
//Update database...
} else if (res.equals("INVALID")) {
//INVALID
}
我已经检查了 paypal 提供的所有三种可能性,以防 paypal 返回 INVALID 如下:
I have checked all three possibilities provided by paypal in case paypal return INVALID as follow:
1) 缺少参数 - 因为我发送了所有参数,所以没有缺少参数的问题
1) Missing Parameters - As I am send all the parameters no issue of missing parameters
2) 无效的 URL.- 我正在使用沙箱,所以 URL 是:http://www.sandbox.paypal.com/cgi-bin/webscr
2) Invalid URL. - I am using sandbox so URL is : http://www.sandbox.paypal.com/cgi-bin/webscr
3) 字符编码.- 尝试使用与paypal账户设置参数编码相同的字符编码.
3) Character encoding. - Tried with character encoding same as paypal account setting parameter encoding.
我使用以下参数发送回贝宝的请求:
the request I am sending back to paypal using following parameters:
cmd=_notify-validate&last_name=User&test_ipn=1&address_name=Test+User&txn_type=web_accept&receiver_email=sellr1_1252495907_biz%40gmail.com&residence_+country_pays&address_name=Test+User &txn_type=web_accept=01%3A55%3A04+Sep+26%2C+2009+PDT&address_zip=95131&payment_status=Completed&address_street=1+Main+St&first_name=Test&payer_email=buyer1_1251mail_4957&payer_email=buyer1_1251mail_4957= BXBKS22JQCUWL和放大器; verify_sign = AOMkeg7ofCL7FJfioyWA19uCxD4XAgZirsjiGh8cUy1fd2YAqBwOkkst和放大器; payment_type =即时和放大器;商业= sellr1_1252495907_biz%40gmail.com和放大器; address_country_code = US&放大器; mc_fee = 0.64安培; address_status =确认和放大器; transaction_subject =真+向上和数量= 1&安培; notify_version = 2.8安培; mc_currency = EUR&放;custom=&address_state=CA&payment_fee=&handling_amount=0.00&payer_status=verified&shipping=0.00&item_name=True+Up&tax=0.00&username=hannonj&charset=windows-1252&item_number=567&mc_gross=10.00&txn_id=7F456350BS7942738&receiver_id=MASSU6BSR9SC2&address_country=United+States
cmd=_notify-validate&last_name=User&test_ipn=1&address_name=Test+User&txn_type=web_accept&receiver_email=sellr1_1252495907_biz%40gmail.com&residence_country=US&address_city=San+Jose&payment_gross=&payment_date=01%3A55%3A04+Sep+26%2C+2009+PDT&address_zip=95131&payment_status=Completed&address_street=1+Main+St&first_name=Test&payer_email=buyer1_1252495751_per%40gmail.com&protection_eligibility=Eligible&payer_id=BXBKS22JQCUWL&verify_sign=AOMkeg7ofCL7FJfioyWA19uCxD4XAgZirsjiGh8cUy1fd2YAqBwOkkst&payment_type=instant&business=sellr1_1252495907_biz%40gmail.com&address_country_code=US&mc_fee=0.64&address_status=confirmed&transaction_subject=True+Up&quantity=1¬ify_version=2.8&mc_currency=EUR&custom=&address_state=CA&payment_fee=&handling_amount=0.00&payer_status=verified&shipping=0.00&item_name=True+Up&tax=0.00&username=hannonj&charset=windows-1252&item_number=567&mc_gross=10.00&txn_id=7F456350BS7942738&receiver_id=MASSU6BSR9SC2&address_country=United+States
请问,谁能指导我正确的方向?我没有得到代码或 URL 或其他任何东西的错误.我尝试了所有的可能性.请帮帮我.
Please , can any one direct me to proper direction? I am not getting what is wrong the code or the URL or anything else. I tried all the possibilities. Please help me.
推荐答案
谢谢大家的回复.哦,我终于解决了.
Thank you guys for your reply. ohhh I solved it at last.
实际上在通知 URL 中我还添加了一个用户名参数.Paypal 希望 IPN 的参数值与它返回到 servlet 相同.(您可以通过 req.getParameterNames() 获取它).因为我有额外的用户名参数,paypal 不知道.Paypal 返回 INVALID.
Actually in notify URL I also added a username parameter. Paypal want the parameter values for IPN same as it return to the servlet.(You can get it as req.getParameterNames()). As I have username parameter extra, which is not known to paypal. Paypal was returning INVALID.
这篇关于Paypal 沙盒 IPN 返回 INVALID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!