面包多支付SDK - https://mbd.pub/
Project description
mbd-pay
Quickstart
Install using pip:
$ pip install mbd-pay
Example
from mbd_pay import Client
c = Client(app_id="**", app_key="**")
# 生成获取openid的链接
print("openid_redirect_url: \n", c.get_openid_redirect_url(target_url="baidu.com"))
print(
"wx jsapi: \n",
c.wx_jsapi(
openid="123", description="321", amount_total=100, callback_url="baidu.com",
),
)
print("wx h5: \n", c.wx_h5(description="321", amount_total=100))
print("alipay: \n", c.alipay(url="baidu.com", description="321", amount_total=100))
print("refund: \n", c.refund(order_id="123"))
print("search order: \n", c.search_order(out_trade_no="123"))
Reference
def _handle_req(self, req) -> dict:
"""
`req` Model to dict, and add sign | 过滤空值、签名、构建请求体
"""
req = req.dict(exclude_none=True)
req.update(app_id=self.app_id)
req.update(sign=sign(req, self.app_key))
return req
def _post(self, _url: str, req, **kwargs):
"""
build request body for POST, split out requests' kwargs
:param url: url
:param req: see ***Req in types.py
:param kwargs: req + `requests.post`'s kwargs, e.g. timeout=5
:return:
"""
body = self._handle_req(req)
# split out requests' kwargs | 抽离出所有面包多Pay以外的参数,并传递给requests执行实际请求
other_kwargs = {
i: kwargs[i] for i in kwargs.keys() if i not in req.__fields_set__
}
return requests.post(_url, json=body, **other_kwargs).json()
def wx_jsapi(self, **kwargs) -> WeChatJSApiRes:
"""
see:https://doc.mbd.pub/api/wei-xin-zhi-fu
:param kwargs: WeChatJSApiReq required fields
and optional `requests.post`'s kwargs, e.g. timeout=5
:return: WeChatJSApiRes
"""
req = WeChatJSApiReq(**kwargs) # 用kwarg实例化一个WeChatJSApiReq对象
api = f"{self.domain}/release/wx/prepay"
res = self._post(api, req, **kwargs)
return WeChatJSApiRes(**res) # 用返回值实例化一个WeChatJSApiRes对象
Thanks
Todos
- WebHooks
License
MIT
Hell Yeah!
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mbd_pay-0.1.4.tar.gz
(5.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mbd_pay-0.1.4.tar.gz.
File metadata
- Download URL: mbd_pay-0.1.4.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.8.5 Darwin/19.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2755591bac8963b907cd5551853a2194bd4e98140594ef16f9e70e61293d3f7e
|
|
| MD5 |
17afe6186d0a749f1634b333081c6853
|
|
| BLAKE2b-256 |
9cec7b34197cdf4a320d7ae13d6b2acd4d4f0d6a144a0de0cfa85ce7de97101b
|
File details
Details for the file mbd_pay-0.1.4-py3-none-any.whl.
File metadata
- Download URL: mbd_pay-0.1.4-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.8.5 Darwin/19.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8602c5e7e649e421a507f0e47192f0f7c372e28cb002adea16a0689e1d8a4faf
|
|
| MD5 |
fd3a5f1d90794fe33559df53daf6296e
|
|
| BLAKE2b-256 |
6dce12380626c4b311007c39df692a1c66e1407a5a90319730c34c9054fbe3f5
|