gpt4 book ai didi

java - Paypal REST API 403 错误

转载 作者:太空宇宙 更新时间:2023-11-03 16:31:01 26 4
gpt4 key购买 nike

我正在尝试将 Paypal 支付集成到我的 JavaEE 网络应用程序中。每次我尝试付款时,它都会抛出 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 command: 14:26:15,551 INFO [stdout] (http--0.0.0.0-8080-6) curl -v 'https://api.sandbox.paypal.com/v1/oauth2/token' \ 14:26:15,552 INFO [stdout] (http--0.0.0.0-8080-6) -H "Authorization: Basic QWJHQTFSQXVpeVA0RDVvQmt5d1o3dTBCanJJWkt0dm9CaVhTcDZ0QWFINlM4LXRFdzByX2hyRzNfbUZMOkVBRmhVQkJkZWRqTmJfTXV6SlNpbVI1YnY3SThQVzdwUldibGQ2aE9seThMZlNnRlhhbS1LaHJtRVZmZA==" \ 14:26:15,552 INFO [stdout] (http--0.0.0.0-8080-6) -H "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)" \ 14:26:15,553 INFO [stdout] (http--0.0.0.0-8080-6) -H "Accept: application/json" \ 14:26:15,553 INFO [stdout] (http--0.0.0.0-8080-6) -d 'grant_type=client_credentials' 14:26:16,878 INFO [stdout] (http--0.0.0.0-8080-6) curl command: 14:26:16,879 INFO [stdout] (http--0.0.0.0-8080-6) curl -v 'https://api.sandbox.paypal.com/v1/payments/payment' \ 14:26:16,879 INFO [stdout] (http--0.0.0.0-8080-6) -H "Authorization: Bearer A015iJYDQHdb7TJXzJzVIW-eSm1lP8NObGmlJkTzx2wVREo" \ 14:26:16,879 INFO [stdout] (http--0.0.0.0-8080-6) -H "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)" \ 14:26:16,880 INFO [stdout] (http--0.0.0.0-8080-6) -H "PayPal-Request-Id: 7b42030f-9b96-4027-9257-0c1311082fa2" \ 14:26:16,880 INFO [stdout] (http--0.0.0.0-8080-6) -H "Content-Type: application/json" \ 14:26:16,880 INFO [stdout] (http--0.0.0.0-8080-6) -d '{ 14:26:16,880 INFO [stdout] (http--0.0.0.0-8080-6) "intent": "sale", 14:26:16,880 INFO [stdout] (http--0.0.0.0-8080-6) "payer": { 14:26:16,881 INFO [stdout] (http--0.0.0.0-8080-6)
"payment_method": "paypal" 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) "transactions": [ 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) "amount": { 14:26:16,882 INFO [stdout] (http--0.0.0.0-8080-6) "currency": "EUR", 14:26:16,882 INFO [stdout] (http--0.0.0.0-8080-6) "total": "25" 14:26:16,882 INFO [stdout] (http--0.0.0.0-8080-6) }, 14:26:16,882 INFO [stdout] (http--0.0.0.0-8080-6) "description": "Creating Payment" 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) "redirect_urls": { 14:26:16,883 INFO [stdout] (http--0.0.0.0-8080-6) "return_url": "http://example.com/a-vos-cas-JSP/paypal-response.html", 14:26:16,883 INFO [stdout] (http--0.0.0.0-8080-6) "cancel_url": "http://example.com/a-vos-cas-JSP/paypal-cancel.html" 14:26:16,884 INFO [stdout] (http--0.0.0.0-8080-6) } 14:26:16,884 INFO [stdout] (http--0.0.0.0-8080-6) }' 14:26:17,909 Grave [class com.paypal.core.HttpConnection] (http--0.0.0.0-8080-6) Error code : 403 with response : {"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"} 14:26:17,911 ERROR [stderr] (http--0.0.0.0-8080-6) com.paypal.core.rest.PayPalRESTException: Error code : 403 with response : {"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"}

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

最佳答案

答案包含在这个响应中:

{"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 联系支持人员。他们可以帮助您正确配置帐户。

关于java - Paypal REST API 403 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23845108/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com