forked from shenghui0779/sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
refund.go
184 lines (157 loc) · 4.96 KB
/
refund.go
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package mch
import (
"strconv"
"github.com/accaolei/gochat/wx"
)
// RefundData 退款数据
type RefundData struct {
// 必填参数
OutRefundNO string // 商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔
TotalFee int // 订单总金额,单位为分,只能为整数,详见支付金额
RefundFee int // 退款总金额,订单总金额,单位为分,只能为整数,详见支付金额
// 选填参数
RefundFeeType string // 货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
RefundDesc string // 若商户传入,会在下发给用户的退款消息中体现退款原因
RefundAccount string // 退款资金来源,仅针对老资金流商户使用
NotifyURL string // 异步接收微信支付退款结果通知的回调地址,通知URL必须为外网可访问的url,不允许带参数
}
// RefundByTransactionID 根据微信订单号退款
func RefundByTransactionID(transactionID string, data *RefundData) wx.Action {
return wx.NewAPI(RefundApplyURL,
wx.WithMethod(wx.MethodPost),
wx.WithTLS(),
wx.WithWXML(func(appid, mchid, nonce string) (wx.WXML, error) {
body := wx.WXML{
"appid": appid,
"mch_id": mchid,
"nonce_str": nonce,
"transaction_id": transactionID,
"out_refund_no": data.OutRefundNO,
"total_fee": strconv.Itoa(data.TotalFee),
"refund_fee": strconv.Itoa(data.RefundFee),
"sign_type": SignMD5,
}
if data.RefundFeeType != "" {
body["refund_fee_type"] = data.RefundFeeType
}
if data.RefundDesc != "" {
body["refund_desc"] = data.RefundDesc
}
if data.RefundAccount != "" {
body["refund_account"] = data.RefundAccount
}
if data.NotifyURL != "" {
body["notify_url"] = data.NotifyURL
}
return body, nil
}),
)
}
// RefundByOutTradeNO 根据商户订单号退款
func RefundByOutTradeNO(outTradeNO string, data *RefundData) wx.Action {
return wx.NewAPI(RefundApplyURL,
wx.WithMethod(wx.MethodPost),
wx.WithTLS(),
wx.WithWXML(func(appid, mchid, nonce string) (wx.WXML, error) {
body := wx.WXML{
"appid": appid,
"mch_id": mchid,
"nonce_str": nonce,
"out_trade_no": outTradeNO,
"out_refund_no": data.OutRefundNO,
"total_fee": strconv.Itoa(data.TotalFee),
"refund_fee": strconv.Itoa(data.RefundFee),
"sign_type": SignMD5,
}
if data.RefundFeeType != "" {
body["refund_fee_type"] = data.RefundFeeType
}
if data.RefundDesc != "" {
body["refund_desc"] = data.RefundDesc
}
if data.RefundAccount != "" {
body["refund_account"] = data.RefundAccount
}
if data.NotifyURL != "" {
body["notify_url"] = data.NotifyURL
}
return body, nil
}),
)
}
// QueryRefundByRefundID 根据微信退款单号查询退款信息
func QueryRefundByRefundID(refundID string, offset ...int) wx.Action {
return wx.NewAPI(RefundQueryURL,
wx.WithMethod(wx.MethodPost),
wx.WithWXML(func(appid, mchid, nonce string) (wx.WXML, error) {
body := wx.WXML{
"appid": appid,
"mch_id": mchid,
"refund_id": refundID,
"nonce_str": nonce,
"sign_type": SignMD5,
}
if len(offset) != 0 {
body["offset"] = strconv.Itoa(offset[0])
}
return body, nil
}),
)
}
// QueryRefundByOutRefundNO 根据商户退款单号查询退款信息
func QueryRefundByOutRefundNO(outRefundNO string, offset ...int) wx.Action {
return wx.NewAPI(RefundQueryURL,
wx.WithMethod(wx.MethodPost),
wx.WithWXML(func(appid, mchid, nonce string) (wx.WXML, error) {
body := wx.WXML{
"appid": appid,
"mch_id": mchid,
"out_refund_no": outRefundNO,
"nonce_str": nonce,
"sign_type": SignMD5,
}
if len(offset) != 0 {
body["offset"] = strconv.Itoa(offset[0])
}
return body, nil
}),
)
}
// QueryRefundByTransactionID 根据微信订单号查询退款信息
func QueryRefundByTransactionID(transactionID string, offset ...int) wx.Action {
return wx.NewAPI(RefundQueryURL,
wx.WithMethod(wx.MethodPost),
wx.WithWXML(func(appid, mchid, nonce string) (wx.WXML, error) {
body := wx.WXML{
"appid": appid,
"mch_id": mchid,
"transaction_id": transactionID,
"nonce_str": nonce,
"sign_type": SignMD5,
}
if len(offset) != 0 {
body["offset"] = strconv.Itoa(offset[0])
}
return body, nil
}),
)
}
// QueryRefundByOutTradeNO 根据商户订单号查询退款信息
func QueryRefundByOutTradeNO(outTradeNO string, offset ...int) wx.Action {
return wx.NewAPI(RefundQueryURL,
wx.WithMethod(wx.MethodPost),
wx.WithWXML(func(appid, mchid, nonce string) (wx.WXML, error) {
body := wx.WXML{
"appid": appid,
"mch_id": mchid,
"out_trade_no": outTradeNO,
"nonce_str": nonce,
"sign_type": SignMD5,
}
if len(offset) != 0 {
body["offset"] = strconv.Itoa(offset[0])
}
return body, nil
}),
)
}