This commit is contained in:
Guoqs
2026-04-08 14:30:11 +08:00
parent da17b5151d
commit ab8930ea4c
2 changed files with 270 additions and 3 deletions

View File

@@ -1345,7 +1345,74 @@ public class AdapayService {
}
/**
* 查询支付退款对象
* 按汇付文档查询支付对象详情
* Payment.query(paymentId, merchantKey)
*/
public AdaPayment queryPaymentDetail(String paymentId, String wechatAppId) throws BaseAdaPayException {
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
Map<String, Object> response = Payment.query(paymentId, config.getWechatAppId());
if (response == null || response.isEmpty()) {
return null;
}
String resultPaymentId = (String) response.get("id");
String errorCode = (String) response.get("error_code");
if (!StringUtils.equals(paymentId, resultPaymentId) || StringUtils.isNotBlank(errorCode)) {
return null;
}
return JSON.parseObject(JSON.toJSONString(response), AdaPayment.class);
}
/**
* 按汇付文档通过 payment_id 查询支付对象列表
* 作为 Payment.query 的补充,用于查询 3 天前的交易
*/
public List<AdaPayment> queryPaymentListByPaymentId(String paymentId, String wechatAppId) throws BaseAdaPayException {
List<AdaPayment> resultList = Lists.newArrayList();
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
Map<String, Object> queryListParam = Maps.newHashMap();
queryListParam.put("app_id", config.getAdapayAppId());
queryListParam.put("payment_id", paymentId);
queryListParam.put("page_index", 1);
queryListParam.put("page_size", 1);
Map<String, Object> paymentListResult = Payment.queryList(queryListParam, config.getWechatAppId());
if (paymentListResult == null || paymentListResult.isEmpty()) {
return resultList;
}
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(paymentListResult));
List<AdaPayment> payments = jsonObject.getList("payments", AdaPayment.class, JSONReader.Feature.FieldBased);
if (CollectionUtils.isNotEmpty(payments)) {
resultList.addAll(payments);
}
return resultList;
}
/**
* 查询支付对象详情
* 先查 Payment.query未命中时再按 payment_id 查询列表
*/
public AdaPayment queryPaymentDetailWithFallback(String paymentId, String wechatAppId) throws BaseAdaPayException {
AdaPayment payment = queryPaymentDetail(paymentId, wechatAppId);
if (payment != null) {
return payment;
}
List<AdaPayment> payments = queryPaymentListByPaymentId(paymentId, wechatAppId);
if (CollectionUtils.isEmpty(payments)) {
return null;
}
return payments.get(0);
}
/**
* 按汇付文档通过 payment_id 查询退款对象
* Refund.query({payment_id}, merchantKey)
*/
public List<RefundInfo> queryPaymentRefund(String paymentId, String wechatAppId) throws BaseAdaPayException {
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
@@ -1354,7 +1421,6 @@ public class AdapayService {
}
Map<String, Object> refundParams = Maps.newHashMap();
refundParams.put("payment_id", paymentId);
refundParams.put("app_id", config.getAdapayAppId());
Map<String, Object> response = Refund.query(refundParams, config.getWechatAppId());
PaymentRefundResponse paymentRefundResponse = JSON.parseObject(JSON.toJSONString(response), PaymentRefundResponse.class);
List<RefundInfo> refunds = paymentRefundResponse.getRefunds();