When use PayPal Rest API , i get AUTHENTICATION_FAILURE from response.
woniu
New Community Member
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on
Jan-30-2019
02:59 AM
This is my code :
String scope = "https://api.paypal.com/v1/payments/.* https://uri.paypal.com/services/payments/refund https://uri.paypal.com/services/applications/webhooks https://uri.paypal.com/services/payments/payment/authcapture https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.* https://uri.paypal.com/services/reporting/search/read https://uri.paypal.com/services/disputes/read-seller https://uri.paypal.com/services/disputes/read-buyer https://api.paypal.com/v1/vault/credit-card openid https://uri.paypal.com/services/disputes/update-seller https://uri.paypal.com/services/payments/realtimepayment"; Tokeninfo tokeninfo = new Tokeninfo(); String pClientID = "xxx"; String pClientSecret = "xxx"; CreateFromRefreshTokenParameters param = new CreateFromRefreshTokenParameters(); param.setClientID(pClientID); param.setClientSecret(pClientSecret); tokeninfo.setRefreshToken("xxxx"); tokeninfo.setTokenType("Bearer"); tokeninfo.setScope(scope); APIContext apiContext = new APIContext(); apiContext.setMode("live"); try { Tokeninfo token = tokeninfo.createFromRefreshToken(apiContext,param); LOG.info(token.getAccessToken()); } catch (PayPalRESTException e) { e.printStackTrace(); }
Then , i get accessToken and use it call RufundAPI , code :
Amount amount = new Amount(); amount.setTotal(totalAmount); amount.setCurrency(currencyCode.toString()); RefundRequest refundRequest = new RefundRequest(); refundRequest.setAmount(amount); DetailedRefund detailedRefund = null; boolean isHaveException = false; String exceptionMsg = null; try{ APIContext apiContext = new APIContext(accessToken); apiContext.setMode("live"); Sale sale = new Sale(); sale.setId(transactionId); detailedRefund = sale.refund(apiContext,refundRequest); } catch (PayPalRESTException e){ isHaveException = true; exceptionMsg = e.getMessage(); LOG.error(exceptionMsg); } PayPalRefundResponse refundResponse = new PayPalRefundResponse(); if (isHaveException){ refundResponse.setStatus(ERROR); refundResponse.setMessage(exceptionMsg); }else{ if (detailedRefund == null){ refundResponse.setStatus(ERROR); refundResponse.setMessage("detailedRefund == null"); return refundResponse; } if ("failed".equalsIgnoreCase(detailedRefund.getState())){ refundResponse.setStatus(ERROR); refundResponse.setMessage("refund failed"); return refundResponse; } if ("pending".equalsIgnoreCase(detailedRefund.getState())){ refundResponse.setStatus(ERROR); refundResponse.setMessage("refund pending"); refundResponse.setRefundTransactionID(detailedRefund.getId()); return refundResponse; } if ("completed".equalsIgnoreCase(detailedRefund.getState())){ refundResponse.setStatus(SUCCESS); refundResponse.setRefundTransactionID(detailedRefund.getId()); refundResponse.setCurrency(detailedRefund.getAmount().getCurrency()); refundResponse.setAmount(detailedRefund.getAmount().getTotal()); refundResponse.setRefundFromTransactionFee(detailedRefund.getRefundFromTransactionFee().getValue()); refundResponse.setRefundFromReceivedAmount(detailedRefund.getRefundFromReceivedAmount().getValue()); refundResponse.setTotalRefundedAmount(detailedRefund.getTotalRefundedAmount().getValue()); return refundResponse; } }
I get error message
Response code: 401 Error response: {"name":"AUTHENTICATION_FAILURE","message":"Authentication failed due to invalid authentication credentials or a missing Authorization header.","links":[{"href":"https://developer.paypal.com/docs/api/overview/#error","rel":"information_link"}]}
Why?
Could someone help me?
1 REPLY 1
woniu
New Community Member
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jan-30-2019
03:09 AM
Should i do like this :
String scope = "https://api.paypal.com/v1/payments/.* https://uri.paypal.com/services/payments/refund https://uri.paypal.com/services/applications/webhooks https://uri.paypal.com/services/payments/payment/authcapture https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.* https://uri.paypal.com/services/reporting/search/read https://uri.paypal.com/services/disputes/read-seller https://uri.paypal.com/services/disputes/read-buyer https://api.paypal.com/v1/vault/credit-card openid https://uri.paypal.com/services/disputes/update-seller https://uri.paypal.com/services/payments/realtimepayment";
APIContext apiContext = new APIContext(pClientID,pClientSecret,"live");
Tokeninfo tokeninfo = Tokeninfo.createFromAuthorizationCode(apiContext,authorizationCode);
tokeninfo.setTokenType("Bearer");
tokeninfo.setScope(scope);
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
Related Content
- SetExpressCheckout 10003 error with ITEMCATEGORY=Digital in NVP/SOAP APIs
- Issue with Empty store_info in Response Using /v1/reporting/transactions on Sandbox API in REST APIs
- Add Others data in SDKs
- IPN works in sandbox but not live in Sandbox Environment
- Connecting with site to take payments in Payflow