mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
修改退款逻辑code review
This commit is contained in:
parent
bcc2ff0f5b
commit
e8368bb7fd
@ -2,7 +2,7 @@ package cn.iocoder.yudao.coreservice.modules.pay.convert.order;
|
|||||||
|
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.order.PayOrderDO;
|
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.order.PayOrderDO;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.order.PayRefundDO;
|
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.order.PayRefundDO;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.bo.PayRefundPostReqBO;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayRefundPostReqDTO;
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.dto.PayRefundUnifiedRespDTO;
|
import cn.iocoder.yudao.framework.pay.core.client.dto.PayRefundUnifiedRespDTO;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.factory.Mappers;
|
import org.mapstruct.factory.Mappers;
|
||||||
@ -14,7 +14,7 @@ public interface PayRefundCoreConvert {
|
|||||||
|
|
||||||
PayRefundCoreConvert INSTANCE = Mappers.getMapper(PayRefundCoreConvert.class);
|
PayRefundCoreConvert INSTANCE = Mappers.getMapper(PayRefundCoreConvert.class);
|
||||||
|
|
||||||
PayRefundPostReqBO convert(PayRefundUnifiedRespDTO respDTO);
|
PayRefundPostReqDTO convert(PayRefundUnifiedRespDTO respDTO);
|
||||||
|
|
||||||
//TODO 太多需要处理了, 暂时不用
|
//TODO 太多需要处理了, 暂时不用
|
||||||
@Mappings(value = {
|
@Mappings(value = {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package cn.iocoder.yudao.coreservice.modules.pay.service.order;
|
package cn.iocoder.yudao.coreservice.modules.pay.service.order;
|
||||||
|
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.bo.PayRefundPostReqBO;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayRefundPostReqDTO;
|
||||||
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelRespEnum;
|
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelRespEnum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -20,7 +20,7 @@ public interface PayRefundChannelPostHandler {
|
|||||||
/**
|
/**
|
||||||
* 根据渠道返回,处理支付退款单
|
* 根据渠道返回,处理支付退款单
|
||||||
*
|
*
|
||||||
* @param respBO
|
* @param req 退款后置处理请求
|
||||||
*/
|
*/
|
||||||
void handleRefundChannelResp(PayRefundPostReqBO respBO);
|
void handleRefundChannelResp(PayRefundPostReqDTO req);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package cn.iocoder.yudao.coreservice.modules.pay.service.order;
|
package cn.iocoder.yudao.coreservice.modules.pay.service.order;
|
||||||
|
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.bo.PayRefundReqBO;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayRefundReqDTO;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.bo.PayRefundRespBO;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayRefundRespDTO;
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.dto.PayNotifyDataDTO;
|
import cn.iocoder.yudao.framework.pay.core.client.dto.PayNotifyDataDTO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -11,14 +11,13 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.PayNotifyDataDTO;
|
|||||||
*/
|
*/
|
||||||
public interface PayRefundCoreService {
|
public interface PayRefundCoreService {
|
||||||
|
|
||||||
// TODO @jason:方法名改成,submitRefundOrder,发起退款订单。这样和发起支付单,保持一致
|
|
||||||
/**
|
/**
|
||||||
* 提交退款申请
|
* 提交退款申请
|
||||||
*
|
*
|
||||||
* @param reqDTO 退款申请信息
|
* @param reqDTO 退款申请信息
|
||||||
* @return 退款申请返回信息
|
* @return 退款申请返回信息
|
||||||
*/
|
*/
|
||||||
PayRefundRespBO refund(PayRefundReqBO reqDTO);
|
PayRefundRespDTO submitRefundOrder(PayRefundReqDTO reqDTO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 渠道的退款通知
|
* 渠道的退款通知
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package cn.iocoder.yudao.coreservice.modules.pay.service.order.bo;
|
package cn.iocoder.yudao.coreservice.modules.pay.service.order.dto;
|
||||||
|
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayRefundTypeEnum;
|
import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayRefundTypeEnum;
|
||||||
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelRespEnum;
|
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelRespEnum;
|
||||||
@ -8,13 +8,15 @@ import lombok.Data;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
// TODO @jason:改到 dto 哈。我们项目,统一使用 DTO
|
/**
|
||||||
|
* 退款后置处理请求 Request DTO
|
||||||
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class PayRefundPostReqBO {
|
public class PayRefundPostReqDTO {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
@ -1,4 +1,4 @@
|
|||||||
package cn.iocoder.yudao.coreservice.modules.pay.service.order.bo;
|
package cn.iocoder.yudao.coreservice.modules.pay.service.order.dto;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@ -6,7 +6,6 @@ import lombok.Data;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
// TODO @jason:改到 dto 哈。我们项目,统一使用 DTO
|
|
||||||
/**
|
/**
|
||||||
* 退款申请单 Request DTO
|
* 退款申请单 Request DTO
|
||||||
*/
|
*/
|
||||||
@ -15,7 +14,7 @@ import lombok.experimental.Accessors;
|
|||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class PayRefundReqBO {
|
public class PayRefundReqDTO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付订单编号自增
|
* 支付订单编号自增
|
@ -1,4 +1,4 @@
|
|||||||
package cn.iocoder.yudao.coreservice.modules.pay.service.order.bo;
|
package cn.iocoder.yudao.coreservice.modules.pay.service.order.dto;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@ -6,7 +6,6 @@ import lombok.Data;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
// TODO @jason:改到 dto 哈。我们项目,统一使用 DTO
|
|
||||||
/**
|
/**
|
||||||
* 退款申请单 Response DTO
|
* 退款申请单 Response DTO
|
||||||
*/
|
*/
|
||||||
@ -15,7 +14,7 @@ import lombok.experimental.Accessors;
|
|||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class PayRefundRespBO {
|
public class PayRefundRespDTO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付退款单编号, 自增
|
* 支付退款单编号, 自增
|
@ -14,6 +14,8 @@ import cn.iocoder.yudao.coreservice.modules.pay.enums.notify.PayNotifyTypeEnum;
|
|||||||
import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayOrderNotifyStatusEnum;
|
import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayOrderNotifyStatusEnum;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.notify.PayNotifyCoreService;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.notify.PayNotifyCoreService;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.notify.dto.PayNotifyTaskCreateReqDTO;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.notify.dto.PayNotifyTaskCreateReqDTO;
|
||||||
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayRefundPostReqDTO;
|
||||||
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayRefundReqDTO;
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.dto.PayRefundNotifyDTO;
|
import cn.iocoder.yudao.framework.pay.core.client.dto.PayRefundNotifyDTO;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayRefundTypeEnum;
|
import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayRefundTypeEnum;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayOrderStatusEnum;
|
import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayOrderStatusEnum;
|
||||||
@ -22,9 +24,7 @@ import cn.iocoder.yudao.coreservice.modules.pay.service.merchant.PayAppCoreServi
|
|||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.merchant.PayChannelCoreService;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.merchant.PayChannelCoreService;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayRefundCoreService;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayRefundCoreService;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayRefundChannelPostHandler;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayRefundChannelPostHandler;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.bo.PayRefundPostReqBO;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayRefundRespDTO;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.bo.PayRefundReqBO;
|
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.bo.PayRefundRespBO;
|
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.util.PaySeqUtils;
|
import cn.iocoder.yudao.coreservice.modules.pay.util.PaySeqUtils;
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.PayClient;
|
import cn.iocoder.yudao.framework.pay.core.client.PayClient;
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory;
|
import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory;
|
||||||
@ -71,15 +71,14 @@ public class PayRefundCoreServiceImpl implements PayRefundCoreService {
|
|||||||
@Resource
|
@Resource
|
||||||
private List<PayRefundChannelPostHandler> handlerList;
|
private List<PayRefundChannelPostHandler> handlerList;
|
||||||
|
|
||||||
// TODO @json:mapHandlers
|
private final EnumMap<PayChannelRespEnum, PayRefundChannelPostHandler> mapHandlers = new EnumMap<>(PayChannelRespEnum.class);
|
||||||
private final EnumMap<PayChannelRespEnum, PayRefundChannelPostHandler> mapHandler = new EnumMap<>(PayChannelRespEnum.class);
|
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init(){
|
public void init(){
|
||||||
if (Objects.nonNull(handlerList)) {
|
if (Objects.nonNull(handlerList)) {
|
||||||
handlerList.forEach(handler -> {
|
handlerList.forEach(handler -> {
|
||||||
for (PayChannelRespEnum item : handler.supportHandleResp()) {
|
for (PayChannelRespEnum item : handler.supportHandleResp()) {
|
||||||
mapHandler.put(item, handler);
|
mapHandlers.put(item, handler);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -87,9 +86,9 @@ public class PayRefundCoreServiceImpl implements PayRefundCoreService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public PayRefundRespBO refund(PayRefundReqBO reqBO) {
|
public PayRefundRespDTO submitRefundOrder(PayRefundReqDTO req) {
|
||||||
// 获得 PayOrderDO
|
// 获得 PayOrderDO
|
||||||
PayOrderDO order = payOrderCoreMapper.selectById(reqBO.getPayOrderId());
|
PayOrderDO order = payOrderCoreMapper.selectById(req.getPayOrderId());
|
||||||
// 校验订单是否存在
|
// 校验订单是否存在
|
||||||
if (Objects.isNull(order) ) {
|
if (Objects.isNull(order) ) {
|
||||||
throw exception(PAY_ORDER_NOT_FOUND);
|
throw exception(PAY_ORDER_NOT_FOUND);
|
||||||
@ -106,14 +105,13 @@ public class PayRefundCoreServiceImpl implements PayRefundCoreService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 校验退款的条件
|
// 校验退款的条件
|
||||||
validatePayRefund(reqBO, order);
|
validatePayRefund(req, order);
|
||||||
|
|
||||||
// 退款类型
|
// 退款类型
|
||||||
PayRefundTypeEnum refundType = PayRefundTypeEnum.SOME;
|
PayRefundTypeEnum refundType = PayRefundTypeEnum.SOME;
|
||||||
if (Objects.equals(reqBO.getAmount(), order.getAmount())) {
|
if (Objects.equals(req.getAmount(), order.getAmount())) {
|
||||||
refundType = PayRefundTypeEnum.ALL;
|
refundType = PayRefundTypeEnum.ALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 退款单入库 退款单状态:生成, 没有和渠道产生交互
|
// 退款单入库 退款单状态:生成, 没有和渠道产生交互
|
||||||
PayOrderExtensionDO orderExtensionDO = payOrderExtensionCoreMapper.selectById(order.getSuccessExtensionId());
|
PayOrderExtensionDO orderExtensionDO = payOrderExtensionCoreMapper.selectById(order.getSuccessExtensionId());
|
||||||
PayRefundDO refundDO = PayRefundDO.builder().channelOrderNo(order.getChannelOrderNo())
|
PayRefundDO refundDO = PayRefundDO.builder().channelOrderNo(order.getChannelOrderNo())
|
||||||
@ -123,54 +121,47 @@ public class PayRefundCoreServiceImpl implements PayRefundCoreService {
|
|||||||
.channelId(order.getChannelId())
|
.channelId(order.getChannelId())
|
||||||
.merchantId(order.getMerchantId())
|
.merchantId(order.getMerchantId())
|
||||||
.orderId(order.getId())
|
.orderId(order.getId())
|
||||||
.merchantRefundNo(reqBO.getMerchantRefundNo())
|
.merchantRefundNo(req.getMerchantRefundNo())
|
||||||
.notifyUrl(app.getRefundNotifyUrl())
|
.notifyUrl(app.getRefundNotifyUrl())
|
||||||
.payAmount(order.getAmount())
|
.payAmount(order.getAmount())
|
||||||
.refundAmount(reqBO.getAmount())
|
.refundAmount(req.getAmount())
|
||||||
.userIp(reqBO.getUserIp())
|
.userIp(req.getUserIp())
|
||||||
.merchantOrderId(order.getMerchantOrderId())
|
.merchantOrderId(order.getMerchantOrderId())
|
||||||
.tradeNo(orderExtensionDO.getNo())
|
.tradeNo(orderExtensionDO.getNo())
|
||||||
.status(PayRefundStatusEnum.CREATE.getStatus())
|
.status(PayRefundStatusEnum.CREATE.getStatus())
|
||||||
.reason(reqBO.getReason())
|
.reason(req.getReason())
|
||||||
.notifyStatus(PayOrderNotifyStatusEnum.NO.getStatus())
|
.notifyStatus(PayOrderNotifyStatusEnum.NO.getStatus())
|
||||||
.reqNo(PaySeqUtils.genRefundReqNo())
|
.reqNo(PaySeqUtils.genRefundReqNo())
|
||||||
.type(refundType.getStatus())
|
.type(refundType.getStatus())
|
||||||
.build();
|
.build();
|
||||||
payRefundCoreMapper.insert(refundDO);
|
payRefundCoreMapper.insert(refundDO);
|
||||||
|
|
||||||
// TODO @jason:可以把“调用渠道进行退款"写到这里,这样分块更明确
|
// 调用渠道进行退款
|
||||||
PayRefundUnifiedReqDTO unifiedReqDTO = PayRefundUnifiedReqDTO.builder()
|
PayRefundUnifiedReqDTO unifiedReqDTO = PayRefundUnifiedReqDTO.builder()
|
||||||
.userIp(reqBO.getUserIp())
|
.userIp(req.getUserIp())
|
||||||
.channelOrderNo(refundDO.getChannelOrderNo())
|
.channelOrderNo(refundDO.getChannelOrderNo())
|
||||||
.payTradeNo(refundDO.getTradeNo())
|
.payTradeNo(refundDO.getTradeNo())
|
||||||
.refundReqNo(refundDO.getReqNo())
|
.refundReqNo(refundDO.getReqNo())
|
||||||
.amount(reqBO.getAmount())
|
.amount(req.getAmount())
|
||||||
.reason(refundDO.getReason())
|
.reason(refundDO.getReason())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// 调用渠道进行退款
|
|
||||||
PayRefundUnifiedRespDTO refundUnifiedRespDTO = client.unifiedRefund(unifiedReqDTO);
|
PayRefundUnifiedRespDTO refundUnifiedRespDTO = client.unifiedRefund(unifiedReqDTO);
|
||||||
|
|
||||||
// TODO @jason:下面这块,是一整块逻辑,不要空开。不然阅读的时候,会以为不是一块逻辑
|
|
||||||
// 根据渠道返回,获取退款后置处理,由postHandler 进行处理
|
// 根据渠道返回,获取退款后置处理,由postHandler 进行处理
|
||||||
PayRefundChannelPostHandler payRefundChannelPostHandler = mapHandler.get(refundUnifiedRespDTO.getRespEnum());
|
PayRefundChannelPostHandler payRefundChannelPostHandler = mapHandlers.get(refundUnifiedRespDTO.getRespEnum());
|
||||||
|
|
||||||
if (Objects.isNull(payRefundChannelPostHandler)) {
|
if (Objects.isNull(payRefundChannelPostHandler)) {
|
||||||
throw exception(PAY_REFUND_POST_HANDLER_NOT_FOUND);
|
throw exception(PAY_REFUND_POST_HANDLER_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
PayRefundPostReqDTO dto = PayRefundCoreConvert.INSTANCE.convert(refundUnifiedRespDTO);
|
||||||
PayRefundPostReqBO bo = PayRefundCoreConvert.INSTANCE.convert(refundUnifiedRespDTO);
|
dto.setRefundAmount(req.getAmount())
|
||||||
bo.setRefundAmount(reqBO.getAmount())
|
|
||||||
.setRefundedAmount(order.getRefundAmount())
|
.setRefundedAmount(order.getRefundAmount())
|
||||||
.setRefundedTimes(order.getRefundTimes())
|
.setRefundedTimes(order.getRefundTimes())
|
||||||
.setRefundId(refundDO.getId())
|
.setRefundId(refundDO.getId())
|
||||||
.setOrderId(order.getId())
|
.setOrderId(order.getId())
|
||||||
.setRefundTypeEnum(refundType);
|
.setRefundTypeEnum(refundType);
|
||||||
|
|
||||||
//调用退款的后置处理
|
//调用退款的后置处理
|
||||||
payRefundChannelPostHandler.handleRefundChannelResp(bo);
|
payRefundChannelPostHandler.handleRefundChannelResp(dto);
|
||||||
|
|
||||||
return PayRefundRespBO.builder().refundId(refundDO.getId()).build();
|
return PayRefundRespDTO.builder().refundId(refundDO.getId()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -234,10 +225,10 @@ public class PayRefundCoreServiceImpl implements PayRefundCoreService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验是否进行退款
|
* 校验是否进行退款
|
||||||
* @param reqBO 退款申请信息
|
* @param req 退款申请信息
|
||||||
* @param order 原始支付订单信息
|
* @param order 原始支付订单信息
|
||||||
*/
|
*/
|
||||||
private void validatePayRefund(PayRefundReqBO reqBO, PayOrderDO order) {
|
private void validatePayRefund(PayRefundReqDTO req, PayOrderDO order) {
|
||||||
// 校验状态,必须是支付状态
|
// 校验状态,必须是支付状态
|
||||||
if (!PayOrderStatusEnum.SUCCESS.getStatus().equals(order.getStatus())) {
|
if (!PayOrderStatusEnum.SUCCESS.getStatus().equals(order.getStatus())) {
|
||||||
throw exception(PAY_ORDER_STATUS_IS_NOT_SUCCESS);
|
throw exception(PAY_ORDER_STATUS_IS_NOT_SUCCESS);
|
||||||
@ -247,7 +238,7 @@ public class PayRefundCoreServiceImpl implements PayRefundCoreService {
|
|||||||
throw exception(PAY_REFUND_ALL_REFUNDED);
|
throw exception(PAY_REFUND_ALL_REFUNDED);
|
||||||
}
|
}
|
||||||
// 校验金额 退款金额不能大于 原定的金额
|
// 校验金额 退款金额不能大于 原定的金额
|
||||||
if(reqBO.getAmount() + order.getRefundAmount() > order.getAmount()){
|
if(req.getAmount() + order.getRefundAmount() > order.getAmount()){
|
||||||
throw exception(PAY_REFUND_AMOUNT_EXCEED);
|
throw exception(PAY_REFUND_AMOUNT_EXCEED);
|
||||||
}
|
}
|
||||||
// 校验渠道订单号
|
// 校验渠道订单号
|
||||||
|
@ -9,7 +9,7 @@ import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayRefundStatusEnum;
|
|||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.notify.PayNotifyCoreService;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.notify.PayNotifyCoreService;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.notify.dto.PayNotifyTaskCreateReqDTO;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.notify.dto.PayNotifyTaskCreateReqDTO;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayRefundAbstractChannelPostHandler;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayRefundAbstractChannelPostHandler;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.bo.PayRefundPostReqBO;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayRefundPostReqDTO;
|
||||||
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelRespEnum;
|
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelRespEnum;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -38,25 +38,25 @@ public class PayRefundChannelFailedHandler extends PayRefundAbstractChannelPostH
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRefundChannelResp(PayRefundPostReqBO respBO) {
|
public void handleRefundChannelResp(PayRefundPostReqDTO req) {
|
||||||
//退款失败
|
//退款失败
|
||||||
//更新退款单表
|
//更新退款单表
|
||||||
PayRefundDO updateRefundDO = new PayRefundDO();
|
PayRefundDO updateRefundDO = new PayRefundDO();
|
||||||
|
|
||||||
updateRefundDO.setId(respBO.getRefundId())
|
updateRefundDO.setId(req.getRefundId())
|
||||||
.setStatus(PayRefundStatusEnum.FAILURE.getStatus())
|
.setStatus(PayRefundStatusEnum.FAILURE.getStatus())
|
||||||
.setChannelErrorCode(respBO.getChannelErrCode())
|
.setChannelErrorCode(req.getChannelErrCode())
|
||||||
.setChannelErrorMsg(Optional.ofNullable(respBO.getChannelErrMsg())
|
.setChannelErrorMsg(Optional.ofNullable(req.getChannelErrMsg())
|
||||||
.orElse(respBO.getExceptionMsg()));
|
.orElse(req.getExceptionMsg()));
|
||||||
updatePayRefund(updateRefundDO);
|
updatePayRefund(updateRefundDO);
|
||||||
PayOrderDO updateOrderDO = new PayOrderDO();
|
PayOrderDO updateOrderDO = new PayOrderDO();
|
||||||
//更新订单表
|
//更新订单表
|
||||||
updateOrderDO.setId(respBO.getOrderId())
|
updateOrderDO.setId(req.getOrderId())
|
||||||
.setRefundTimes(respBO.getRefundedTimes() + 1);
|
.setRefundTimes(req.getRefundedTimes() + 1);
|
||||||
updatePayOrder(updateOrderDO);
|
updatePayOrder(updateOrderDO);
|
||||||
// 立刻插入退款通知记录
|
// 立刻插入退款通知记录
|
||||||
// TODO 通知商户成功或者失败. 现在通知似乎没有实现, 只是回调
|
// TODO 通知商户成功或者失败. 现在通知似乎没有实现, 只是回调
|
||||||
payNotifyCoreService.createPayNotifyTask(PayNotifyTaskCreateReqDTO.builder()
|
payNotifyCoreService.createPayNotifyTask(PayNotifyTaskCreateReqDTO.builder()
|
||||||
.type(PayNotifyTypeEnum.REFUND.getType()).dataId(respBO.getRefundId()).build());
|
.type(PayNotifyTypeEnum.REFUND.getType()).dataId(req.getRefundId()).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import cn.iocoder.yudao.coreservice.modules.pay.dal.mysql.order.PayOrderCoreMapp
|
|||||||
import cn.iocoder.yudao.coreservice.modules.pay.dal.mysql.order.PayRefundCoreMapper;
|
import cn.iocoder.yudao.coreservice.modules.pay.dal.mysql.order.PayRefundCoreMapper;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayRefundStatusEnum;
|
import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayRefundStatusEnum;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayRefundAbstractChannelPostHandler;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayRefundAbstractChannelPostHandler;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.bo.PayRefundPostReqBO;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayRefundPostReqDTO;
|
||||||
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelRespEnum;
|
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelRespEnum;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -28,17 +28,17 @@ public class PayRefundChannelNotifyHandler extends PayRefundAbstractChannelPostH
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRefundChannelResp(PayRefundPostReqBO respBO) {
|
public void handleRefundChannelResp(PayRefundPostReqDTO req) {
|
||||||
PayRefundDO updateRefundDO = new PayRefundDO();
|
PayRefundDO updateRefundDO = new PayRefundDO();
|
||||||
//更新退款单表
|
//更新退款单表
|
||||||
updateRefundDO.setId(respBO.getRefundId())
|
updateRefundDO.setId(req.getRefundId())
|
||||||
.setStatus(PayRefundStatusEnum.PROCESSING_NOTIFY.getStatus());
|
.setStatus(PayRefundStatusEnum.PROCESSING_NOTIFY.getStatus());
|
||||||
updatePayRefund(updateRefundDO);
|
updatePayRefund(updateRefundDO);
|
||||||
|
|
||||||
PayOrderDO updateOrderDO = new PayOrderDO();
|
PayOrderDO updateOrderDO = new PayOrderDO();
|
||||||
//更新订单表
|
//更新订单表
|
||||||
updateOrderDO.setId(respBO.getOrderId())
|
updateOrderDO.setId(req.getOrderId())
|
||||||
.setRefundTimes(respBO.getRefundedTimes() + 1);
|
.setRefundTimes(req.getRefundedTimes() + 1);
|
||||||
updatePayOrder(updateOrderDO);
|
updatePayOrder(updateOrderDO);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import cn.iocoder.yudao.coreservice.modules.pay.dal.mysql.order.PayOrderCoreMapp
|
|||||||
import cn.iocoder.yudao.coreservice.modules.pay.dal.mysql.order.PayRefundCoreMapper;
|
import cn.iocoder.yudao.coreservice.modules.pay.dal.mysql.order.PayRefundCoreMapper;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayRefundStatusEnum;
|
import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayRefundStatusEnum;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayRefundAbstractChannelPostHandler;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayRefundAbstractChannelPostHandler;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.bo.PayRefundPostReqBO;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayRefundPostReqDTO;
|
||||||
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelRespEnum;
|
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelRespEnum;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -32,23 +32,23 @@ public class PayRefundChannelQueryHandler extends PayRefundAbstractChannelPostHa
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRefundChannelResp(PayRefundPostReqBO respBO) {
|
public void handleRefundChannelResp(PayRefundPostReqDTO req) {
|
||||||
final PayChannelRespEnum respEnum = respBO.getRespEnum();
|
final PayChannelRespEnum respEnum = req.getRespEnum();
|
||||||
PayRefundStatusEnum refundStatus =
|
PayRefundStatusEnum refundStatus =
|
||||||
Objects.equals(PayChannelRespEnum.PROCESSING_QUERY, respEnum) ? PayRefundStatusEnum.PROCESSING_QUERY
|
Objects.equals(PayChannelRespEnum.PROCESSING_QUERY, respEnum) ? PayRefundStatusEnum.PROCESSING_QUERY
|
||||||
: PayRefundStatusEnum.UNKNOWN_QUERY;
|
: PayRefundStatusEnum.UNKNOWN_QUERY;
|
||||||
//更新退款单表
|
//更新退款单表
|
||||||
PayRefundDO updateRefundDO = new PayRefundDO();
|
PayRefundDO updateRefundDO = new PayRefundDO();
|
||||||
updateRefundDO.setId(respBO.getRefundId())
|
updateRefundDO.setId(req.getRefundId())
|
||||||
.setStatus(refundStatus.getStatus())
|
.setStatus(refundStatus.getStatus())
|
||||||
.setChannelErrorCode(respBO.getChannelErrCode())
|
.setChannelErrorCode(req.getChannelErrCode())
|
||||||
.setChannelErrorMsg(respBO.getChannelErrMsg());
|
.setChannelErrorMsg(req.getChannelErrMsg());
|
||||||
updatePayRefund(updateRefundDO);
|
updatePayRefund(updateRefundDO);
|
||||||
|
|
||||||
PayOrderDO updateOrderDO = new PayOrderDO();
|
PayOrderDO updateOrderDO = new PayOrderDO();
|
||||||
//更新订单表
|
//更新订单表
|
||||||
updateOrderDO.setId(respBO.getOrderId())
|
updateOrderDO.setId(req.getOrderId())
|
||||||
.setRefundTimes(respBO.getRefundedTimes() + 1);
|
.setRefundTimes(req.getRefundedTimes() + 1);
|
||||||
updatePayOrder(updateOrderDO);
|
updatePayOrder(updateOrderDO);
|
||||||
|
|
||||||
//TODO 发起查询任务
|
//TODO 发起查询任务
|
||||||
|
@ -6,7 +6,7 @@ import cn.iocoder.yudao.coreservice.modules.pay.dal.mysql.order.PayOrderCoreMapp
|
|||||||
import cn.iocoder.yudao.coreservice.modules.pay.dal.mysql.order.PayRefundCoreMapper;
|
import cn.iocoder.yudao.coreservice.modules.pay.dal.mysql.order.PayRefundCoreMapper;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayRefundStatusEnum;
|
import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayRefundStatusEnum;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayRefundAbstractChannelPostHandler;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayRefundAbstractChannelPostHandler;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.bo.PayRefundPostReqBO;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayRefundPostReqDTO;
|
||||||
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelRespEnum;
|
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelRespEnum;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -29,20 +29,20 @@ public class PayRefundChannelRetryHandler extends PayRefundAbstractChannelPostHa
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRefundChannelResp(PayRefundPostReqBO respBO) {
|
public void handleRefundChannelResp(PayRefundPostReqDTO req) {
|
||||||
|
|
||||||
PayRefundDO updateRefundDO = new PayRefundDO();
|
PayRefundDO updateRefundDO = new PayRefundDO();
|
||||||
//更新退款单表
|
//更新退款单表
|
||||||
updateRefundDO.setId(respBO.getRefundId())
|
updateRefundDO.setId(req.getRefundId())
|
||||||
.setStatus(PayRefundStatusEnum.UNKNOWN_RETRY.getStatus())
|
.setStatus(PayRefundStatusEnum.UNKNOWN_RETRY.getStatus())
|
||||||
.setChannelErrorCode(respBO.getChannelErrCode())
|
.setChannelErrorCode(req.getChannelErrCode())
|
||||||
.setChannelErrorMsg(respBO.getChannelErrMsg());
|
.setChannelErrorMsg(req.getChannelErrMsg());
|
||||||
updatePayRefund(updateRefundDO);
|
updatePayRefund(updateRefundDO);
|
||||||
|
|
||||||
PayOrderDO updateOrderDO = new PayOrderDO();
|
PayOrderDO updateOrderDO = new PayOrderDO();
|
||||||
//更新订单表
|
//更新订单表
|
||||||
updateOrderDO.setId(respBO.getOrderId())
|
updateOrderDO.setId(req.getOrderId())
|
||||||
.setRefundTimes(respBO.getRefundedTimes() + 1);
|
.setRefundTimes(req.getRefundedTimes() + 1);
|
||||||
updatePayOrder(updateOrderDO);
|
updatePayOrder(updateOrderDO);
|
||||||
|
|
||||||
//TODO 发起重试任务
|
//TODO 发起重试任务
|
||||||
|
@ -9,7 +9,7 @@ import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayRefundStatusEnum;
|
|||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.notify.PayNotifyCoreService;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.notify.PayNotifyCoreService;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.notify.dto.PayNotifyTaskCreateReqDTO;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.notify.dto.PayNotifyTaskCreateReqDTO;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayRefundAbstractChannelPostHandler;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayRefundAbstractChannelPostHandler;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.bo.PayRefundPostReqBO;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayRefundPostReqDTO;
|
||||||
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelRespEnum;
|
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelRespEnum;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -38,27 +38,27 @@ public class PayRefundChannelSuccessHandler extends PayRefundAbstractChannelPost
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRefundChannelResp(PayRefundPostReqBO respBO) {
|
public void handleRefundChannelResp(PayRefundPostReqDTO req) {
|
||||||
//退款成功
|
//退款成功
|
||||||
PayRefundDO updateRefundDO = new PayRefundDO();
|
PayRefundDO updateRefundDO = new PayRefundDO();
|
||||||
//更新退款单表
|
//更新退款单表
|
||||||
updateRefundDO.setId(respBO.getRefundId())
|
updateRefundDO.setId(req.getRefundId())
|
||||||
.setStatus(PayRefundStatusEnum.SUCCESS.getStatus())
|
.setStatus(PayRefundStatusEnum.SUCCESS.getStatus())
|
||||||
.setChannelRefundNo(respBO.getChannelRefundNo())
|
.setChannelRefundNo(req.getChannelRefundNo())
|
||||||
.setSuccessTime(new Date());
|
.setSuccessTime(new Date());
|
||||||
updatePayRefund(updateRefundDO);
|
updatePayRefund(updateRefundDO);
|
||||||
|
|
||||||
PayOrderDO updateOrderDO = new PayOrderDO();
|
PayOrderDO updateOrderDO = new PayOrderDO();
|
||||||
//更新订单表
|
//更新订单表
|
||||||
updateOrderDO.setId(respBO.getOrderId())
|
updateOrderDO.setId(req.getOrderId())
|
||||||
.setRefundTimes(respBO.getRefundedTimes() + 1)
|
.setRefundTimes(req.getRefundedTimes() + 1)
|
||||||
.setRefundStatus(respBO.getRefundTypeEnum().getStatus())
|
.setRefundStatus(req.getRefundTypeEnum().getStatus())
|
||||||
.setRefundAmount(respBO.getRefundedAmount()+respBO.getRefundAmount());
|
.setRefundAmount(req.getRefundedAmount()+ req.getRefundAmount());
|
||||||
updatePayOrder(updateOrderDO);
|
updatePayOrder(updateOrderDO);
|
||||||
|
|
||||||
// 立刻插入退款通知记录
|
// 立刻插入退款通知记录
|
||||||
// TODO 通知商户成功或者失败. 现在通知似乎没有实现, 只是回调
|
// TODO 通知商户成功或者失败. 现在通知似乎没有实现, 只是回调
|
||||||
payNotifyCoreService.createPayNotifyTask(PayNotifyTaskCreateReqDTO.builder()
|
payNotifyCoreService.createPayNotifyTask(PayNotifyTaskCreateReqDTO.builder()
|
||||||
.type(PayNotifyTypeEnum.REFUND.getType()).dataId(respBO.getRefundId()).build());
|
.type(PayNotifyTypeEnum.REFUND.getType()).dataId(req.getRefundId()).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package cn.iocoder.yudao.userserver.modules.pay.controller.order;
|
package cn.iocoder.yudao.userserver.modules.pay.controller.order;
|
||||||
|
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayRefundCoreService;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.PayRefundCoreService;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.bo.PayRefundReqBO;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayRefundReqDTO;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.util.PaySeqUtils;
|
import cn.iocoder.yudao.coreservice.modules.pay.util.PaySeqUtils;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
import cn.iocoder.yudao.userserver.modules.pay.controller.order.vo.PayRefundReqVO;
|
import cn.iocoder.yudao.userserver.modules.pay.controller.order.vo.PayRefundReqVO;
|
||||||
@ -32,13 +32,13 @@ public class PayRefundController {
|
|||||||
|
|
||||||
@PostMapping("/refund")
|
@PostMapping("/refund")
|
||||||
@ApiOperation("提交退款订单")
|
@ApiOperation("提交退款订单")
|
||||||
public CommonResult<PayRefundRespVO> refund(@RequestBody PayRefundReqVO reqVO){
|
public CommonResult<PayRefundRespVO> submitRefundOrder(@RequestBody PayRefundReqVO reqVO){
|
||||||
PayRefundReqBO reqBO = PayRefundConvert.INSTANCE.convert(reqVO);
|
PayRefundReqDTO req = PayRefundConvert.INSTANCE.convert(reqVO);
|
||||||
reqBO.setUserIp(getClientIP());
|
req.setUserIp(getClientIP());
|
||||||
//TODO 测试暂时模拟生成商户退款订单
|
//TODO 测试暂时模拟生成商户退款订单
|
||||||
reqBO.setMerchantRefundNo(PaySeqUtils.genMerchantRefundNo());
|
req.setMerchantRefundNo(PaySeqUtils.genMerchantRefundNo());
|
||||||
//reqBO.setMerchantRefundNo("MO202111210814084370000");
|
//req.setMerchantRefundNo("MO202111210814084370000");
|
||||||
return CommonResult.success( PayRefundConvert.INSTANCE.convert(payRefundCoreService.refund(reqBO)));
|
return CommonResult.success( PayRefundConvert.INSTANCE.convert(payRefundCoreService.submitRefundOrder(req)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package cn.iocoder.yudao.userserver.modules.pay.convert.order;
|
package cn.iocoder.yudao.userserver.modules.pay.convert.order;
|
||||||
|
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.bo.PayRefundReqBO;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayRefundReqDTO;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.service.order.bo.PayRefundRespBO;
|
import cn.iocoder.yudao.coreservice.modules.pay.service.order.dto.PayRefundRespDTO;
|
||||||
import cn.iocoder.yudao.userserver.modules.pay.controller.order.vo.PayRefundReqVO;
|
import cn.iocoder.yudao.userserver.modules.pay.controller.order.vo.PayRefundReqVO;
|
||||||
import cn.iocoder.yudao.userserver.modules.pay.controller.order.vo.PayRefundRespVO;
|
import cn.iocoder.yudao.userserver.modules.pay.controller.order.vo.PayRefundRespVO;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
@ -17,7 +17,7 @@ public interface PayRefundConvert {
|
|||||||
|
|
||||||
PayRefundConvert INSTANCE = Mappers.getMapper(PayRefundConvert.class);
|
PayRefundConvert INSTANCE = Mappers.getMapper(PayRefundConvert.class);
|
||||||
|
|
||||||
PayRefundReqBO convert(PayRefundReqVO reqVO);
|
PayRefundReqDTO convert(PayRefundReqVO reqVO);
|
||||||
|
|
||||||
PayRefundRespVO convert(PayRefundRespBO respBO);
|
PayRefundRespVO convert(PayRefundRespDTO respBO);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user