@@ -55,7 +55,7 @@ def pay(self,
55
55
:param goods_tag: 订单优惠标记,示例值:'WXG'
56
56
:param detail: 优惠功能,示例值:{'cost_price':608800, 'invoice_id':'微信123', 'goods_detail':[{'merchant_goods_id':'商品编码', 'wechatpay_goods_id':'1001', 'goods_name':'iPhoneX 256G', 'quantity':1, 'unit_price':828800}]}
57
57
:param scene_info: 场景信息,示例值:{'payer_client_ip':'14.23.150.211', 'device_id':'013467007045764', 'store_info':{'id':'0001', 'name':'腾讯大厦分店', 'area_code':'440305', 'address':'广东省深圳市南山区科技中一道10000号'}}
58
- :param settle_info: 结算信息,示例值:{'profit_sharing':false }
58
+ :param settle_info: 结算信息,示例值:{'profit_sharing':False }
59
59
:param notify_url: 通知地址,示例值:'https://www.weixin.qq.com/wxpay/pay.php'
60
60
"""
61
61
params = {}
@@ -74,6 +74,8 @@ def pay(self,
74
74
params .update ({'amount' : amount })
75
75
else :
76
76
raise WeChatPayException ('amount is not assigned.' )
77
+ if payer :
78
+ params .update ({'payer' : payer })
77
79
if scene_info :
78
80
params .update ({'scene_info' : scene_info })
79
81
if time_expire :
@@ -87,9 +89,7 @@ def pay(self,
87
89
if settle_info :
88
90
params .update ({'settle_info' : settle_info })
89
91
if self ._type in [WeChatPayType .JSAPI , WeChatPayType .MINIPROG ]:
90
- if payer :
91
- params .update ({'payer' : payer })
92
- else :
92
+ if not payer :
93
93
raise WeChatPayException ('payer is not assigned' )
94
94
path = '/v3/pay/transactions/jsapi'
95
95
elif self ._type == WeChatPayType .APP :
@@ -100,7 +100,7 @@ def pay(self,
100
100
path = '/v3/pay/transactions/h5'
101
101
elif self ._type == WeChatPayType .NATIVE :
102
102
path = '/v3/pay/transactions/native'
103
- self ._core .post (path , json = json .dumps (params ))
103
+ return self ._core .post (path , json = json .dumps (params ))
104
104
105
105
def close (self , out_trade_no ):
106
106
"""关闭订单
@@ -121,15 +121,12 @@ def query(self, transaction_id=None, out_trade_no=None):
121
121
"""
122
122
if not (transaction_id or out_trade_no ):
123
123
raise WeChatPayException ('params is not assigned' )
124
- params = {}
125
- params ['mchid' ] = self ._mchid
126
124
if transaction_id :
127
125
path = '/v3/pay/transactions/id/%s' % transaction_id
128
- params ['transaction_id' ] = transaction_id
129
126
else :
130
127
path = '/v3/pay/transactions/out-trade-no/%s' % out_trade_no
131
- params [ 'out_trade_no' ] = out_trade_no
132
- return self ._core .get (path , json = json . dumps ( params ) )
128
+ path = '%s?mchid=%s' % ( path , self . _mchid )
129
+ return self ._core .get (path )
133
130
134
131
def refund (self ,
135
132
out_refund_no ,
@@ -209,9 +206,95 @@ def download_bill(self, url):
209
206
return self ._core .get (path )
210
207
211
208
def certificate (self ):
209
+ """下载微信支付平台证书
210
+ """
212
211
path = '/v3/certificates'
213
212
return self ._core .get (path )
214
213
214
+ def combine_pay (self ,
215
+ combine_out_trade_no ,
216
+ sub_orders ,
217
+ scene_info = None ,
218
+ combine_payer_info = None ,
219
+ time_start = None ,
220
+ time_expire = None ,
221
+ combine_appid = None ,
222
+ combine_mchid = None ,
223
+ notify_url = None ):
224
+ """合单支付下单
225
+ :param combine_out_trade_no: 合单商户订单号, 示例值:'P20150806125346'
226
+ :param sub_orders: 子单信息,示例值:[{'mchid':'1900000109', 'attach':'深圳分店', 'amount':{'total_amount':100,'currency':'CNY'}, 'out_trade_no':'20150806125346', 'description':'腾讯充值中心-QQ会员充值', 'settle_info':{'profit_sharing':False, 'subsidy_amount':10}}]
227
+ :param scene_info: 场景信息, 示例值:{'device_id':'POS1:123', 'payer_client_ip':'14.17.22.32'}
228
+ :param combine_payer_info: 支付者, 示例值:{'openid':'oUpF8uMuAJO_M2pxb1Q9zNjWeS6o'}
229
+ :param time_start: 交易起始时间,示例值:'2019-12-31T15:59:59+08:00'
230
+ :param time_expire: 交易结束时间, 示例值:'2019-12-31T15:59:59+08:00'
231
+ :param combine_appid: 合单商户appid, 示例值:'wxd678efh567hg6787'
232
+ :param combine_mchid: 合单发起方商户号,示例值:'1900000109'
233
+ :param notify_url: 通知地址, 示例值:'https://yourapp.com/notify'
234
+ """
235
+ params = {}
236
+ params ['combine_appid' ] = combine_appid or self ._appid
237
+ params ['combine_mchid' ] = combine_mchid or self ._mchid
238
+ params ['notify_url' ] = notify_url or self ._notify_url
239
+ if combine_out_trade_no :
240
+ params .update ({'combine_out_trade_no' : combine_out_trade_no })
241
+ else :
242
+ raise WeChatPayException ('combine_out_trade_no is not assigned.' )
243
+ if sub_orders :
244
+ params .update ({'sub_orders' : sub_orders })
245
+ else :
246
+ raise WeChatPayException ('sub_orders is not assigned.' )
247
+ if scene_info :
248
+ params .update ({'scene_info' : scene_info })
249
+ if combine_payer_info :
250
+ params .update ({'combine_payer_info' : combine_payer_info })
251
+ if time_start :
252
+ params .update ({'time_start' : time_start })
253
+ if time_expire :
254
+ params .update ({'time_expire' : time_expire })
255
+ if self ._type in [WeChatPayType .JSAPI , WeChatPayType .MINIPROG ]:
256
+ if not combine_payer_info :
257
+ raise WeChatPayException ('combine_payer_info is not assigned' )
258
+ path = '/v3/combine-transactions/jsapi'
259
+ elif self ._type == WeChatPayType .APP :
260
+ path = '/v3/combine-transactions/app'
261
+ elif self ._type == WeChatPayType .H5 :
262
+ if not scene_info :
263
+ raise WeChatPayException ('scene_info is not assigned.' )
264
+ path = '/v3/combine-transactions/h5'
265
+ elif self ._type == WeChatPayType .NATIVE :
266
+ path = '/v3/combine-transactions/native'
267
+ return self ._core .post (path , json = json .dumps (params ))
268
+
269
+ def combine_query (self , combine_out_trade_no ):
270
+ """合单查询订单
271
+ :param combine_out_trade_no: 合单商户订单号,示例值:P20150806125346
272
+ """
273
+ params = {}
274
+ if not combine_out_trade_no :
275
+ raise WeChatPayException ('param combine_out_trade_no is not assigned' )
276
+ else :
277
+ params .update ({'combine_out_trade_no' :combine_out_trade_no })
278
+ path = '/v3/combine-transactions/out-trade-no/%s' % combine_out_trade_no
279
+ return self ._core .get (path )
280
+
281
+ def combine_close (self , combine_out_trade_no , sub_orders , combine_appid = None ):
282
+ """合单关闭订单
283
+ :param combine_out_trade_no: 合单商户订单号,示例值:'P20150806125346'
284
+ :param sub_orders: 子单信息, 示例值:[{'mchid': '1900000109', 'out_trade_no': '20150806125346'}]
285
+ :param combine_appid: 合单商户appid, 示例值:'wxd678efh567hg6787'
286
+ """
287
+ params = {}
288
+ params ['combine_appid' ] = combine_appid or self ._appid
289
+
290
+ if not combine_out_trade_no :
291
+ raise WeChatPayException ('combine_out_trade_no is not assigned.' )
292
+ if not sub_orders :
293
+ raise WeChatPayException ('sub_orders is not assigned.' )
294
+ else :
295
+ params .update ({'sub_orders' : sub_orders })
296
+ path = '/v3/combine-transactions/out-trade-no/%s/close' % combine_out_trade_no
297
+ return self ._core .post (path , json = json .dumps (params ))
215
298
216
299
class WeChatPayException (Exception ):
217
300
def __init__ (self , reason ):
0 commit comments