我正在尝试在PayPal Java SDK中找到一个API调用,以从PayPal服务中提取退款详细信息。我有交易明细和退款ID,但找不到任何API调用来获取退款的实际详细信息。 在PayPal开发人员的网站上,我仅看到curl命令,但没有看到该操作的SDK示例。我想念什么吗?
答案 0 :(得分:3)
您可以使用任何Http库中的documentation中指定的GET /v2/payments/refunds/{refund_id}
PayPal API获取退款详细信息。
或者,如果您要专门使用PayPal的Java SDK本身,则可以使用source中存在的RefundsGetRequest
对象(Checkout-Java-SDK),如下所示:
// 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
}
}
上面显示的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
}
Maven存储库中checkout-sdk的链接为here