申请退款
更新时间:2024.12.18当交易发生之后一年内(按支付成功时间+365天计算),由于用户或者商户原因需要退款时,商户可以通过申请退款接口将支付款退全额或部分还给用户。
注意:
1.一笔订单最多部分退款50次(多次部分退款需更换商户退款单号,间隔1分钟再调用)。
2.申请退款失败重试时请使用原商户退款单号,避免重复退款造成资损。
3.商户号维度调用成功频率限制150qps,错误或无效请求频率限制6qps。
4.申请退款接口返回成功仅代表退款单受理成功,具体退款结果以退款结果通知和查单退款返回为准。
5.一个月之前的订单申请退款如果返回报错"频率限制,1个月之前的订单请降低申请频率再重试",原参重试即可。
接口说明
支持商户:【普通商户】
请求方式:【POST】/v3/refund/domestic/refunds
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
Content-Type 必填 string
请设置为application/json
body 包体参数
transaction_id 选填 string(32)
【微信支付订单号】微信支付分扣款单的唯一标识,非0元结单且支付分渠道扣款成功后支付成功回调和查询支付分订单返回的收款信息明细collection.details中包含该字段。
transaction_id和out_trade_no二选一填写,建议商户都通过transaction_id申请退款。
out_trade_no 选填 string(32)
【商户订单号】支付分轮询扣款时生成的商户订单号,只能通过使用transaction_id调用基础支付查单接口获取。
transaction_id和out_trade_no二选一填写,建议商户都通过transaction_id申请退款。
out_refund_no 必填 string(64)
【商户退款单号】商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|@ ,同一退款单号多次请求只退一笔。
reason 选填 string(80)
【退款原因】若商户传入了退款原因,该字段将显示在用户接收到的退款消息通知中。
注意:若订单部分退款且退款金额≤1元,则不会在退款消息中体现退款原因。
notify_url 选填 string(256)
【退款结果回调url】商户异步接收退款结果通知的回调地址,通知url必须为外网可访问的url,不能携带参数,如果申请退款参数中传了notify_url,则商户平台上配置的退款回调地址将不会生效,优先回调当前传的这个地址。需按照notify-url填写注意事项规范填写。
funds_account 选填 string
【退款资金来源】若传递此参数则使用对应的资金账户退款,否则默认使用未结算资金退款(仅对老资金流商户适用)
可选取值:
AVAILABLE: 仅对老资金流商户适用,指定从可用余额账户出资
amount 必填 object
【金额信息】订单金额信息
属性 | |||||||
refund 必填 integer 【退款金额】申请退款时传的退款金额,整型,单位为分。 from 选填 array[object] 【退款出资账户及金额】申请退款时传的出资账户类型及出资金额。
total 必填 integer 【原订单金额】原支付交易的订单总金额,单位为分,只能为整数。 currency 必填 string(16) 【退款币种】固定传CNY,代表人民币。 |
goods_detail 选填 array[GoodsDetail]
【退款商品】指定商品退款需要传此参数,其他场景无需传递
属性 | |
merchant_goods_id 必填 string(32) 【商户侧商品编码】商品编码,由半角的大小写字母、数字、中划线、下划线中的一种或几种组成。 wechatpay_goods_id 选填 string(32) 【微信侧商品编码】微信支付定义的统一商品编号(没有可不传) goods_name 选填 string(256) 【商品名称】商品的实际名称 unit_price 必填 integer 【商品单价】商品单价金额,单位为分 refund_amount 必填 integer 【商品退款金额】商品退款金额,单位为分 refund_quantity 必填 integer 【商品退货数量】对应商品的退货数量 |
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/refund/domestic/refunds \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Content-Type: application/json" \ 6 -d '{ 7 "transaction_id" : "1217752501201407033233368018", 8 "out_trade_no" : "1217752501201407033233368018", 9 "out_refund_no" : "1217752501201407033233368018", 10 "reason" : "商品已售完", 11 "notify_url" : "https://weixin.qq.com", 12 "funds_account" : "AVAILABLE", 13 "amount" : { 14 "refund" : 888, 15 "from" : [ 16 { 17 "account" : "AVAILABLE", 18 "amount" : 444 19 } 20 ], 21 "total" : 888, 22 "currency" : "CNY" 23 }, 24 "goods_detail" : [ 25 { 26 "merchant_goods_id" : "1217752501201407033233368018", 27 "wechatpay_goods_id" : "1001", 28 "goods_name" : "iPhone6s 16G", 29 "unit_price" : 528800, 30 "refund_amount" : 528800, 31 "refund_quantity" : 1 32 } 33 ] 34 }'
需配合微信支付工具库 WXPayUtility 使用,请参考Java
1package com.java.demo; 2 3import com.java.utils.WXPayUtility; // 引用微信支付工具库,参考:https://pay.weixin.qq.com/doc/v3/merchant/4014931831 4 5import com.google.gson.annotations.SerializedName; 6import com.google.gson.annotations.Expose; 7import okhttp3.MediaType; 8import okhttp3.OkHttpClient; 9import okhttp3.Request; 10import okhttp3.RequestBody; 11import okhttp3.Response; 12 13import java.io.IOException; 14import java.io.UncheckedIOException; 15import java.security.PrivateKey; 16import java.security.PublicKey; 17import java.util.ArrayList; 18import java.util.HashMap; 19import java.util.List; 20import java.util.Map; 21 22/** 23 * 退款申请 24 */ 25public class Create { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "POST"; 28 private static String PATH = "/v3/refund/domestic/refunds"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/merchant/4013070756 32 Create client = new Create( 33 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/merchant/4013070756 34 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053 35 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 36 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816 37 "/path/to/wxp_pub.pem" // 微信支付公钥文件路径,本地文件路径 38 ); 39 40 CreateRequest request = new CreateRequest(); 41 request.transactionId = "1217752501201407033233368018"; 42 request.outTradeNo = "1217752501201407033233368018"; 43 request.outRefundNo = "1217752501201407033233368018"; 44 request.reason = "商品已售完"; 45 request.notifyUrl = "https://weixin.qq.com"; 46 request.fundsAccount = ReqFundsAccount.AVAILABLE; 47 request.amount = new AmountReq(); 48 request.amount.refund = 888L; 49 request.amount.from = new ArrayList<>(); 50 { 51 FundsFromItem fromItem = new FundsFromItem(); 52 fromItem.account = Account.AVAILABLE; 53 fromItem.amount = 444L; 54 request.amount.from.add(fromItem); 55 }; 56 request.amount.total = 888L; 57 request.amount.currency = "CNY"; 58 request.goodsDetail = new ArrayList<>(); 59 { 60 GoodsDetail goodsDetailItem = new GoodsDetail(); 61 goodsDetailItem.merchantGoodsId = "1217752501201407033233368018"; 62 goodsDetailItem.wechatpayGoodsId = "1001"; 63 goodsDetailItem.goodsName = "iPhone6s 16G"; 64 goodsDetailItem.unitPrice = 528800L; 65 goodsDetailItem.refundAmount = 528800L; 66 goodsDetailItem.refundQuantity = 1L; 67 request.goodsDetail.add(goodsDetailItem); 68 }; 69 try { 70 Refund response = client.run(request); 71 // TODO: 请求成功,继续业务逻辑 72 System.out.println(response); 73 } catch (WXPayUtility.ApiException e) { 74 // TODO: 请求失败,根据状态码执行不同的逻辑 75 e.printStackTrace(); 76 } 77 } 78 79 public Refund run(CreateRequest request) { 80 String uri = PATH; 81 String reqBody = WXPayUtility.toJson(request); 82 83 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 84 reqBuilder.addHeader("Accept", "application/json"); 85 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 86 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 87 reqBuilder.addHeader("Content-Type", "application/json"); 88 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 89 reqBuilder.method(METHOD, requestBody); 90 Request httpRequest = reqBuilder.build(); 91 92 // 发送HTTP请求 93 OkHttpClient client = new OkHttpClient.Builder().build(); 94 try (Response httpResponse = client.newCall(httpRequest).execute()) { 95 String respBody = WXPayUtility.extractBody(httpResponse); 96 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 97 // 2XX 成功,验证应答签名 98 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 99 httpResponse.headers(), respBody); 100 101 // 从HTTP应答报文构建返回数据 102 return WXPayUtility.fromJson(respBody, Refund.class); 103 } else { 104 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 105 } 106 } catch (IOException e) { 107 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 108 } 109 } 110 111 private final String mchid; 112 private final String certificateSerialNo; 113 private final PrivateKey privateKey; 114 private final String wechatPayPublicKeyId; 115 private final PublicKey wechatPayPublicKey; 116 117 public Create(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 118 this.mchid = mchid; 119 this.certificateSerialNo = certificateSerialNo; 120 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 121 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 122 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 123 } 124 125 public static class CreateRequest { 126 @SerializedName("transaction_id") 127 public String transactionId; 128 129 @SerializedName("out_trade_no") 130 public String outTradeNo; 131 132 @SerializedName("out_refund_no") 133 public String outRefundNo; 134 135 @SerializedName("reason") 136 public String reason; 137 138 @SerializedName("notify_url") 139 public String notifyUrl; 140 141 @SerializedName("funds_account") 142 public ReqFundsAccount fundsAccount; 143 144 @SerializedName("amount") 145 public AmountReq amount; 146 147 @SerializedName("goods_detail") 148 public List<GoodsDetail> goodsDetail; 149 150 } 151 152 public static class Refund { 153 @SerializedName("refund_id") 154 public String refundId; 155 156 @SerializedName("out_refund_no") 157 public String outRefundNo; 158 159 @SerializedName("transaction_id") 160 public String transactionId; 161 162 @SerializedName("out_trade_no") 163 public String outTradeNo; 164 165 @SerializedName("channel") 166 public Channel channel; 167 168 @SerializedName("user_received_account") 169 public String userReceivedAccount; 170 171 @SerializedName("success_time") 172 public String successTime; 173 174 @SerializedName("create_time") 175 public String createTime; 176 177 @SerializedName("status") 178 public Status status; 179 180 @SerializedName("funds_account") 181 public FundsAccount fundsAccount; 182 183 @SerializedName("amount") 184 public Amount amount; 185 186 @SerializedName("promotion_detail") 187 public List<Promotion> promotionDetail; 188 189 } 190 191 public enum ReqFundsAccount { 192 @SerializedName("AVAILABLE") 193 AVAILABLE, 194 @SerializedName("UNSETTLED") 195 UNSETTLED 196 } 197 198 public static class AmountReq { 199 @SerializedName("refund") 200 public Long refund; 201 202 @SerializedName("from") 203 public List<FundsFromItem> from; 204 205 @SerializedName("total") 206 public Long total; 207 208 @SerializedName("currency") 209 public String currency; 210 } 211 212 public static class GoodsDetail { 213 @SerializedName("merchant_goods_id") 214 public String merchantGoodsId; 215 216 @SerializedName("wechatpay_goods_id") 217 public String wechatpayGoodsId; 218 219 @SerializedName("goods_name") 220 public String goodsName; 221 222 @SerializedName("unit_price") 223 public Long unitPrice; 224 225 @SerializedName("refund_amount") 226 public Long refundAmount; 227 228 @SerializedName("refund_quantity") 229 public Long refundQuantity; 230 } 231 232 233 public enum Channel { 234 @SerializedName("ORIGINAL") 235 ORIGINAL, 236 @SerializedName("BALANCE") 237 BALANCE, 238 @SerializedName("OTHER_BALANCE") 239 OTHER_BALANCE, 240 @SerializedName("OTHER_BANKCARD") 241 OTHER_BANKCARD 242 } 243 244 public enum Status { 245 @SerializedName("SUCCESS") 246 SUCCESS, 247 @SerializedName("CLOSED") 248 CLOSED, 249 @SerializedName("PROCESSING") 250 PROCESSING, 251 @SerializedName("ABNORMAL") 252 ABNORMAL 253 } 254 255 public enum FundsAccount { 256 @SerializedName("UNSETTLED") 257 UNSETTLED, 258 @SerializedName("AVAILABLE") 259 AVAILABLE, 260 @SerializedName("UNAVAILABLE") 261 UNAVAILABLE, 262 @SerializedName("OPERATION") 263 OPERATION, 264 @SerializedName("BASIC") 265 BASIC, 266 @SerializedName("ECNY_BASIC") 267 ECNY_BASIC 268 } 269 270 public static class Amount { 271 @SerializedName("total") 272 public Long total; 273 274 @SerializedName("refund") 275 public Long refund; 276 277 @SerializedName("from") 278 public List<FundsFromItem> from; 279 280 @SerializedName("payer_total") 281 public Long payerTotal; 282 283 @SerializedName("payer_refund") 284 public Long payerRefund; 285 286 @SerializedName("settlement_refund") 287 public Long settlementRefund; 288 289 @SerializedName("settlement_total") 290 public Long settlementTotal; 291 292 @SerializedName("discount_refund") 293 public Long discountRefund; 294 295 @SerializedName("currency") 296 public String currency; 297 298 @SerializedName("refund_fee") 299 public Long refundFee; 300 } 301 302 public static class Promotion { 303 @SerializedName("promotion_id") 304 public String promotionId; 305 306 @SerializedName("scope") 307 public PromotionScope scope; 308 309 @SerializedName("type") 310 public PromotionType type; 311 312 @SerializedName("amount") 313 public Long amount; 314 315 @SerializedName("refund_amount") 316 public Long refundAmount; 317 318 @SerializedName("goods_detail") 319 public List<GoodsDetail> goodsDetail; 320 } 321 322 public static class FundsFromItem { 323 @SerializedName("account") 324 public Account account; 325 326 @SerializedName("amount") 327 public Long amount; 328 } 329 330 public enum PromotionScope { 331 @SerializedName("GLOBAL") 332 GLOBAL, 333 @SerializedName("SINGLE") 334 SINGLE 335 } 336 337 public enum PromotionType { 338 @SerializedName("CASH") 339 CASH, 340 @SerializedName("NOCASH") 341 NOCASH 342 } 343 344 public enum Account { 345 @SerializedName("AVAILABLE") 346 AVAILABLE, 347 @SerializedName("UNAVAILABLE") 348 UNAVAILABLE 349 } 350 351}
需配合微信支付工具库 wxpay_utility 使用,请参考Go
1package main 2 3import ( 4 "bytes" 5 "demo/wxpay_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/v3/merchant/4015119334 6 "encoding/json" 7 "fmt" 8 "net/http" 9 "net/url" 10 "time" 11) 12 13func main() { 14 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/merchant/4013070756 15 config, err := wxpay_utility.CreateMchConfig( 16 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/merchant/4013070756 17 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053 18 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 19 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816 20 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 21 ) 22 if err != nil { 23 fmt.Println(err) 24 return 25 } 26 27 request := &CreateRequest{ 28 TransactionId: wxpay_utility.String("1217752501201407033233368018"), 29 OutTradeNo: wxpay_utility.String("1217752501201407033233368018"), 30 OutRefundNo: wxpay_utility.String("1217752501201407033233368018"), 31 Reason: wxpay_utility.String("商品已售完"), 32 NotifyUrl: wxpay_utility.String("https://weixin.qq.com"), 33 FundsAccount: REQFUNDSACCOUNT_AVAILABLE.Ptr(), 34 Amount: &AmountReq{ 35 Refund: wxpay_utility.Int64(888), 36 From: []FundsFromItem{FundsFromItem{ 37 Account: ACCOUNT_AVAILABLE.Ptr(), 38 Amount: wxpay_utility.Int64(444), 39 }}, 40 Total: wxpay_utility.Int64(888), 41 Currency: wxpay_utility.String("CNY"), 42 }, 43 GoodsDetail: []GoodsDetail{GoodsDetail{ 44 MerchantGoodsId: wxpay_utility.String("1217752501201407033233368018"), 45 WechatpayGoodsId: wxpay_utility.String("1001"), 46 GoodsName: wxpay_utility.String("iPhone6s 16G"), 47 UnitPrice: wxpay_utility.Int64(528800), 48 RefundAmount: wxpay_utility.Int64(528800), 49 RefundQuantity: wxpay_utility.Int64(1), 50 }}, 51 } 52 53 response, err := Create(config, request) 54 if err != nil { 55 fmt.Printf("请求失败: %+v\n", err) 56 // TODO: 请求失败,根据状态码执行不同的处理 57 return 58 } 59 60 // TODO: 请求成功,继续业务逻辑 61 fmt.Printf("请求成功: %+v\n", response) 62} 63 64func Create(config *wxpay_utility.MchConfig, request *CreateRequest) (response *Refund, err error) { 65 const ( 66 host = "https://api.mch.weixin.qq.com" 67 method = "POST" 68 path = "/v3/refund/domestic/refunds" 69 ) 70 71 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 72 if err != nil { 73 return nil, err 74 } 75 reqBody, err := json.Marshal(request) 76 if err != nil { 77 return nil, err 78 } 79 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 80 if err != nil { 81 return nil, err 82 } 83 httpRequest.Header.Set("Accept", "application/json") 84 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 85 httpRequest.Header.Set("Content-Type", "application/json") 86 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 87 if err != nil { 88 return nil, err 89 } 90 httpRequest.Header.Set("Authorization", authorization) 91 92 client := &http.Client{} 93 httpResponse, err := client.Do(httpRequest) 94 if err != nil { 95 return nil, err 96 } 97 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 98 if err != nil { 99 return nil, err 100 } 101 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 102 // 2XX 成功,验证应答签名 103 err = wxpay_utility.ValidateResponse( 104 config.WechatPayPublicKeyId(), 105 config.WechatPayPublicKey(), 106 &httpResponse.Header, 107 respBody, 108 ) 109 if err != nil { 110 return nil, err 111 } 112 response := &Refund{} 113 if err := json.Unmarshal(respBody, response); err != nil { 114 return nil, err 115 } 116 117 return response, nil 118 } else { 119 return nil, wxpay_utility.NewApiException( 120 httpResponse.StatusCode, 121 httpResponse.Header, 122 respBody, 123 ) 124 } 125} 126 127type CreateRequest struct { 128 TransactionId *string `json:"transaction_id,omitempty"` 129 OutTradeNo *string `json:"out_trade_no,omitempty"` 130 OutRefundNo *string `json:"out_refund_no,omitempty"` 131 Reason *string `json:"reason,omitempty"` 132 NotifyUrl *string `json:"notify_url,omitempty"` 133 FundsAccount *ReqFundsAccount `json:"funds_account,omitempty"` 134 Amount *AmountReq `json:"amount,omitempty"` 135 GoodsDetail []GoodsDetail `json:"goods_detail,omitempty"` 136} 137 138type Refund struct { 139 RefundId *string `json:"refund_id,omitempty"` 140 OutRefundNo *string `json:"out_refund_no,omitempty"` 141 TransactionId *string `json:"transaction_id,omitempty"` 142 OutTradeNo *string `json:"out_trade_no,omitempty"` 143 Channel *Channel `json:"channel,omitempty"` 144 UserReceivedAccount *string `json:"user_received_account,omitempty"` 145 SuccessTime *time.Time `json:"success_time,omitempty"` 146 CreateTime *time.Time `json:"create_time,omitempty"` 147 Status *Status `json:"status,omitempty"` 148 FundsAccount *FundsAccount `json:"funds_account,omitempty"` 149 Amount *Amount `json:"amount,omitempty"` 150 PromotionDetail []Promotion `json:"promotion_detail,omitempty"` 151} 152 153type ReqFundsAccount string 154 155func (e ReqFundsAccount) Ptr() *ReqFundsAccount { 156 return &e 157} 158 159const ( 160 REQFUNDSACCOUNT_AVAILABLE ReqFundsAccount = "AVAILABLE" 161 REQFUNDSACCOUNT_UNSETTLED ReqFundsAccount = "UNSETTLED" 162) 163 164type AmountReq struct { 165 Refund *int64 `json:"refund,omitempty"` 166 From []FundsFromItem `json:"from,omitempty"` 167 Total *int64 `json:"total,omitempty"` 168 Currency *string `json:"currency,omitempty"` 169} 170 171type GoodsDetail struct { 172 MerchantGoodsId *string `json:"merchant_goods_id,omitempty"` 173 WechatpayGoodsId *string `json:"wechatpay_goods_id,omitempty"` 174 GoodsName *string `json:"goods_name,omitempty"` 175 UnitPrice *int64 `json:"unit_price,omitempty"` 176 RefundAmount *int64 `json:"refund_amount,omitempty"` 177 RefundQuantity *int64 `json:"refund_quantity,omitempty"` 178} 179 180type Channel string 181 182func (e Channel) Ptr() *Channel { 183 return &e 184} 185 186const ( 187 CHANNEL_ORIGINAL Channel = "ORIGINAL" 188 CHANNEL_BALANCE Channel = "BALANCE" 189 CHANNEL_OTHER_BALANCE Channel = "OTHER_BALANCE" 190 CHANNEL_OTHER_BANKCARD Channel = "OTHER_BANKCARD" 191) 192 193type Status string 194 195func (e Status) Ptr() *Status { 196 return &e 197} 198 199const ( 200 STATUS_SUCCESS Status = "SUCCESS" 201 STATUS_CLOSED Status = "CLOSED" 202 STATUS_PROCESSING Status = "PROCESSING" 203 STATUS_ABNORMAL Status = "ABNORMAL" 204) 205 206type FundsAccount string 207 208func (e FundsAccount) Ptr() *FundsAccount { 209 return &e 210} 211 212const ( 213 FUNDSACCOUNT_UNSETTLED FundsAccount = "UNSETTLED" 214 FUNDSACCOUNT_AVAILABLE FundsAccount = "AVAILABLE" 215 FUNDSACCOUNT_UNAVAILABLE FundsAccount = "UNAVAILABLE" 216 FUNDSACCOUNT_OPERATION FundsAccount = "OPERATION" 217 FUNDSACCOUNT_BASIC FundsAccount = "BASIC" 218 FUNDSACCOUNT_ECNY_BASIC FundsAccount = "ECNY_BASIC" 219) 220 221type Amount struct { 222 Total *int64 `json:"total,omitempty"` 223 Refund *int64 `json:"refund,omitempty"` 224 From []FundsFromItem `json:"from,omitempty"` 225 PayerTotal *int64 `json:"payer_total,omitempty"` 226 PayerRefund *int64 `json:"payer_refund,omitempty"` 227 SettlementRefund *int64 `json:"settlement_refund,omitempty"` 228 SettlementTotal *int64 `json:"settlement_total,omitempty"` 229 DiscountRefund *int64 `json:"discount_refund,omitempty"` 230 Currency *string `json:"currency,omitempty"` 231 RefundFee *int64 `json:"refund_fee,omitempty"` 232} 233 234type Promotion struct { 235 PromotionId *string `json:"promotion_id,omitempty"` 236 Scope *PromotionScope `json:"scope,omitempty"` 237 Type *PromotionType `json:"type,omitempty"` 238 Amount *int64 `json:"amount,omitempty"` 239 RefundAmount *int64 `json:"refund_amount,omitempty"` 240 GoodsDetail []GoodsDetail `json:"goods_detail,omitempty"` 241} 242 243type FundsFromItem struct { 244 Account *Account `json:"account,omitempty"` 245 Amount *int64 `json:"amount,omitempty"` 246} 247 248type PromotionScope string 249 250func (e PromotionScope) Ptr() *PromotionScope { 251 return &e 252} 253 254const ( 255 PROMOTIONSCOPE_GLOBAL PromotionScope = "GLOBAL" 256 PROMOTIONSCOPE_SINGLE PromotionScope = "SINGLE" 257) 258 259type PromotionType string 260 261func (e PromotionType) Ptr() *PromotionType { 262 return &e 263} 264 265const ( 266 PROMOTIONTYPE_CASH PromotionType = "CASH" 267 PROMOTIONTYPE_NOCASH PromotionType = "NOCASH" 268) 269 270type Account string 271 272func (e Account) Ptr() *Account { 273 return &e 274} 275 276const ( 277 ACCOUNT_AVAILABLE Account = "AVAILABLE" 278 ACCOUNT_UNAVAILABLE Account = "UNAVAILABLE" 279)
应答参数
|
refund_id 必填 string(32)
【微信支付退款号】微信侧返回的退款单唯一标识,由数字组成,50或52开头。
out_refund_no 必填 string(64)
【商户退款单号】商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|@ ,同一退款单号多次请求只退一笔。
transaction_id 必填 string(32)
out_trade_no 必填 string(32)
【商户订单号】支付分轮询扣款时生成的商户订单号。
channel 必填 string
【退款渠道】本单资金实际的退款渠道。
可选取值:
ORIGINAL: 原路退款
BALANCE: 退回到余额
OTHER_BALANCE: 原账户异常退到其他余额账户
OTHER_BANKCARD: 原银行卡异常退到其他银行卡
user_received_account 必填 string(64)
【退款入账账户】
退款单入账方。
取值有以下几种情况
退回银行卡:{银行名称}{卡类型}{卡尾号}
退回支付用户零钱:支付用户零钱
退还商户:商户基本账户商户结算银行账户
退回支付用户零钱通:支付用户零钱通
退回支付用户银行电子账户:支付用户银行电子账户
退回支付用户零花钱:支付用户零花钱
退回用户经营账户:用户经营账户
退回支付用户来华零钱包:支付用户来华零钱包
退回企业支付商户:企业支付商户
退回支付用户小金罐:支付用户小金罐
success_time 选填 string(64)
【退款成功时间】退款成功时间,退款状态status为SUCCESS(退款成功)时,返回该字段。遵循rfc3339标准格式,格式为YYYY-MM-DDTHH:mm:ss+TIMEZONE,YYYY-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日13点29分35秒。
create_time 必填 string(64)
【退款创建时间】退款受理时间,遵循rfc3339标准格式,格式为YYYY-MM-DDTHH:mm:ss+TIMEZONE,YYYY-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日13点29分35秒。
status 必填 string
【退款状态】退款单状态。
可选取值:
SUCCESS: 退款成功
CLOSED: 退款关闭
PROCESSING: 退款处理中
ABNORMAL: 退款异常,需商户平台手动处理,参考交易退款方法介绍。
funds_account 选填 string
【资金账户】退款所使用资金对应的资金账户类型
可选取值:
UNSETTLED: 未结算资金
AVAILABLE: 可用余额
UNAVAILABLE: 不可用余额
OPERATION: 运营户
BASIC: 基本账户(含可用余额和不可用余额)
ECNY_BASIC: 数字人民币基本账户
amount 必填 object
【金额信息】金额详细信息
属性 | |||||||
total 必填 integer 【订单金额】订单总金额,单位为分 refund 必填 integer 【退款金额】申请退款时传的退款金额,整型,单位为分。 from 选填 array[object] 【退款出资账户及金额】申请退款时传的出资账户类型及出资金额。
payer_total 必填 integer 【用户支付金额】用户现金支付金额,整型,单位为分,例如10元订单用户使用了2元代金券,则该金额为用户实际支付的8元。 payer_refund 必填 integer 【用户退款金额】指用户实际收到的现金退款金额,数据类型为整型,单位为分。例如在一个10元的订单中,用户使用了2元的代金券,若商户申请退款5元,则用户将收到4元的现金退款(即该字段所示金额)和1元的代金券退款。 settlement_refund 必填 integer 【应结退款金额】去掉免充值代金券退款金额后的退款金额,整型,单位为分,例如10元订单用户使用了2元代金券(一张免充值1元 + 一张预充值1元),商户申请退款5元,则该金额为 退款金额5元 - 0.5元免充值代金券退款金额 = 4.5元。 settlement_total 必填 integer 【应结订单金额】去除免充值代金券金额后的订单金额,整型,单位为分,例如10元订单用户使用了2元代金券(一张免充值1元 + 一张预充值1元),则该金额为 订单金额10元 - 免充值代金券金额1元 = 9元。 discount_refund 必填 integer 【优惠退款金额】申请退款后用户收到的代金券退款金额,整型,单位为分,例如10元订单用户使用了2元代金券,商户申请退款5元,用户收到的是4元现金 + 1元代金券退款金额(该字段) 。 currency 必填 string(16) 【退款币种】固定值CNY,代表人民币。 refund_fee 选填 integer 【手续费退款金额】订单退款时退还的手续费金额,整型,单位为分,例如一笔100元的订单收了0.6元手续费,商户申请退款50元,该金额为等比退还的0.3元手续费。 |
promotion_detail 选填 array[object]
【优惠退款信息】代金券信息,当订单支付时,有使用代金券时,该字段将返回所使用的代金券信息。
属性 | |||||||
promotion_id 必填 string(32) 【券ID】券或者立减优惠id scope 必填 string 【优惠范围】优惠活动中代金券的适用范围,分为两种类型:
type 必填 string 【优惠类型】代金券资金类型,优惠活动中代金券的结算资金类型,分为两种类型:
amount 必填 integer 【优惠券面额】代金券优惠的金额 refund_amount 必填 integer 【优惠退款金额】优惠退款金额<=退款金额,退款金额-代金券或立减优惠退款金额为用户支付的现金,说明详见代金券或立减优惠,单位为分 goods_detail 选填 array[object] 【商品列表】单品列表
|
应答示例
|
1{ 2 "refund_id" : "50000000382019052709732678859", 3 "out_refund_no" : "1217752501201407033233368018", 4 "transaction_id" : "1217752501201407033233368018", 5 "out_trade_no" : "1217752501201407033233368018", 6 "channel" : "ORIGINAL", 7 "user_received_account" : "招商银行信用卡0403", 8 "success_time" : "2020-12-01T16:18:12+08:00", 9 "create_time" : "2020-12-01T16:18:12+08:00", 10 "status" : "SUCCESS", 11 "funds_account" : "UNSETTLED", 12 "amount" : { 13 "total" : 100, 14 "refund" : 100, 15 "from" : [ 16 { 17 "account" : "AVAILABLE", 18 "amount" : 444 19 } 20 ], 21 "payer_total" : 90, 22 "payer_refund" : 90, 23 "settlement_refund" : 100, 24 "settlement_total" : 100, 25 "discount_refund" : 10, 26 "currency" : "CNY", 27 "refund_fee" : 100 28 }, 29 "promotion_detail" : [ 30 { 31 "promotion_id" : "109519", 32 "scope" : "GLOBAL", 33 "type" : "COUPON", 34 "amount" : 5, 35 "refund_amount" : 100, 36 "goods_detail" : [ 37 { 38 "merchant_goods_id" : "1217752501201407033233368018", 39 "wechatpay_goods_id" : "1001", 40 "goods_name" : "iPhone6s 16G", 41 "unit_price" : 528800, 42 "refund_amount" : 528800, 43 "refund_quantity" : 1 44 } 45 ] 46 } 47 ] 48}
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
业务错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | INVALID_REQUEST | 请求参数符合参数格式,但不符合业务规则 | 此状态代表退款申请失败,商户可根据具体的错误提示做相应的处理。 |
401 | SIGN_ERROR | 签名错误 | 请检查签名参数和方法是否都符合签名算法要求 |
403 | NO_AUTH | 没有退款权限 | 此状态代表退款申请失败,请检查是否有该笔订单的退款权限 |
403 | NOT_ENOUGH | 余额不足 | 此状态代表退款申请失败,商户可根据具体的错误提示做相应的处理。 |
403 | USER_ACCOUNT_ABNORMAL | 退款请求失败 | 此状态代表退款申请失败,商户可自行处理退款。 |
404 | MCH_NOT_EXISTS | MCHID不存在 | 请检查MCHID是否正确 |
404 | RESOURCE_NOT_EXISTS | 订单号不存在 | 请检查你的订单号是否正确且是否已支付,未支付的订单不能发起退款 |
429 | FREQUENCY_LIMITED | 频率限制 | 该笔退款为受理中,请调用查单接口确认或降低频率原单重试,重试请勿更换单号 |
500 | SYSTEM_ERROR | 系统超时 | 请不要更换商户退款单号,请使用相同参数再次调用API。 |