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