update校验未支付订单

This commit is contained in:
2023-11-03 16:43:33 +08:00
parent c3d3c9eb9b
commit 3fbb39474e
3 changed files with 58 additions and 7 deletions

View File

@@ -242,8 +242,9 @@ public class SpringBootTestController {
@Test
public void queryPaymentByOrderNoTest() {
String orderNo = "C44903356969";
String wechatAppId = "wxbb3e0d474569481d";
try {
List<AdaPayment> adaPayments = adapayService.queryPaymentByOrderNo(orderNo);
List<AdaPayment> adaPayments = adapayService.queryPaymentByOrderNo(orderNo, wechatAppId);
System.out.println(JSON.toJSONString(adaPayments));
} catch (BaseAdaPayException e) {
throw new RuntimeException(e);

View File

@@ -1106,7 +1106,12 @@ public class AdapayService {
public List<AdaPayment> queryPaymentList(String startTime, String endTime) throws BaseAdaPayException {
List<AdaPayment> resultList = Lists.newArrayList();
String wechatAppId = "wxbb3e0d474569481d";
String appId = "app_d0c80cb1-ffc8-48cb-a030-fe9bec823aaa";
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
String appId = config.getAdapayAppId();
long begin = DateUtils.dateStrToTimestamp(startTime); // 13位时间戳
long end = DateUtils.dateStrToTimestamp(endTime); // 13位时间戳
int pageNum = 0; // 页面容量,取值范围 1~20默认值为 10
@@ -1143,11 +1148,13 @@ public class AdapayService {
/**
* 查询支付列表
*/
public List<AdaPayment> queryPaymentByOrderNo(String orderNo) throws BaseAdaPayException {
public List<AdaPayment> queryPaymentByOrderNo(String orderNo, String wechatAppId) throws BaseAdaPayException {
List<AdaPayment> resultList = Lists.newArrayList();
String wechatAppId = "wxbb3e0d474569481d";
String appId = "app_d0c80cb1-ffc8-48cb-a030-fe9bec823aaa";
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
throw new BusinessException(ReturnCodeEnum.CODE_ADAPAY_CONFIG_IS_NULL_ERROR);
}
String appId = config.getAdapayAppId();
int pageNum = 0; // 页面容量,取值范围 1~20默认值为 10
int pageSize = 20; // 页面容量,取值范围 1~20默认值为 10

View File

@@ -6,6 +6,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import com.jsowell.adapay.common.AdaPayment;
import com.jsowell.adapay.dto.QueryPaymentConfirmDTO;
import com.jsowell.adapay.operation.PaymentReverseOperation;
import com.jsowell.adapay.response.PaymentConfirmResponse;
@@ -25,6 +26,7 @@ import com.jsowell.common.enums.AcquirerEnum;
import com.jsowell.common.enums.DelFlagEnum;
import com.jsowell.common.enums.MemberWalletEnum;
import com.jsowell.common.enums.adapay.AdapayStatusEnum;
import com.jsowell.common.enums.adapay.MerchantDelayModeEnum;
import com.jsowell.common.enums.ykc.*;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.DateUtils;
@@ -2014,12 +2016,53 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
this.cleanCacheByOrderCode(orderBasicInfo.getOrderCode(), orderBasicInfo.getTransactionCode());
// 通过订单号查询汇付有没有支付单
checkUnpaidOrder(orderBasicInfo);
}
}
return orderList.size();
}
/**
* 校验未支付订单
* 如果存在因为未收到支付回调导致超时关闭的订单,在修改订单状态后,检查一下是否支付过,把支付的金额退款
* @param orderBasicInfo
*/
private void checkUnpaidOrder(OrderBasicInfo orderBasicInfo) {
String orderCode = orderBasicInfo.getOrderCode();
List<AdaPayment> adaPayments = null;
String memberId = orderBasicInfo.getMemberId();
String merchantId = orderBasicInfo.getMerchantId();
String wechatAppId = pileMerchantInfoService.queryAppIdByMerchantId(merchantId);
String delayMode = pileMerchantInfoService.getDelayModeByWechatAppId(wechatAppId);
try {
adaPayments = adapayService.queryPaymentByOrderNo(orderCode, wechatAppId);
} catch (BaseAdaPayException e) {
throw new RuntimeException(e);
}
if (CollectionUtils.isEmpty(adaPayments)) {
return;
}
// 退款
for (AdaPayment adaPayment : adaPayments) {
String status = adaPayment.getStatus();
if (!AdapayStatusEnum.SUCCEEDED.getValue().equals(status)) {
// 不是交易完成状态,就跳过
continue;
}
String paymentId = adaPayment.getId();
BigDecimal payAmt = new BigDecimal(adaPayment.getPay_amt());
if (MerchantDelayModeEnum.DELAY.getMode().equals(delayMode)) {
// 延时分账商户,创建交易撤销请求
adapayService.createPaymentReverseRequest(paymentId, payAmt, wechatAppId, memberId, ScenarioEnum.ORDER.getValue(), orderCode);
} else {
// 实时分账商户,创建交易退款请求
adapayService.createRefundRequest(paymentId, payAmt, wechatAppId, memberId, ScenarioEnum.ORDER.getValue(), orderCode);
}
}
}
/**
* 微信支付-订单退款处理逻辑
*/