使用java的Paypal mobile express结账

使用java的Paypal mobile express结账,paypal,Paypal,我开发了一个需要与paypal集成的移动应用程序,我的后端服务器是RESTfull java server。因此,为了与paypal集成,我从客户端获取deviceReferenceTokenWithAppId,并在后端服务器调用servlet以及其他详细信息cartId。等等,当请求到达servlet时,我会执行一些后端操作并调用paypal以获取移动支付所需的特定SetExpressCheckout令牌 StringBuilder postData = new StringBuilder()

我开发了一个需要与paypal集成的移动应用程序,我的后端服务器是RESTfull java server。因此,为了与paypal集成,我从客户端获取deviceReferenceTokenWithAppId,并在后端服务器调用servlet以及其他详细信息cartId。等等,当请求到达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
有人能告诉我为什么我会犯这个错误吗?我错过什么了吗

如果我能成功地获得令牌,接下来我必须将servlet响应重定向到以下Url,以将移动签出视图转到移动应用程序

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

如果我在这里犯了错误,如果有人能指导我找到正确的路径,我将不胜感激。

这意味着您访问的端点的API凭据不正确。
尝试用PWD替换密码;通过PayPal的“用户”、“PWD”和“签名”进行身份验证。

谢谢。我发现了错误,我输入了paypal商户账号,而不是用户id。但是我仍然存在一个问题,即它没有在paypal视图中显示要收费的金额,我尝试将版本88.0的“PAYMENTREQUEST\u 0\u AMT”和版本62.0的“AMT”设置为金额2位小数。但是它没有在paypal窗口中显示用户需要支付的金额。这是一个单独的问题,您最初没有提到。不管怎样,都要解决这个问题;append useraction=commit到您的PayPal重定向URL,以便它读取