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