Paypal & Java: Not Showing order summary and failure in acknowledgement

In my paypal JSP application , when redirect to paypal account(https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-50634332TM915520D) it doesn't show account summary(As in the image). At last at success page it shows failure also. ![enter image description here][1] [1]: http://i.stack.imgur.com/YgTD2.jpg . setcheckout.jsp is <% String url = "https://api-3t.sandbox.paypal.com/nvp"; String charset = "UTF-8"; String user = "cinewo_13895465_biz_api1.gmail.com"; String pwd = "1233310405"; String signature = "AbLJtIu5Xk-EeZNM1Qxyhl8A3UcjAXCXJk7gW24OlxsLXL3ORPJX5no3"; //Get the amount here String amount = "20"; String amt = request.getParameter("amount"); System.out.println("amt : "+amt); if ( amt != null) { amount = amt; // Setting amount to session session.setAttribute("amount", amount); } // Please give your ip address here not localhost // if dont no ip addrress just take google on your sys and search what is my ip it shows give it here String returnurl = "http://192.168.0.230:8084/Payment/sucess.jsp"; String cancelurl = "http://192.168.0.230:8084/Payment/canceled.jsp"; String query = "USER=" + user + "&PWD=" + pwd + "&SIGNATURE=" + signature + "&PAYMENTREQUEST_0_PAYMENTACTION=Sale&" + "PAYMENTREQUEST_0_AMT=" + amount + "&RETURNURL=" + returnurl + "&CANCELURL=" + cancelurl + "&METHOD=SetExpressCheckout" + "&VERSION=84.0"; URLConnection connection = new URL(url).openConnection(); connection.setDoOutput(true); // Triggers POST. connection.setRequestProperty("Accept-Charset", charset); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset); OutputStream output = null; try { output = connection.getOutputStream(); output.write(query.getBytes(charset)); } finally { if (output != null) { try { output.close(); } catch (IOException logOrIgnore) { System.out.println("logOrIgnore : " + logOrIgnore); } } } InputStream resp = connection.getInputStream(); // StringBufferInputStream buf = new StringBufferInputStream(s); InputStreamReader reader = new InputStreamReader(resp); // Read from the input stream. int charRead; String outp = ""; char tmp; while ((charRead = reader.read()) >= 0) { System.out.print((char) charRead); tmp = (char) charRead; outp += Character.toString(tmp); // out.print((char)charRead); } out.println("outp : " + outp); // Close the InputStreamReader and the // StringBufferInputStream objects. resp.close(); reader.close(); String decoded = URLDecoder.decode(outp, charset); //String n= URLEncoder.encode(outp, charset); String[] params = decoded.split("&"); String[] eachpair; HashMap hm = new HashMap(); for (int i = 0; i < params.length; i++) { eachpair = params[i].split("="); hm.put(eachpair[0], eachpair[1]); } String ack = "", token = "", version = "", tms = "", bld = "", corelid = ""; out.println("ACK : " + hm.get("ACK")); ack = hm.get("ACK"); if (ack.equals("Success")) { token = hm.get("TOKEN"); version = hm.get("VERSION"); tms = hm.get("TIMESTAMP"); bld = hm.get("BUILD"); corelid = hm.get("CORRELATIONID"); String logurl = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + token; response.sendRedirect(logurl); } System.out.println("resp :" + resp); // final String PAYPAL_URL = "https://api-3t.sandbox.paypal.com/nvp"; %>

Hello World!

and success.jsp is <% String user = "cinewo_13895465_biz_api1.gmail.com"; String pwd = "1325310405"; String signature = "AbLJtIu5Xk-EeZNM1Qxyhl8A3UcjAXCXJk7gW24OlxsLXL3ORPJX5no3"; String payerID = request.getParameter("PayerID"); String token = request.getParameter("token"); String amount = "25"; //Reading amount from session String amt = session.getAttribute("amount")+""; if(amt!=""){ amount=amt; } String version = request.getParameter("VERSION"); String build = request.getParameter("BUILD"); String charset = "UTF-8"; token = URLEncoder.encode(token, charset); payerID = URLEncoder.encode(payerID, charset); String query = "USER=" + user + "&PWD=" + pwd + "&SIGNATURE=" + signature + "&PAYMENTACTION=Sale&" + "PAYERID=" + payerID + "&TOKEN=" + token + "&AMT=" + amount + "&METHOD=DoExpressCheckoutPayment" + "&VERSION=84.0"; String url = "https://api-3t.sandbox.paypal.com/nvp"; URLConnection connection = new URL(url).openConnection(); connection.setDoOutput(true); // Triggers POST. connection.setRequestProperty("Accept-Charset", charset); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset); OutputStream output = null; try { output = connection.getOutputStream(); output.write(query.getBytes(charset)); } finally { if (output != null) { try { output.close(); } catch (IOException logOrIgnore) { System.out.println("logOrIgnore : " + logOrIgnore); } } } InputStream resp = connection.getInputStream(); InputStreamReader reader = new InputStreamReader(resp); // Read from the input stream. int charRead; String outp = ""; char tmp; while ((charRead = reader.read()) >= 0) { System.out.print((char) charRead); tmp = (char) charRead; outp += Character.toString(tmp); // out.print((char)charRead); } String decoded = URLDecoder.decode(outp, charset); //out.println("decoded : " + decoded); String[] params = decoded.split("&"); String[] eachpair; HashMap hm = new HashMap(); for (int i = 0; i < params.length; i++) { eachpair = params[i].split("="); hm.put(eachpair[0], eachpair[1]); } String ack = "", corelid = "", tms = "", bld = ""; out.println("ACK : " + hm.get("ACK")); ack = hm.get("ACK"); if (ack.equals("Success")) { token = hm.get("TOKEN"); version = hm.get("VERSION"); tms = hm.get("TIMESTAMP"); bld = hm.get("BUILD"); corelid = hm.get("CORRELATIONID"); out.println("token : " + token); out.println("version : " + version); out.println("tms : " + tms); out.println("bld : " + bld); out.println("corelid : " + corelid); } else { out.println("Sorry try again later"); } // Close the InputStreamReader and the // StringBufferInputStream objects. resp.close(); reader.close(); %>

Hello Sucess

以上就是Paypal & Java: Not Showing order summary and failure in acknowledgement的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏