用于支付集成的Mercadopago SDK模块
mercadopago的Python项目详细描述
安装
在python 2.x上
pip install mercadopago
在python 3.x上
pip3 install mercadopago
基本签出
配置您的凭据
- 在以下地址中获取client\u id和client\u secret:
- 阿根廷:https://www.mercadopago.com/mla/herramientas/aplicaciones
- 巴西:https://www.mercadopago.com/mlb/ferramentas/aplicacoes <“>”>“>”
- 委内瑞拉:https://www.mercadopago.com/mlv/herramientas/aplicaciones
- 哥伦比亚:https://www.mercadopago.com/mco/herramientas/aplicaciones
- 智利:https://www.mercadopago.com/mlc/herramientas/aplicaciones
import mercadopago import json mp = mercadopago.MP("CLIENT_ID", "CLIENT_SECRET")
偏好
得到一个存在的签出偏好
def index(req, **kwargs): preferenceResult = mp.get_preference("PREFERENCE_ID") return json.dumps(preferenceResult, indent=4)
创建签出首选项
def index(req, **kwargs):
preference = {
"items": [
{
"title": "Test",
"quantity": 1,
"currency_id": "USD",
"unit_price": 10.4
}
]
}
preferenceResult = mp.create_preference(preference)
return json.dumps(preferenceResult, indent=4)
更新现有的结账偏好
def index(req, **kwargs): preference = { "items": [ { "title": "Test Modified", "quantity": 1, "currency_id": "USD", "unit_price": 20.4 } ] } preferenceResult = mp.update_preference(id, preference) return json.dumps(preferenceResult, indent=4)
付款/收款
搜索付款
def index(req, **kwargs):
filters = {
"id": None,
"external_reference": None
}
searchResult = mp.search_payment(filters)
return json.dumps(searchResult, indent=4)
获取付款数据
import mercadopago
import json
def index(req, **kwargs):
mp = mercadopago.MP("CLIENT_ID", "CLIENT_SECRET")
paymentInfo = mp.get_payment (kwargs["id"])
if paymentInfo["status"] == 200:
return json.dumps(paymentInfo, indent=4)
else:
return None
取消(仅适用于待付款)
def index(req, **kwargs): result = mp.cancel_payment("ID") // Show result return json.dumps(result, indent=4)
退款(仅限于经认可的付款)
def index(req, **kwargs): result = mp.refund_payment("ID") // Show result return json.dumps(result, indent=4)
定制结账
配置您的凭据
import mercadopago import json mp = mercadopago.MP("ACCESS_TOKEN")
创建付款
mp.post ("/v1/payments", payment_data)
创建客户
mp.post ("/v1/customers", {"email": "email@test.com"})
获取客户
mp.get ("/v1/customers/CUSTOMER_ID")
- 在开发人员站点中查看更多自定义签出相关的API
- 委内瑞拉:https://www.mercadopago.com.ve/developers
- 哥伦比亚:https://www.mercadopago.com.co/developers
一般方法
您可以使用泛型方法从Mercadopago API访问任何其他资源:
// Get a resource, with optional URL params. Also you can disable authentication for public APIs mp.get ("/resource/uri", [params], [authenticate=true]); // Create a resource with "data" and optional URL params. mp.post ("/resource/uri", data, [params]); // Update a resource with "data" and optional URL params. mp.put ("/resource/uri", data, [params]); // Delete a resource with optional URL params. mp.delete ("/resource/uri", [params]);
例如,如果要获取站点列表(无参数,无身份验证):
result = mp.get ("/sites", null, false); print (json.dumps(result, indent=4))
运行测试
在python 2.x上
python setup.py test
在python 3.x上
python3 setup.py test