- fix: 修复退款时未检验退款金额问题,导致可以退款余额可以大于可退余额

This commit is contained in:
xxm1995
2024-02-26 16:06:02 +08:00
parent 2c7eff24ee
commit 8714b1feda
5 changed files with 36 additions and 17 deletions

View File

@@ -120,6 +120,7 @@ public class RefundAssistService {
List<String> tradesStatus = Arrays.asList(
PayStatusEnum.PROGRESS.getCode(),
PayStatusEnum.CLOSE.getCode(),
PayStatusEnum.REFUNDED.getCode(),
PayStatusEnum.REFUNDING.getCode(),
PayStatusEnum.FAIL.getCode());
if (tradesStatus.contains(payOrder.getStatus())) {
@@ -128,12 +129,14 @@ public class RefundAssistService {
}
// 过滤掉金额为空和0的退款参数
List<RefundChannelParam> channelParams = param.getRefundChannels()
.stream()
.filter(r -> Objects.nonNull(r.getAmount()))
.filter(r -> r.getAmount() > 0)
.collect(Collectors.toList());
param.setRefundChannels(channelParams);
if (!param.isRefundAll()) {
List<RefundChannelParam> channelParams = param.getRefundChannels()
.stream()
.filter(r -> Objects.nonNull(r.getAmount()))
.filter(r -> r.getAmount() > 0)
.collect(Collectors.toList());
param.setRefundChannels(channelParams);
}
// 退款号唯一校验
if (StrUtil.isNotBlank(param.getRefundNo())

View File

@@ -101,7 +101,7 @@ public class RefundService {
.stream()
.map(o -> new RefundChannelParam()
.setChannel(o.getChannel())
.setAmount(o.getAmount()))
.setAmount(o.getRefundableBalance()))
.collect(Collectors.toList());
param.setRefundChannels(channelParams);
} else if (simple) {
@@ -154,13 +154,16 @@ public class RefundService {
refundStrategy.initRefundParam(payOrder, refundParam, payChannelOrder);
}
// 生成通道退款订单对象
// 2.1 退款前校验操作
payRefundStrategies.forEach(AbsRefundStrategy::doBeforeCheckHandler);
// 2.2 生成通道退款订单对象
payRefundStrategies.forEach(AbsRefundStrategy::generateChannelOrder);
// 退款操作的预处理, 使用独立的新事物进行发起, 返回创建成功的退款订单, 成功后才可以进行下一阶段的操作
// 2.3 退款操作的预处理, 使用独立的新事物进行发起, 返回创建成功的退款订单, 成功后才可以进行下一阶段的操作
RefundOrder refundOrder = SpringUtil.getBean(this.getClass()).preRefundMethod(refundParam, payOrder, payRefundStrategies);
// 设置退款订单对象
// 2.4 设置退款订单对象
payRefundStrategies.forEach(r->r.setRefundOrder(refundOrder));
try {
@@ -168,7 +171,7 @@ public class RefundService {
payRefundStrategies.forEach(AbsRefundStrategy::doBeforeRefundHandler);
// 3.2 执行退款策略
payRefundStrategies.forEach(AbsRefundStrategy::doRefundHandler);
// 3.4 执行退款发起成功后操作
// 3.3 执行退款发起成功后操作
payRefundStrategies.forEach(AbsRefundStrategy::doSuccessHandler);
// 4.进行成功处理, 分别处理退款订单, 通道退款订单, 支付订单

View File

@@ -1,7 +1,8 @@
package cn.bootx.platform.daxpay.service.func;
import cn.bootx.platform.daxpay.code.RefundStatusEnum;
import cn.bootx.platform.daxpay.code.PayStatusEnum;
import cn.bootx.platform.daxpay.code.RefundStatusEnum;
import cn.bootx.platform.daxpay.exception.pay.PayFailureException;
import cn.bootx.platform.daxpay.param.pay.RefundChannelParam;
import cn.bootx.platform.daxpay.param.pay.RefundParam;
import cn.bootx.platform.daxpay.service.core.order.pay.entity.PayChannelOrder;
@@ -62,9 +63,20 @@ public abstract class AbsRefundStrategy implements PayStrategy{
}
/**
* 退款前对处理
* 退款前对退款数据校验
*/
public void doBeforeRefundHandler() {}
public void doBeforeCheckHandler() {
// 退款金额不可以大于可退余额
if (this.getRefundChannelParam().getAmount() > this.getPayChannelOrder().getRefundableBalance()) {
throw new PayFailureException("["+ this.getChannel().getName() +"]退款金额大于可退余额");
}
}
/**
* 退款前对处理, 主要进行配置的加载和检查
*/
public void doBeforeRefundHandler() {
}
/**
* 退款操作