修改支付分订单金额
更新时间:2024.12.06订单collection.state为USER_PAYING待支付状态时,商户可调用该接口下调收款金额。
|
接口说明
支持商户:【普通服务商】
请求方式:【POST】/v3/payscore/partner/serviceorder/{out_order_no}/modify
请求域名:【主域名】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
path 路径参数
out_order_no 必填 string(32)
【商户服务订单号】 商户系统内部服务订单号,要求32个字符内,只能是数字、大小写字母_-|* 且在同一个商户号下唯一。需要开发者特别注意,该参数不可用于申请退款接口中的 out_trade_no 参数。
body 包体参数
service_id 选填 string(32)
【服务ID】 商户支付分服务的唯一标识,由32位数字组成。支付分产品权限审核通过后,微信支付运营会向商户提供该ID。
sub_mchid 必填 string(32)
【子商户号】服务商下的子商户商户号,普通服务商使用特约商户进件生成,平台收付通服务商使用二级商户进件生成。
post_payments 必填 array[Payment]
【后付费项目】 用于展示订单后付费项目明细,商户需要按照所属行业规程传参,详见post_payments(后付费项目)字段传参说明。
属性 | |
name 选填 string(20) 【付费名称】 不能超过20个字符,需严格按照post_payments(后付费项目)字段传参说明传参。 amount 选填 integer 【付费金额】 付费项目金额,整型,大于等于0(等于0时表示不需要扣费),单位为分,需严格按照post_payments(后付费项目)字段传参说明传参。 description 选填 string(30) 【付费说明】 对付费项目的详细说明,不超过30个字符,需严格按照post_payments(后付费项目)字段传参说明传参。 count 选填 integer 【付费数量】 后付费项目的数量,为整型。相同的后付费项目建议合并计算amount和count。 |
post_discounts 选填 array[ServiceOrderCoupon]
【商户优惠】 用于展示订单优惠项目明细,最多30条,完结订单时传的收款总金额需满足计算条件(收款总金额=后付费项目amount和-优惠项目amount和)
属性 | |
name 选填 string(20) 【优惠名称】 用于描述优惠项目,不超过20个字符,同一单多个优惠项目名称不可重复。 description 选填 string(30) 【优惠说明】 用于描述优惠项目使用条件,不超过30个字符。 amount 选填 integer 【优惠金额】 整型,单位为分,用于描述优惠项目金额。 count 选填 integer 【优惠数量】 整型,用于描述优惠项目使用数量,例如用户使用了两张同一活动优惠券,则count填2。 |
total_amount 必填 integer
【总金额】
订单最终收款总金额,整型,单位为分,商户调用完结订单接口和修改订单金额接口传入,受服务ID风险金额上限影响,服务ID风险金额上限具体请与BD确认。
先免模式:total_amount<=创单risk_fund.amount(押金金额)<=服务ID风险金额上限。
先享模式:total_amount<=服务ID风险金额上限。
需满足计算条件:total_amount = 后付费项目金额(post_payments.amount总和) - 优惠项目金额(post_discounts.amount总和),例如商户后付费项目金额总和为10元,优惠项目金额总和为2元,则订单收款总金额为8元。
reason 必填 string(50)
【修改原因】 支付分修改订单原因,长度不能超过50个字符。
device 选填 object
【设备信息】
属性 | |
start_device_id 选填 string(50) 【服务开始的设备ID】 某一设备在商户对应服务ID下的唯一标识,由商户自行填写,建议采用设备SN值。售货机、充电宝、充电桩等无人自助设备行业必传。 end_device_id 选填 string(50) 【服务结束的设备ID】 某一设备在商户对应服务ID下的唯一标识,由商户自行填写,建议采用设备SN值。售货机、充电宝、充电桩等无人自助设备行业必传。 materiel_no 选填 string(100) 【物料编码】 若商家参与政策,则商家填写行业侧给到商家的物料码(字母+数字的形式);若商家未参与政策,则商家填写URL链接。 |
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/payscore/partner/serviceorder/1234323JKHDFE1243252/modify \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Content-Type: application/json" \ 6 -d '{ 7 "service_id" : "2002000000000558128851361561536", 8 "sub_mchid" : "1900000109", 9 "post_payments" : [ 10 { 11 "name" : "就餐费用", 12 "amount" : 40000, 13 "description" : "就餐人均100元", 14 "count" : 4 15 } 16 ], 17 "post_discounts" : [ 18 { 19 "name" : "满20减1元", 20 "description" : "不与其他优惠叠加", 21 "amount" : 100 22 } 23 ], 24 "total_amount" : 50000, 25 "reason" : "用户投诉", 26 "device" : { 27 "start_device_id" : "HG123456", 28 "end_device_id" : "HG123456", 29 "materiel_no" : "example_materiel_no" 30 } 31 }' 32
需配合微信支付工具库 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 ModifyPartnerServiceOrder { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "POST"; 28 private static String PATH = "/v3/payscore/partner/serviceorder/{out_order_no}/modify"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 ModifyPartnerServiceOrder client = new ModifyPartnerServiceOrder( 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 ModifyPartnerServiceOrderRequest request = new ModifyPartnerServiceOrderRequest(); 41 request.outOrderNo = "1234323JKHDFE1243252"; 42 request.serviceId = "2002000000000558128851361561536"; 43 request.subMchid = "1900000109"; 44 request.postPayments = new ArrayList<>(); 45 { 46 Payment postPaymentsItem = new Payment(); 47 postPaymentsItem.name = "就餐费用"; 48 postPaymentsItem.amount = 40000L; 49 postPaymentsItem.description = "就餐人均100元"; 50 postPaymentsItem.count = 4L; 51 request.postPayments.add(postPaymentsItem); 52 }; 53 request.postDiscounts = new ArrayList<>(); 54 { 55 ServiceOrderCoupon postDiscountsItem = new ServiceOrderCoupon(); 56 postDiscountsItem.name = "满20减1元"; 57 postDiscountsItem.description = "不与其他优惠叠加"; 58 postDiscountsItem.amount = 100L; 59 request.postDiscounts.add(postDiscountsItem); 60 }; 61 request.totalAmount = 50000L; 62 request.reason = "用户投诉"; 63 request.device = new Device(); 64 request.device.startDeviceId = "HG123456"; 65 request.device.endDeviceId = "HG123456"; 66 request.device.materielNo = "example_materiel_no"; 67 try { 68 client.run(request); 69 } catch (WXPayUtility.ApiException e) { 70 // TODO: 请求失败,根据状态码执行不同的逻辑 71 e.printStackTrace(); 72 } 73 } 74 75 public void run(ModifyPartnerServiceOrderRequest request) { 76 String uri = PATH; 77 uri = uri.replace("{out_order_no}", WXPayUtility.urlEncode(request.outOrderNo)); 78 String reqBody = WXPayUtility.toJson(request); 79 80 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 81 reqBuilder.addHeader("Accept", "application/json"); 82 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 83 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 84 reqBuilder.addHeader("Content-Type", "application/json"); 85 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 86 reqBuilder.method(METHOD, requestBody); 87 Request httpRequest = reqBuilder.build(); 88 89 // 发送HTTP请求 90 OkHttpClient client = new OkHttpClient.Builder().build(); 91 try (Response httpResponse = client.newCall(httpRequest).execute()) { 92 String respBody = WXPayUtility.extractBody(httpResponse); 93 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 94 // 2XX 成功,验证应答签名 95 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 96 httpResponse.headers(), respBody); 97 98 return; 99 } else { 100 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 101 } 102 } catch (IOException e) { 103 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 104 } 105 } 106 107 private final String mchid; 108 private final String certificateSerialNo; 109 private final PrivateKey privateKey; 110 private final String wechatPayPublicKeyId; 111 private final PublicKey wechatPayPublicKey; 112 113 public ModifyPartnerServiceOrder(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 114 this.mchid = mchid; 115 this.certificateSerialNo = certificateSerialNo; 116 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 117 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 118 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 119 } 120 121 public static class ModifyPartnerServiceOrderRequest { 122 @SerializedName("service_id") 123 public String serviceId; 124 125 @SerializedName("sub_mchid") 126 public String subMchid; 127 128 @SerializedName("out_order_no") 129 @Expose(serialize = false) 130 public String outOrderNo; 131 132 @SerializedName("post_payments") 133 public List<Payment> postPayments = new ArrayList<Payment>(); 134 135 @SerializedName("post_discounts") 136 public List<ServiceOrderCoupon> postDiscounts; 137 138 @SerializedName("total_amount") 139 public Long totalAmount; 140 141 @SerializedName("reason") 142 public String reason; 143 144 @SerializedName("device") 145 public Device device; 146 } 147 148 public static class Payment { 149 @SerializedName("name") 150 public String name; 151 152 @SerializedName("amount") 153 public Long amount; 154 155 @SerializedName("description") 156 public String description; 157 158 @SerializedName("count") 159 public Long count; 160 } 161 162 public static class ServiceOrderCoupon { 163 @SerializedName("name") 164 public String name; 165 166 @SerializedName("description") 167 public String description; 168 169 @SerializedName("amount") 170 public Long amount; 171 } 172 173 public static class Device { 174 @SerializedName("start_device_id") 175 public String startDeviceId; 176 177 @SerializedName("end_device_id") 178 public String endDeviceId; 179 180 @SerializedName("materiel_no") 181 public String materielNo; 182 } 183 184} 185
需配合微信支付工具库 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 "strings" 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 := &ModifyPartnerServiceOrderRequest{ 28 OutOrderNo: wxpay_utility.String("1234323JKHDFE1243252"), 29 ServiceId: wxpay_utility.String("2002000000000558128851361561536"), 30 SubMchid: wxpay_utility.String("1900000109"), 31 PostPayments: []Payment{Payment{ 32 Name: wxpay_utility.String("就餐费用"), 33 Amount: wxpay_utility.Int64(40000), 34 Description: wxpay_utility.String("就餐人均100元"), 35 Count: wxpay_utility.Int64(4), 36 }}, 37 PostDiscounts: []ServiceOrderCoupon{ServiceOrderCoupon{ 38 Name: wxpay_utility.String("满20减1元"), 39 Description: wxpay_utility.String("不与其他优惠叠加"), 40 Amount: wxpay_utility.Int64(100), 41 }}, 42 TotalAmount: wxpay_utility.Int64(50000), 43 Reason: wxpay_utility.String("用户投诉"), 44 Device: &Device{ 45 StartDeviceId: wxpay_utility.String("HG123456"), 46 EndDeviceId: wxpay_utility.String("HG123456"), 47 MaterielNo: wxpay_utility.String("example_materiel_no"), 48 }, 49 } 50 51 err = ModifyPartnerServiceOrder(config, request) 52 if err != nil { 53 fmt.Printf("请求失败: %+v\n", err) 54 // TODO: 请求失败,根据状态码执行不同的处理 55 return 56 } 57 58 // TODO: 请求成功,继续业务逻辑 59 fmt.Println("请求成功") 60} 61 62func ModifyPartnerServiceOrder(config *wxpay_utility.MchConfig, request *ModifyPartnerServiceOrderRequest) (err error) { 63 const ( 64 host = "https://api.mch.weixin.qq.com" 65 method = "POST" 66 path = "/v3/payscore/partner/serviceorder/{out_order_no}/modify" 67 ) 68 69 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 70 if err != nil { 71 return err 72 } 73 reqUrl.Path = strings.Replace(reqUrl.Path, "{out_order_no}", url.PathEscape(*request.OutOrderNo), -1) 74 reqBody, err := json.Marshal(request) 75 if err != nil { 76 return err 77 } 78 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 79 if err != nil { 80 return err 81 } 82 httpRequest.Header.Set("Accept", "application/json") 83 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 84 httpRequest.Header.Set("Content-Type", "application/json") 85 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 86 if err != nil { 87 return err 88 } 89 httpRequest.Header.Set("Authorization", authorization) 90 91 client := &http.Client{} 92 httpResponse, err := client.Do(httpRequest) 93 if err != nil { 94 return err 95 } 96 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 97 if err != nil { 98 return err 99 } 100 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 101 // 2XX 成功,验证应答签名 102 err = wxpay_utility.ValidateResponse( 103 config.WechatPayPublicKeyId(), 104 config.WechatPayPublicKey(), 105 &httpResponse.Header, 106 respBody, 107 ) 108 if err != nil { 109 return err 110 } 111 return nil 112 } else { 113 return wxpay_utility.NewApiException( 114 httpResponse.StatusCode, 115 httpResponse.Header, 116 respBody, 117 ) 118 } 119} 120 121type ModifyPartnerServiceOrderRequest struct { 122 ServiceId *string `json:"service_id,omitempty"` 123 SubMchid *string `json:"sub_mchid,omitempty"` 124 OutOrderNo *string `json:"out_order_no,omitempty"` 125 PostPayments []Payment `json:"post_payments,omitempty"` 126 PostDiscounts []ServiceOrderCoupon `json:"post_discounts,omitempty"` 127 TotalAmount *int64 `json:"total_amount,omitempty"` 128 Reason *string `json:"reason,omitempty"` 129 Device *Device `json:"device,omitempty"` 130} 131 132func (o *ModifyPartnerServiceOrderRequest) MarshalJSON() ([]byte, error) { 133 type Alias ModifyPartnerServiceOrderRequest 134 a := &struct { 135 OutOrderNo *string `json:"out_order_no,omitempty"` 136 *Alias 137 }{ 138 // 序列化时移除非 Body 字段 139 OutOrderNo: nil, 140 Alias: (*Alias)(o), 141 } 142 return json.Marshal(a) 143} 144 145type Payment struct { 146 Name *string `json:"name,omitempty"` 147 Amount *int64 `json:"amount,omitempty"` 148 Description *string `json:"description,omitempty"` 149 Count *int64 `json:"count,omitempty"` 150} 151 152type ServiceOrderCoupon struct { 153 Name *string `json:"name,omitempty"` 154 Description *string `json:"description,omitempty"` 155 Amount *int64 `json:"amount,omitempty"` 156} 157 158type Device struct { 159 StartDeviceId *string `json:"start_device_id,omitempty"` 160 EndDeviceId *string `json:"end_device_id,omitempty"` 161 MaterielNo *string `json:"materiel_no,omitempty"` 162} 163
应答参数
204 No Content
无应答包体
应答示例
204 No Content
1'无应答包体' 2
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
业务错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | INVALID_ORDER_STATE | 单据状态错误 | 确认操作是否符合流程 |
400 | INVALID_REQUEST | 请求参数符合参数格式,但不符合业务规则 | 请确认相同单号是否使用了不同的参数 |
400 | ORDER_CANCELED | 单据已取消 | 当前状态无需操作 |
400 | ORDER_DONE | 订单已完成 | 当前状态无需操作 |
403 | NO_AUTH | 商户信息不合法 | 登录商户平台核对,传入正确信息 |
404 | ORDER_NOT_ EXIST | 订单不存在 | 确认入参,传入正确单据 |
429 | FREQUENCY_LIMITED | 频率超限 | 请求量不要超过接口调用频率限制 |
500 | SYSTEM_ERROR | 系统错误 | 5开头的状态码都为系统问题,请使用相同参数稍后重新调用 |