2026-06-25 a26b31cc9f3ee9b21b1a754e80fa7359e8a7a8f8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package cn.iocoder.yudao.module.pay.framework.pay.core.client.dto.refund;
 
import cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum;
import cn.iocoder.yudao.module.pay.framework.pay.core.client.exception.PayClientException;
import lombok.Data;
 
import java.time.LocalDateTime;
 
/**
 * 渠道退款订单 Response DTO
 *
 * @author jason
 */
@Data
public class PayRefundRespDTO {
 
    /**
     * 退款状态
     *
     * 枚举 {@link PayRefundStatusEnum}
     */
    private Integer status;
 
    /**
     * 外部退款号
     *
     * 对应 PayRefundDO 的 no 字段
     */
    private String outRefundNo;
 
    /**
     * 渠道退款单号
     *
     * 对应 PayRefundDO.channelRefundNo 字段
     */
    private String channelRefundNo;
 
    /**
     * 退款成功时间
     */
    private LocalDateTime successTime;
 
    /**
     * 原始的异步通知结果
     */
    private Object rawData;
 
    /**
     * 调用渠道的错误码
     *
     * 注意:这里返回的是业务异常,而是不系统异常。
     * 如果是系统异常,则会抛出 {@link PayClientException}
     */
    private String channelErrorCode;
    /**
     * 调用渠道报错时,错误信息
     */
    private String channelErrorMsg;
 
    private PayRefundRespDTO() {
    }
 
    /**
     * 创建【WAITING】状态的退款返回
     */
    public static PayRefundRespDTO waitingOf(String channelRefundNo,
                                             String outRefundNo, Object rawData) {
        PayRefundRespDTO respDTO = new PayRefundRespDTO();
        respDTO.status = PayRefundStatusEnum.WAITING.getStatus();
        respDTO.channelRefundNo = channelRefundNo;
        // 相对通用的字段
        respDTO.outRefundNo = outRefundNo;
        respDTO.rawData = rawData;
        return respDTO;
    }
 
    /**
     * 创建【SUCCESS】状态的退款返回
     */
    public static PayRefundRespDTO successOf(String channelRefundNo, LocalDateTime successTime,
                                             String outRefundNo, Object rawData) {
        PayRefundRespDTO respDTO = new PayRefundRespDTO();
        respDTO.status = PayRefundStatusEnum.SUCCESS.getStatus();
        respDTO.channelRefundNo = channelRefundNo;
        respDTO.successTime = successTime;
        // 相对通用的字段
        respDTO.outRefundNo = outRefundNo;
        respDTO.rawData = rawData;
        return respDTO;
    }
 
    /**
     * 创建【FAILURE】状态的退款返回
     */
    public static PayRefundRespDTO failureOf(String outRefundNo, Object rawData) {
        return failureOf(null, null,
                outRefundNo, rawData);
    }
 
    /**
     * 创建【FAILURE】状态的退款返回
     */
    public static PayRefundRespDTO failureOf(String channelErrorCode, String channelErrorMsg,
                                             String outRefundNo, Object rawData) {
        PayRefundRespDTO respDTO = new PayRefundRespDTO();
        respDTO.status = PayRefundStatusEnum.FAILURE.getStatus();
        respDTO.channelErrorCode = channelErrorCode;
        respDTO.channelErrorMsg = channelErrorMsg;
        // 相对通用的字段
        respDTO.outRefundNo = outRefundNo;
        respDTO.rawData = rawData;
        return respDTO;
    }
 
}