[英]How to get refund details by it's ID using PayPal Java SDK
I'm trying to find an API call in PayPal Java SDK to pull refund details from the PayPal service. 我正在尝试在PayPal Java SDK中找到API调用以从PayPal服务中提取退款详细信息。 I have a transaction details and Refund id, but I can't find any API calls to get actual details of the Refund.
我有一个交易详情和退款ID,但我找不到任何API调用来获取退款的实际细节。 On PayPal developers' site I see only curl command, but not an SDK example for that operation.
在PayPal开发人员的网站上,我只看到了curl命令,但没有看到该操作的SDK示例。 Am I missing something?
我错过了什么吗?
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. 您可以使用任何Http库在文档中指定的PayPal的
GET /v2/payments/refunds/{refund_id}
API获取退款详细信息。
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: 或者,如果您想独占使用PayPal的Java SDK本身,那么您可以使用Checkout-Java-SDK中存在的
RefundsGetRequest
对象( 源 ),如下所示:
// 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块与SDK文档的通用示例一致,但理想情况下最好如下处理它:
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 结帐-sdk的Maven存储库链接在这里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.