Reputation: 1988
I'm trying to find an API call in PayPal Java SDK to pull refund details from the PayPal service. I have a transaction details and Refund id, but I can't find any API calls to get actual details of the Refund. On PayPal developers' site I see only curl command, but not an SDK example for that operation. Am I missing something?
Upvotes: 1
Views: 520
Reputation: 15253
You can get the refund details using GET /v2/payments/refunds/{refund_id}
API of PayPal as specified in the documentation using any Http library.
Alternatively, if you want to exclusively use the PayPal's Java SDK itself, then you can use RefundsGetRequest
object (source) present in the Checkout-Java-SDK as below:
// Construct an environment with your client id and secret"
PayPalEnvironment environment = new PayPalEnvironment.Sandbox("xxxx","xxxx");
// Use this environment to construct a PayPalHttpClient
PayPalHttpClient client = new PayPalHttpClient(environment);
String refundId = "1234"; //set the refundId with the right value
String authorization = "xxxx" //The auth value would be Bearer <Access-Token> or Basic <client_id>:<secret>
// Construct a request object and set the desired parameters.
RefundsGetRequest request = new RefundsGetRequest(refundId)
.authorization(authorization);
try {
// Use your client to execute a request and get a response back
HttpResponse<Refund> refundResponse = client.execute(request);
// If the endpoint returns a body in its response, you can access the deserialized
// version by calling result() on the response.
Refund refundDetails = refundResponse.result();
} catch (IOException ioe) {
if (ioe instanceof HttpException) {
// Something went wrong server-side
HttpException he = (HttpException) ioe);
int statusCode = he.getStatusCode();
String debugId = he.getHeaders().header("PayPal-Debug-Id");
} else {
// Something went wrong client-side
}
}
The catch block shown above is inline with the SDK documentation's generic example, but ideally it would be better to handle it as below:
catch (HttpException ex) {
// Something went wrong server-side
int statusCode = ex.getStatusCode();
String debugId = ex.getHeaders().header("PayPal-Debug-Id");
} catch (Exception e) {
// Handle accordingly
}
Link of Maven repository for the checkout-sdk is here
Upvotes: 3