交易撤销重构

This commit is contained in:
2023-08-26 18:38:00 +08:00
parent 7529dd80b2
commit da47be42f9
3 changed files with 95 additions and 12 deletions

View File

@@ -9,6 +9,7 @@ import com.google.common.collect.Maps;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import com.jsowell.adapay.dto.QueryPaymentConfirmDTO;
import com.jsowell.adapay.operation.PaymentConfirmOperation;
import com.jsowell.adapay.operation.PaymentReverseOperation;
import com.jsowell.adapay.response.PaymentConfirmResponse;
import com.jsowell.adapay.response.PaymentReverseResponse;
import com.jsowell.adapay.response.QueryPaymentConfirmDetailResponse;
@@ -785,7 +786,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
/**
* 不延迟商家订单处理逻辑
* 例如:希晓
*
* 相当于已经分账完成了
* @param orderBasicInfo 订单信息
* @param adapayMemberAccount 汇付用户信息
* @param wechatAppId 小程序appId
@@ -1234,6 +1235,9 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
BigDecimal deductionAmount = vo.getDeductionAmount();
// 延时分账使用确认交易API
// PaymentConfirmResponse paymentConfirmResponse = adapayService.createPaymentConfirmRequest(paymentId, adapayMemberAccount, deductionAmount, orderCode, wechatAppId);
// 换新的方法,逻辑不变,参数封装了
PaymentConfirmOperation operation = new PaymentConfirmOperation();
operation.setPaymentId(paymentId);
operation.setConfirmAmt(deductionAmount);
@@ -1242,7 +1246,6 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
operation.setMerchantKey(wechatAppId);
PaymentConfirmResponse paymentConfirmResponse = adapayService.createPaymentConfirmRequest(operation);
// PaymentConfirmResponse paymentConfirmResponse = adapayService.createPaymentConfirmRequest(paymentId, adapayMemberAccount, deductionAmount, orderCode, wechatAppId);
if (paymentConfirmResponse != null && paymentConfirmResponse.isNotFailed()) {
confirmAmt = confirmAmt.add(new BigDecimal(paymentConfirmResponse.getConfirm_amt()));
feeAmt = feeAmt.add(new BigDecimal(paymentConfirmResponse.getFee_amt()));
@@ -2369,9 +2372,19 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
// String payMode = "delay";
if (StringUtils.equalsIgnoreCase(payMode, Constants.ADAPAY_PAY_MODE_DELAY)) {
// 延迟分账未确认调撤销调撤销接口退款
PaymentReverseResponse response = adapayService.createPaymentReverseRequest(
paymentId, refundAmount, dto.getWechatAppId(), dto.getMemberId(), ScenarioEnum.ORDER.getValue(),
dto.getOrderCode());
// PaymentReverseResponse response = adapayService.createPaymentReverseRequest(
// paymentId, refundAmount, dto.getWechatAppId(), dto.getMemberId(), ScenarioEnum.ORDER.getValue(),
// dto.getOrderCode());
PaymentReverseOperation operation = new PaymentReverseOperation();
operation.setPaymentId(paymentId);
operation.setReverseAmt(refundAmount);
operation.setMerchantKey(dto.getWechatAppId());
operation.setMemberId(dto.getMemberId());
operation.setScenarioType(ScenarioEnum.ORDER.getValue());
operation.setOrderCode(dto.getOrderCode());
PaymentReverseResponse response = adapayService.createPaymentReverseRequest(operation);
if (response != null && response.isNotFailed()) {
MemberAdapayRecord record = memberAdapayRecordService.selectByPaymentId(paymentId);
BigDecimal reverseAmt = new BigDecimal(response.getReverse_amt());
@@ -2470,8 +2483,16 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
BigDecimal deductionAmount = vo.getDeductionAmount();
// 调汇付的交易撤销接口
PaymentReverseResponse paymentReverseRequest = adapayService.createPaymentReverseRequest(paymentId, deductionAmount, dto.getWechatAppId(),
dto.getMemberId(), ScenarioEnum.BALANCE.getValue(), null);
// PaymentReverseResponse paymentReverseRequest = adapayService.createPaymentReverseRequest(paymentId, deductionAmount, dto.getWechatAppId(),
// dto.getMemberId(), ScenarioEnum.BALANCE.getValue(), null);
PaymentReverseOperation operation = new PaymentReverseOperation();
operation.setPaymentId(paymentId);
operation.setReverseAmt(deductionAmount);
operation.setMerchantKey(dto.getWechatAppId());
operation.setMemberId(dto.getMemberId());
operation.setScenarioType(ScenarioEnum.BALANCE.getValue());
PaymentReverseResponse paymentReverseRequest = adapayService.createPaymentReverseRequest(operation);
if (paymentReverseRequest != null && paymentReverseRequest.isNotFailed()) {
memberAdapayRecordService.updateRefundAmount(paymentId, deductionAmount);
@@ -2865,9 +2886,19 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
List<PaymentReverseResponse> paymentReverses = queryOrderAdapayRefund(orderBasicInfo);
if (CollectionUtils.isEmpty(paymentReverses)) {
// 如果没有退款过,重新执行一遍退款
PaymentReverseResponse response = adapayService.createPaymentReverseRequest(
paymentId, refundAmount, wechatAppId, memberId, ScenarioEnum.ORDER.getValue(),
orderCode);
// PaymentReverseResponse response = adapayService.createPaymentReverseRequest(
// paymentId, refundAmount, wechatAppId, memberId, ScenarioEnum.ORDER.getValue(),
// orderCode);
PaymentReverseOperation operation = new PaymentReverseOperation();
operation.setPaymentId(paymentId);
operation.setReverseAmt(refundAmount);
operation.setMerchantKey(wechatAppId);
operation.setMemberId(memberId);
operation.setScenarioType(ScenarioEnum.ORDER.getValue());
operation.setOrderCode(orderCode);
PaymentReverseResponse response = adapayService.createPaymentReverseRequest(operation);
logger.info("重试订单退款response:{}", JSON.toJSONString(response));
} else {
BigDecimal reversedAmt = BigDecimal.ZERO;