Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java PayPal IPN在live上返回无效,并在sandbox上验证_Java_Paypal_Paypal Sandbox_Paypal Ipn - Fatal编程技术网

Java PayPal IPN在live上返回无效,并在sandbox上验证

Java PayPal IPN在live上返回无效,并在sandbox上验证,java,paypal,paypal-sandbox,paypal-ipn,Java,Paypal,Paypal Sandbox,Paypal Ipn,我一直在尝试在我们公司的网站上实现paypal IPN系统。当我在IPN沙盒工具中测试我的脚本时,它是经过验证的,一切都进行得很顺利,但是当我移动它时,IPN返回为无效,但支付已经完成。 当我检查我的帐户中的IPN历史记录时,我可以看到带有HTTP响应200的IPN消息: mc\u毛额=0.01&发票=40&保护\u资格=不合格&项目编号1=&付款人\u id=mypayerId&tax=0.00&付款日期=03年9月8:06:52,2013PDT&payment\u status=Comple

我一直在尝试在我们公司的网站上实现paypal IPN系统。当我在IPN沙盒工具中测试我的脚本时,它是经过验证的,一切都进行得很顺利,但是当我移动它时,IPN返回为无效,但支付已经完成。 当我检查我的帐户中的IPN历史记录时,我可以看到带有HTTP响应200的IPN消息:

mc\u毛额=0.01&发票=40&保护\u资格=不合格&项目编号1=&付款人\u id=mypayerId&tax=0.00&付款日期=03年9月8:06:52,2013PDT&payment\u status=Completed&charset=windows-1252&mc\u shipping=0.00&mc\u handling=0.00&first\u name=myName&mc\u fee=0.01¬ify\u version=3.7&custom=18528&payer\u status=verified&business=business\u mail&num\u cart\u items=1&mc\u handling1=0.00&Verifix\u sign=AJ.HL1F2A9OBIQCLN.3J QkKQGAF.W8ER5RBGJ6SSQFURTD&WBU=0.00=6105238B4613440H&payment\u type=instant&last\u name=MyUrName&item\u name1=Paquete Lite&receiver\u email=MyBusiness\u mail&payment\u fee=&quantity1=1&receiver\u id=SVRxVCZYEE2AYC&txn\u type=cart&mc\u gross\u 1=0.01&mc\u currency=EUR&residence\u country\u country\e=ES&transaction\u subject=18528&payment\u gross=ipn\u track\id=38c492cbe6257

  • Paypal live凭证还可以
  • URL正常()
我的IPNHandler是一个Javaservlet。doPost操作是:

 @Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // Java JSP
    log.error("IPN doPost " + new Date().getHours() + ":" + new Date().getMinutes() + ":" + new Date().getSeconds());

    // read post from PayPal system and add 'cmd'
    Enumeration en = request.getParameterNames();
    String str = "cmd=_notify-validate";
    while (en.hasMoreElements()) {
        String paramName = (String) en.nextElement();
        String paramValue = request.getParameter(paramName);
        paramValue = new String(paramValue.getBytes("iso-8859-1"), "utf-8");
        str = str + "&" + paramName + "=" + URLEncoder.encode(paramValue);
    }

    boolean isSandbox = "true".equals(PropertiesManager.getProperty("signbox", "PaypalSandbox"));
    // post back to PayPal system to validate
    // NOTE: change http: to https: in the following URL to verify using SSL (for increased security).
    // using HTTPS requires either Java 1.4 or greater, or Java Secure Socket Extension (JSSE)
    // and configured for older versions.
    String url = null;
    if (isSandbox){
        url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
    }else{
        url = "https://www.paypal.com/cgi-bin/webscr";
    }
    log.error("La url de a la que redirigimos a Paypal es " + url);
    URL u = new URL(url);
    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();
    log.error("Tras abrir la conexión, res es = " + res);

    // assign posted variables to local variables
    String idUser = request.getParameter("custom");
    String idCompra = request.getParameter("invoice");
    String paymentStatus = request.getParameter("payment_status");
    String paymentAmount = request.getParameter("mc_gross");
    String fee = request.getParameter("mc_fee");
    String paymentCurrency = request.getParameter("mc_currency");
    String txnId = request.getParameter("txn_id");
    String receiptId = request.getParameter("receipt_id");
    String receiverEmail = request.getParameter("receiver_email");
    String payerEmail = request.getParameter("payer_email");
    String paymentType = request.getParameter("payment_type");
    String txnType = request.getParameter("txn_type");

    if (!"instant".equals(paymentType) || !"cart".equals(txnType)) {
        log.debug("NO ES UN CART CHECKOUT. Detalles:");
        log.debug("idCompra=" + idCompra);
        log.debug("status=" + paymentStatus);
        log.debug("amount=" + paymentAmount);
        log.debug("currency=" + paymentCurrency);
        log.debug("transactionId=" + txnId);
        log.debug("receiptId=" + receiptId);
        log.debug("receiverEmail=" + receiverEmail);
        log.debug("payerEmail=" + payerEmail);
        log.debug("paymentType=" + paymentType);
        log.debug("txnType=" + txnType);

        return;
    }

    **//HERE THE RESPONSE IS INVALID IN LIVE MODE**
    if (res != null && res.equals("VERIFIED")) { //res = "VERIFIED" res = "INVALID"
        // more code not important for this issue....

有什么想法吗?正如我所说,付款已完成,但IPN发送无效。

我知道这是旧的,但它可能会帮助其他人,我认为您需要发布数据进行验证

根据:


要从PayPal接收IPN消息数据,您的侦听器必须遵循以下请求-响应流:

1.您的侦听器侦听PayPal随每个事件发送的HTTPS POST IPN消息

2.从PayPal接收IPN消息后,侦听器将向PayPal返回一个空的HTTP 200响应。否则,PayPal将重新发送IPN消息

3.您的侦听器使用HTTPS POST将完整消息发送回PayPal

使用cmd=\u notify-validate变量作为返回消息的前缀,但不要更改消息字段、字段顺序或原始消息的字符编码

将响应消息发送回PayPal:

  • (适用于沙箱IPN)
  • https:/ipnpb.paypal.com/cgi-bin/webscr(适用于实时IPN)
有关更多信息,请参见:

关闭沙盒:布尔值isSandbox=“false”。似乎是沙盒=已验证,live=无效的#1原因。简单的事情会把我们绊倒!
//After receiving an IPN message from PayPal, 
//you must respond to PayPal with a POST message 
//that begins with "cmd=_notify-validate".
//Append to your message a duplicate of the 
//notification received (the same IPN fields 
//and values in the exact order you received them)

...
URL u = new URL(url);
HttpURLConnection uc = (HttpURLConnection) u.openConnection();
uc.setRequestMethod("POST");
...