查询支付状态
这里只讲查询支付状态的,获得 token 什么的比较简单,这里就不讲解了。
这里是根据按钮进行对接的,也就是这篇
根据回调参数 txn_id 查询支付状态
官网有Show captured payment details
postman
只需要带个 token 就行了
代码如下
public static ServiceResult<String> getPaypalPaymentResult(String txnId) {
if (StringUtils.isBlank(txnId)) {
return ServiceResult.asFail("The transaction number does not exist!");
}
LogUtils.PAYPAL_LOG.info("get Paypal Payment Result txnId:" + txnId);
Request request = new Request.Builder()
.url(GET_PAYPAL_PAYMENT_STATUS_URL + txnId)
.get()
.addHeader("Authorization", "Bearer " + getPaypalToken())
.addHeader("Content-Type", "application/json")
.build();
String responseStr = "";
try {
responseStr = paypalClient.newCall(request).execute().body().string();
LogUtils.PAYPAL_LOG.info("get Paypal Payment Status request:" + request.toString() + " response String:" + responseStr);
return ServiceResult.asSuccess(responseStr, "response");
} catch (Exception e) {
LogUtils.ERROR_LOGGER.error("get Paypal Payment Status request send failed request :" + request.toString());
}
return ServiceResult.asFail("get Paypal Payment Status failed!");
}
根据按钮 sdk 返回的 orderID 查询订单信息
官网有Show order details
postman
如果不知道OrderID在哪里获取,请点这里
代码如下:
public static ServiceResult<PaypalOrderModel> getPaypalOrderDetails(String orderId) {
if (StringUtils.isBlank(orderId)) {
return ServiceResult.asFail("orderId is required!");
}
LogUtils.PAYPAL_LOG.info("get Paypal order Details orderId:" + orderId);
Request request = new Request.Builder()
.url(GET_PAYPAL_ORDER_STATUS_URL + orderId)
.get()
.addHeader("Authorization", "Bearer " + getPaypalToken())
.addHeader("Content-Type", "application/json")
.build();
ServiceResult result = ServiceResult.asFail("");
try {
String responseStr = paypalClient.newCall(request).execute().body().string();
LogUtils.PAYPAL_LOG.info("get Paypal order Details request:" + request.toString() + " response String:" + responseStr);
result.success = PaypalOrderStatus.isPaymentSuccess(responseStr);
PaypalOrderModel paypalOrderModel = jsonConvertOrderModel(responseStr);
result.obj = paypalOrderModel;
} catch (Exception e) {
LogUtils.ERROR_LOGGER.error("get Paypal order Details request send failed request :" + request.toString() + ", order Details transfer PaypalOrderModel failed!");
}
return result;
}