paypal - 回复 paypal 后仍然收到相同的 ipn 消息

标签 paypal paypal-ipn

根据 paypal ipn 文档,我需要在收到 ipn 消息后回复 paypal。问题是即使我从 paypal 服务器收到“已验证”后,我仍然收到相同的 ipn 消息。我做的有什么问题吗?我正在使用 responseBackIpnMessage 来回复 ipn 消息。而且我总是收到“已验证”。

 public void handlePaypalIpnMessage(HttpServletRequest request) {
            Map<String, String> configMap = new HashMap<String, String>();
            IPNMessage message = new IPNMessage(request, configMap);
            boolean isIpnVerified = responseBackIpnMessage(request);
            Map<String, String> map = message.getIpnMap();
            ......
        }

private boolean responseBackIpnMessage(HttpServletRequest request) {
    HttpClient httpClient = new DefaultHttpClient();  
    HttpParams clientParams = httpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(clientParams, 40000);
    HttpConnectionParams.setSoTimeout(clientParams, 40000);

    HttpPost httppost = new HttpPost(paypalIpnUrl); // https://www.paypal.com/cgi-bin/webscr
    httppost.setHeader("Content-Type", "application/x-www-form-urlencoded");

    try {
        Map<String, String> params = new HashMap<String, String>();
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("cmd", "_notify-validate"));
        Enumeration<String> names = request.getParameterNames();
        while (names.hasMoreElements()) {
            String param = names.nextElement();
            String value = request.getParameter(param);
            nameValuePairs.add(new BasicNameValuePair(param, value));
            params.put(param, value);
        }
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        if (!verifyIpnResponse(httpClient.execute(httppost))) {
            logger.error("Previous message is invalid according to paypal server.");
            return false;
        } else {
            logger.info("Previous message is verified by paypal server");
            return true;
        }
    } catch ( UnsupportedEncodingException e ) {            
        e.printStackTrace();
    } catch ( ClientProtocolException e ) {
        e.printStackTrace();
    } catch ( IOException e ) {
        e.printStackTrace();
    }
    return true;    
}

private boolean verifyIpnResponse(HttpResponse response) throws IllegalStateException, IOException {
    InputStream is = response.getEntity().getContent();
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    String responseText = reader.readLine();
    is.close();
    logger.debug("Paypal server ipn response: " + responseText);
    return responseText.equals("VERIFIED");
}

最佳答案

如果您收到重复的 IPN,这意味着您的脚本以某种方式失败并且没有向 PayPal 服务器返回 200 OK 响应。

验证过程确实与此无关。这只是验证数据来自 PayPal。它不会验证脚本是否已成功完成。

如果您在 how to test PayPal IPN 上按照本指南中的步骤操作你应该能够找到问题。

关于paypal - 回复 paypal 后仍然收到相同的 ipn 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31248702/

相关文章:

ruby-on-rails-3 - ActionController::TestCase 模拟 PayPal 购买

api - 如何启用 REST API 直接信用卡付款的实时凭证

google-apps-script - 使用 Google Apps 脚本管理 Paypal IPN

paypal - 付款后修改 PayPal Express Checkout 自定义参数

针对 PayPal 网站支付标准的移动优化结账

html - 网站支付标准 : How would I connect the order being sent and the IPN receiving it?

php - Paypal IPN 返回 HTTP/1.1 200 OK

php - 如何使用 php 自动取消订阅用户的 paypal(当他们升级到不同的订阅时)

php - Paypal IPN 状态 "autochange"?

ruby-on-rails - Express Payments rails 模块需要什么样的 PayPal 沙箱帐户?