WeChatPay¶
-
class
WeChatPay
(appid, mch_id, notify_url, pay_secret, cert=None, key=None)¶ -
unifiedorder
(device_info, sign_type, fee_type, trade_type, **kwargs)¶ Form a new order. more information at API
Parameters: - device_info – exception type
- sign_type – sign method(MD5 or HMAC-SHA256)
- fee_type – currency type
- attach – attach data
- out_trade_no – order id (should be unique in your system)
- trade_type – (JSAPI,NATIVE,APP)
- body – order description
- detail – item detail
- total_fee – the amount of fee
- spbill_create_ip – client ip address
- time_start – order generate time (format yyyyMMddHHmmss)
- time_expire – order expire time (format yyyyMMddHHmmss)
- goods_tag – discount info
- product_id – item id
- limit_pay – no_credit
- openid – user wechat openid
- scene_info – scenario info
Return type:
-
random_str
()¶ Generate a random string
Return type: string
-
verify_notify
(req)¶ Verify WeChat payment notification
Parameters: req – Request object from requests Return type: NotifyResult
orErrorResult
-
to_xml
(dct)¶ Transfer a dict to xml string :param dct: data dict to send :rtype: string
-
sendbox_sign
()¶ Generate sendbox secret key API
Return type: SendBoxKey
-
query_order
(**kwargs)¶ Query order from WeChat API
Parameters: - transaction_id – wechat order id
- out_trade_no – order id (transaction_id and out_trade_no only need one)
Return type:
-
downloadbill
(bill_date, sign_type='MD5', bill_type='ALL', tar_type='GZIP')¶ Download bills API
Parameters: - bill_date – the date of bill (format yyyymmdd)
- bill_type – the type of bill (ALL, SUCCESS, REFUND, RECHARGE_REFUND)
- tar_type – tar type(GZIP)
Return type:
-
close_order
(out_trade_no, sign_type='MD5')¶ Close order API
Parameters: out_trade_no – order id Return type: CloseOrderResult
-
short_url
(long_url, sign_type='MD5')¶ Convert long url to short url and make the Qr code more recognizable API
Parameters: long_url – long url Return type: ShortUrlResult
-
refund
(out_trade_no, out_refund_no, total_fee, refund_fee, sign_type='MD5', refund_fee_type='CNY', **kwargs)¶ Method for refund this method need you to proide your cert.pem and key.pem file API
Parameters: - transaction_id – wechat order id
- out_trade_no – order id (transaction_id and out_trade_no only need one)
- out_refund_no – refund id
- total_fee – total order fee
- refund_fee – refund total fee
- refund_fee_type – currency type (CNY)
- refund_desc – refund reason
- refund_account – refund account
Return type: :py:class::RefundResult
-
refund_query
(out_refund_no, sign_type='MD5', **kwargs)¶ Query refund process API :param transaction_id: wechat order id :param out_trade_no: order id :param out_refund_no: refund id :param refund_id: refund id from WeChat (transaction_id, out_trade_no, out_refund_no, refund_id only need to one) :param offset: query offset :rtype: :py:class::RefundQueryResult
-