贝宝沙盒IPN返回无效 [英] Paypal sandbox IPN return INVALID
问题描述
我正在尝试使用servlet进行IPN回调.我使用的代码由paypal提供,用于验证ipn数据.但是每次我收到 INVALID 答复.
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
}
我已经检查了贝宝提供的所有三种可能性,以防贝宝返回无效,如下所示:
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. -我使用沙箱,因此网址为: 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 = US& s_amp; s&date; city&date; = = 01%3A55%3A04 + Sep + 26%2C + 2009 + PDT& address_zip = 95131& payment_status =已完成&address_street = 1 + Main + St& first_name = Test& payer_email = buyer1_1252495751_per%40gmail.com& E-payion_idligibility = 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& pay_fee =& handling_amount = 0.00& payer_status = verified& shipping = 0.00& item_name = True + Up& tax = 0.00&用户名= hannonj& charset = windows-125 2& item_number = 567& mc_gross = 10.00& txn_id = 7F456350BS7942738& receiver_id = MASSU6BSR9SC2& address_country =美国+州
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中,我还添加了一个username参数. Paypal希望IPN的参数值与返回到servlet相同(您可以通过req.getParameterNames()获得它).因为我有多余的用户名参数,贝宝不知道.贝宝(Paypal)返回无效".
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.
这篇关于贝宝沙盒IPN返回无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!