Paypal REST API 403错误

时间:2014-05-24 12:37:08

标签: java api rest servlets paypal

我试图将paypal付款集成到我的JavaEE Web应用程序中。 每次我尝试付款时,都会产生403错误。

这是我使用的servlet:

@WebServlet(name="PaypalPayment", urlPatterns={"/paypal-payment.html"})
public class Paypal_Payment extends HttpServlet {
  private static final long serialVersionUID = 1L;
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    OAuthTokenCredential token;
    String accessToken;
    APIContext apiContext;

    Map<String, String> sdkConfig = new HashMap<String, String>();
    sdkConfig.put("mode", "sandbox");
    sdkConfig.put("service.EndPoint", "https://api.sandbox.paypal.com");
    sdkConfig.put("client_id", Constantes.PAYPAL_CLIENT_ID);
    sdkConfig.put("secret", Constantes.PAYPAL_CLIENT_SECRET);

    try{
      token = new OAuthTokenCredential(Constantes.PAYPAL_CLIENT_ID, Constantes.PAYPAL_CLIENT_SECRET, sdkConfig);
      accessToken = token.getAccessToken();
      apiContext = new APIContext(accessToken);
      apiContext.setConfigurationMap(sdkConfig);
      Amount amount = new Amount();
      amount.setCurrency("EUR");
      amount.setTotal("25");

      Transaction transaction = new Transaction();
      transaction.setDescription("Creating Payment");   
      transaction.setAmount(amount);
      List<Transaction> transactions = new ArrayList<Transaction>();
      transactions.add(transaction);
      Payer payer = new Payer();
      payer.setPaymentMethod("paypal");
      Payment payment = new Payment();
      payment.setIntent("sale");
      payment.setPayer(payer);
      payment.setTransactions(transactions);

      RedirectUrls redirectUrls = new RedirectUrls();
      redirectUrls.setCancelUrl("http://example.com/a-vos-cas-JSP/paypal-payment.html");
      redirectUrls.setReturnUrl("http://example.com/a-vos-cas-JSP/paypal-payment.html");

      payment.setRedirectUrls(redirectUrls);
      Payment createdPayment = payment.create(apiContext);
      System.out.println("createdPayment : " + createdPayment);
    }catch(PayPalRESTException e){
      e.printStackTrace();
    }
    getServletContext().getNamedDispatcher(Constantes.VUE_PAYPAL_RESPONSE).forward(request, response);
  }
}

这是控制台输出:

  

14:26:15,550 INFO [stdout](http - 0.0.0.0-8080-6)curl命令:   14:26:15,551 INFO [stdout](http - 0.0.0.0-8080-6)curl -v   &#39; https://api.sandbox.paypal.com/v1/oauth2/token&#39; \ 14:26:15,552 INFO   [stdout](http - 0.0.0.0-8080-6)-H&#34;授权:基本   QWJHQTFSQXVpeVA0RDVvQmt5d1o3dTBCanJJWkt0dm9CaVhTcDZ0QWFINlM4LXRFdzByX2hyRzNfbUZMOkVBRmhVQkJkZWRqTmJfTXV6SlNpbVI1YnY3SThQVzdwUldibGQ2aE9seThMZlNnRlhhbS1LaHJtRVZmZA ==&#34;   \ 14:26:15,552 INFO [stdout](http - 0.0.0.0-8080-6)-H&#34; User-Agent:   PayPalSDK / paypal-core-java 1.5.0   (lang = Java; v = 1.7.0_55; bit = 64; os = Mac_OS_X 10.9.2)&#34; \ 14:26:15,553 INFO   [stdout](http - 0.0.0.0-8080-6)-H&#34;接受:application / json&#34; \   14:26:15,553 INFO [stdout](http - 0.0.0.0-8080-6)-d   &#39; grant_type = client_credentials&#39; 14:26:16,878 INFO [stdout]   (http - 0.0.0.0-8080-6)curl命令:14:26:16,879 INFO [stdout]   (http - 0.0.0.0-8080-6)curl -v   &#39; https://api.sandbox.paypal.com/v1/payments/payment&#39; \ 14:26:16,879   INFO [stdout](http - 0.0.0.0-8080-6)-H&#34;授权:持票人   A015iJYDQHdb7TJXzJzVIW-eSm1lP8NObGmlJkTzx2wVREo&#34; \ 14:26:16,879 INFO   [stdout](http - 0.0.0.0-8080-6)-H&#34; User-Agent:   PayPalSDK / rest-sdk-java 0.9.0(lang = Java; v = 1.7.0_55; bit = 64; os = Mac_OS_X   10.9.2)&#34; \ 14:26:16,880 INFO [stdout](http - 0.0.0.0-8080-6)-H&#34; PayPal-Request-Id:7b42030f-9b96-4027-9257-0c1311082fa2&#34; \   14:26:16,880 INFO [stdout](http - 0.0.0.0-8080-6)-H&#34; Content-Type:   应用/ JSON&#34; \ 14:26:16,880 INFO [stdout](http - 0.0.0.0-8080-6)   -d&#39; {14:26:16,880 INFO [stdout](http - 0.0.0.0-8080-6)&#34; intent&#34;:&#34; sale&#34;,14:26: 16,880 INFO [stdout](http - 0.0.0.0-8080-6)&#34;付款人&#34;:   {14:26:16,881 INFO [stdout](http - 0.0.0.0-8080-6)
  &#34; payment_method&#34;:&#34; paypal&#34; 14:26:16,881 INFO [stdout]   (http - 0.0.0.0-8080-6)},14:26:16,881 INFO [stdout]   (http - 0.0.0.0-8080-6)&#34;交易&#34;:[14:26:16,881 INFO [stdout]   (http - 0.0.0.0-8080-6){14:26:16,881 INFO [stdout]   (http - 0.0.0.0-8080-6)&#34;金额&#34;:{14:26:16,882 INFO [stdout]   (http - 0.0.0.0-8080-6)&#34;货币&#34;:&#34; EUR&#34;,14:26:16,882 INFO   [stdout](http - 0.0.0.0-8080-6)&#34;总计&#34;:&#34; 25&#34; 14:26:16882   INFO [stdout](http - 0.0.0.0-8080-6)},14:26:16,882 INFO   [stdout](http - 0.0.0.0-8080-6)&#34;描述&#34;:&#34;创建   付款&#34; 14:26:16,882 INFO [stdout](http - 0.0.0.0-8080-6)}   14:26:16,883 INFO [stdout](http - 0.0.0.0-8080-6)],14:26:16,883   INFO [stdout](http - 0.0.0.0-8080-6)&#34; redirect_urls&#34;:{   14:26:16,883 INFO [stdout](http - 0.0.0.0-8080-6)&#34; return_url&#34;:   &#34; http://example.com/a-vos-cas-JSP/paypal-response.html&#34 ;,   14:26:16,883 INFO [stdout](http - 0.0.0.0-8080-6)&#34; cancel_url&#34;:   &#34; http://example.com/a-vos-cas-JSP/paypal-cancel.html&#34; 14:26:16884   INFO [stdout](http - 0.0.0.0-8080-6)} 14:26:16,884 INFO [stdout]   (http - 0.0.0.0-8080-6)}&#39; 14:26:17,909坟墓[等级   com.paypal.core.HttpConnection](http - 0.0.0.0-8080-6)错误代码:   403响应:{&#34; name&#34;:&#34; REQUIRED_SCOPE_MISSING&#34;,&#34; message&#34;:&#34; Access   令牌没有必要   范围&#34;&#34; information_link&#34;:&#34; https://developer.paypal.com/webapps/developer/docs/api/#REQUIRED_SCOPE_MISSING&#34;&#34; debug_id&#34;:&#34; e066fbac38f41&#34;}   14:26:17,911 ERROR [stderr](http - 0.0.0.0-8080-6)   com.paypal.core.rest.PayPalRESTException:错误代码:403 with   回复:{&#34;名称&#34;:&#34; REQUIRED_SCOPE_MISSING&#34;,&#34;消息&#34;:&#34;访问令牌   没有要求   范围&#34;&#34; information_link&#34;:&#34; https://developer.paypal.com/webapps/developer/docs/api/#REQUIRED_SCOPE_MISSING&#34;&#34; debug_id&#34;:&#34; e066fbac38f41&#34;}

所以,有一条消息说无法找到范围,但我无法获得有关此错误的任何信息。我想我在这个servlet中遗漏了一些东西,但是我无法找到它。任何帮助将不胜感激:D 非常感谢

1 个答案:

答案 0 :(得分:1)

答案包含在此回复中:

{"name":"REQUIRED_SCOPE_MISSING",
 "message":"Access token does not have required scope",
 "information_link":"https://developer.paypal.com/webapps/developer/docs/api/#REQUIRED_SCOPE_MISSING",
 "debug_id":"e066fbac38f41"}

您应用配置中的某些属性已丢失。您最好的选择是与列出的debug_id联系。它们可以帮助您正确配置帐户。