Commit 19b574fd4b9f4a6fdcb1cb80f3c326792b9a7125
1 parent
5bf30455
code review 退款逻辑
Showing
3 changed files
with
11 additions
and
8 deletions
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/dal/dataobject/order/PayRefundDO.java
| @@ -98,6 +98,7 @@ public class PayRefundDO extends BaseDO { | @@ -98,6 +98,7 @@ public class PayRefundDO extends BaseDO { | ||
| 98 | * 退款单请求号,根据规则生成 | 98 | * 退款单请求号,根据规则生成 |
| 99 | * 例如说,R202109181134287570000 | 99 | * 例如说,R202109181134287570000 |
| 100 | */ | 100 | */ |
| 101 | + // TODO @jason:merchantRefundNo =》merchantRefundOId | ||
| 101 | private String merchantRefundNo; | 102 | private String merchantRefundNo; |
| 102 | 103 | ||
| 103 | /** | 104 | /** |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/service/order/impl/PayRefundCoreServiceImpl.java
| @@ -101,7 +101,8 @@ public class PayRefundCoreServiceImpl implements PayRefundCoreService { | @@ -101,7 +101,8 @@ public class PayRefundCoreServiceImpl implements PayRefundCoreService { | ||
| 101 | } | 101 | } |
| 102 | //可以重复提交,保证 退款请求号 一致,由渠道保证幂等 | 102 | //可以重复提交,保证 退款请求号 一致,由渠道保证幂等 |
| 103 | }else { | 103 | }else { |
| 104 | - //成功,插入退款单 状态为生成.没有和渠道交互 | 104 | + // 成功,插入退款单 状态为生成.没有和渠道交互 |
| 105 | + // TODO @jason:搞到 convert 里。一些额外的自动,手动 set 下; | ||
| 105 | payRefundDO = PayRefundDO.builder().channelOrderNo(order.getChannelOrderNo()) | 106 | payRefundDO = PayRefundDO.builder().channelOrderNo(order.getChannelOrderNo()) |
| 106 | .appId(order.getAppId()) | 107 | .appId(order.getAppId()) |
| 107 | .channelOrderNo(order.getChannelOrderNo()) | 108 | .channelOrderNo(order.getChannelOrderNo()) |
| @@ -123,6 +124,7 @@ public class PayRefundCoreServiceImpl implements PayRefundCoreService { | @@ -123,6 +124,7 @@ public class PayRefundCoreServiceImpl implements PayRefundCoreService { | ||
| 123 | .build(); | 124 | .build(); |
| 124 | payRefundCoreMapper.insert(payRefundDO); | 125 | payRefundCoreMapper.insert(payRefundDO); |
| 125 | } | 126 | } |
| 127 | + // TODO @jason:搞到 convert 里。一些额外的自动,手动 set 下; | ||
| 126 | PayRefundUnifiedReqDTO unifiedReqDTO = new PayRefundUnifiedReqDTO(); | 128 | PayRefundUnifiedReqDTO unifiedReqDTO = new PayRefundUnifiedReqDTO(); |
| 127 | unifiedReqDTO.setUserIp(req.getUserIp()) | 129 | unifiedReqDTO.setUserIp(req.getUserIp()) |
| 128 | .setAmount(req.getAmount()) | 130 | .setAmount(req.getAmount()) |
| @@ -132,10 +134,11 @@ public class PayRefundCoreServiceImpl implements PayRefundCoreService { | @@ -132,10 +134,11 @@ public class PayRefundCoreServiceImpl implements PayRefundCoreService { | ||
| 132 | .setReason(req.getReason()); | 134 | .setReason(req.getReason()); |
| 133 | // 向渠道发起退款申请 | 135 | // 向渠道发起退款申请 |
| 134 | PayCommonResult<PayRefundUnifiedRespDTO> refundUnifiedResult = client.unifiedRefund(unifiedReqDTO); | 136 | PayCommonResult<PayRefundUnifiedRespDTO> refundUnifiedResult = client.unifiedRefund(unifiedReqDTO); |
| 135 | - //检查是否失败,失败抛出业务异常。 | ||
| 136 | - //TODO 渠道的异常记录 | 137 | + // 检查是否失败,失败抛出业务异常。 |
| 138 | + // TODO 渠道的异常记录。 | ||
| 139 | + // TODO @jason:可以先打个 warn log 哈; | ||
| 137 | refundUnifiedResult.checkError(); | 140 | refundUnifiedResult.checkError(); |
| 138 | - //成功在 退款回调中处理 | 141 | + // 成功在 退款回调中处理 |
| 139 | return PayRefundRespDTO.builder().refundId(payRefundDO.getId()).build(); | 142 | return PayRefundRespDTO.builder().refundId(payRefundDO.getId()).build(); |
| 140 | } | 143 | } |
| 141 | 144 |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayClient.java
| @@ -118,12 +118,11 @@ public abstract class AbstractAlipayClient extends AbstractPayClient<AlipayPayCl | @@ -118,12 +118,11 @@ public abstract class AbstractAlipayClient extends AbstractPayClient<AlipayPayCl | ||
| 118 | PayRefundUnifiedRespDTO respDTO = new PayRefundUnifiedRespDTO(); | 118 | PayRefundUnifiedRespDTO respDTO = new PayRefundUnifiedRespDTO(); |
| 119 | respDTO.setChannelRefundId(""); | 119 | respDTO.setChannelRefundId(""); |
| 120 | return PayCommonResult.build(response.getCode(), response.getMsg(), respDTO, codeMapping); | 120 | return PayCommonResult.build(response.getCode(), response.getMsg(), respDTO, codeMapping); |
| 121 | - }else{ | ||
| 122 | - //失败。需要抛出异常 | ||
| 123 | - return PayCommonResult.build(response.getCode(), response.getMsg(), null, codeMapping); | ||
| 124 | } | 121 | } |
| 122 | + // 失败。需要抛出异常 | ||
| 123 | + return PayCommonResult.build(response.getCode(), response.getMsg(), null, codeMapping); | ||
| 125 | } catch (AlipayApiException e) { | 124 | } catch (AlipayApiException e) { |
| 126 | - //TODO 记录异常日志 | 125 | + // TODO 记录异常日志 |
| 127 | log.error("[doUnifiedRefund][request({}) 发起退款失败,网络读超时,退款状态未知]", toJsonString(reqDTO), e); | 126 | log.error("[doUnifiedRefund][request({}) 发起退款失败,网络读超时,退款状态未知]", toJsonString(reqDTO), e); |
| 128 | return PayCommonResult.build(e.getErrCode(), e.getErrMsg(), null, codeMapping); | 127 | return PayCommonResult.build(e.getErrCode(), e.getErrMsg(), null, codeMapping); |
| 129 | } | 128 | } |