Paypal移动快递结账用java

时间:2012-06-12 04:13:18

标签: paypal

我开发了一个需要与paypal集成的移动应用程序,我的后端服务器是RESTfull java服务器。因此,为了与paypal集成,我获得了" deviceReferenceTokenWithAppId"从客户端调用后端服务器上的servlet以及其他详细信息(cartId..etc),当请求来到servlet时,我做一些后端操作并调用paypal来获取特定的" SetExpressCheckout"移动支付所需的令牌。

StringBuilder postData = new StringBuilder();
        postData.append(USER).append("=").append(Constants.PAYPAL_MERCHANT_USER);
        postData.append("&").append(PASSWORD).append("=").append(Constants.PAYPAL_MERCHANT_PASSWORD);
        postData.append("&").append(SIGNATURE).append("=").append(Constants.PAYPAL_MERCHANT_SIGNATURE);
        postData.append("&").append(METHOD).append("=").append("SetExpressCheckout");
        postData.append("&").append(VERSION).append("=").append("88");
        postData.append("&").append(AMOUNT).append("=").append(amount.toString());
        postData.append("&").append(CANCEL_URL).append("=").append(Constants.PAYPAL_MERCHANT_CANCEL_URL);
        postData.append("&").append(RETURN_URL).append("=").append(Constants.PAYPAL_MERCHANT_RETURN_URL);
        byte[] postDataArr = postData.toString().getBytes(UTF-8);
        // Hit the the URL.

        URL url = new URL("https://api-3t.sandbox.paypal.com/nvp");
        HttpsURLConnection.setDefaultHostnameVerifier(new CustomizedHostnameVerifier());
        HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setUseCaches(false);
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
        conn.setRequestProperty("Content-Length", Integer.toString(postDataArr.length));


        DataOutputStream output = new DataOutputStream( conn.getOutputStream());
        output.write( postDataArr );
        output.flush();
        output.close ();

        rc = conn.getResponseCode();

我的问题是,如果我调用paypal nvp,我没有获得有效的令牌作为响应,而是我得到以下错误,

Key - TIMESTAMP - value : 2012-06-11T18:16:02Z
 Key - CORRELATIONID - value : 207108cab758a
 Key - ACK - value : Failure
 Key - VERSION - value : 88
 Key - BUILD - value : 2975009
 Key - L_ERRORCODE0 - value : 10002
 Key - L_SHORTMESSAGE0 - value : Security error
 Key - L_LONGMESSAGE0 - value : Security header is not valid
 Key - L_SEVERITYCODE0 - value : Error

有人可以告诉我为什么会出现这个错误?我错过了什么吗?

如果我能成功获得TOKEN,接下来我必须将我的servlet响应重定向到以下Url,以便将移动结帐视图移至移动应用程序。

https://www.sandbox.paypal.com/webscr?cmd=_express-checkout-mobile&drt="+<deviceReferenceTokenWithAppId>+"&token="+<TOKEN from payal nvp>

感谢如果我在这里犯了错误,有人可以引导我走上正确的道路..

1 个答案:

答案 0 :(得分:0)

这表示您正在访问的端点的API凭据不正确 尝试用“PWD”代替“PASSWORD”;使用PayPal进行身份验证,使用'USER','PWD'和'SIGNATURE'。