用于支付集成的Mercadopago SDK模块
mercadopago-sdk-fork的Python项目详细描述
安装
注意:如果您安装了这个,MERCADOPAGO导入将被覆盖,并且可能不会像官方那样不断更新
在python2.x上
pip install mercadopago-sdk-fork
在python3.x上
pip3 install mercadopago-sdk-fork
基本结账
配置您的凭据
- 在以下地址获取您的CLIENT_ID和CLIENT_SECRET:
- 阿根廷:https://www.mercadopago.com/mla/herramientas/aplicaciones
- 巴西:https://www.mercadopago.com/mlb/ferramentas/aplicacoes
- 梅西科:https://www.mercadopago.com/mlm/herramientas/aplicaciones
- 委内瑞拉: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")
首选项
获取现有的签出首选项
^{pr2}$创建签出首选项
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")
泛型方法
您可以使用泛型方法从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))
运行测试
在python2.x上
python setup.py test
在python3.x上
python3 setup.py test
- 项目
标签: