Mercado Pago Setup & Integration Guide
The mercadopago provider integrates Mercado Pago Checkout Pro (Pix, Boleto, OXXO, Cards), Preapproval Subscriptions, and Chargeback Tracking across Latin American markets (BRL, MXN, ARS, CLP, COP, PEN, UYU).
1. Prerequisites & Installation
Section titled “1. Prerequisites & Installation”Kirak communicates with Mercado Pago directly via async REST API calls with httpx. No external Mercado Pago SDK or additional pip package is required.
pip install "kirak"2. Credentials & Configuration
Section titled “2. Credentials & Configuration”Step 1: Obtain Access Token
Section titled “Step 1: Obtain Access Token”In Mercado Pago Developers (Your Integrations):
- Select or create your application.
- Under Production credentials or Test credentials, copy the Access Token.
Step 2: Configure Webhooks
Section titled “Step 2: Configure Webhooks”In your application $\rightarrow$ Webhooks:
- Set the URL to:
https://your-domain.com/payments/webhook/mercadopago. - Select the event topics: Payments, Plans and subscriptions (subscription preapproval and authorized payment), and Chargebacks.
- Copy the generated Secret signature.
[!WARNING] Use modern Webhooks, not legacy IPN notifications. IPN deliveries are un-signed and will be rejected with
400 INVALID_WEBHOOK_SIGNATURE.
Step 3: Configure kirak.json
Section titled “Step 3: Configure kirak.json”{ "payments": { "default_provider": "mercadopago", "providers": { "mercadopago": { "type": "mercadopago", "environment": "sandbox", "success_url": "https://your-domain.com/payment/success" } } }}Step 4: Set Environment Variables
Section titled “Step 4: Set Environment Variables”KIRAK_PAYMENT_MERCADOPAGO_ACCESS_TOKEN=APP_USR-...KIRAK_PAYMENT_MERCADOPAGO_WEBHOOK_SECRET=your_secret_signature_from_step23. Usage Examples
Section titled “3. Usage Examples”3.1 One-Time Checkout (Checkout Pro)
Section titled “3.1 One-Time Checkout (Checkout Pro)”Supports all methods enabled on your Mercado Pago account (credit/debit cards, Pix in Brazil, Boleto, OXXO in Mexico):
result = await kirak.payments.initiate_payment({ "provider": "mercadopago", "user_id": "usr_800", "amount": 4990, # R$ 49.90 in minor units (centavos) "currency": "BRL", "name": "Curso Online", "type": "one_time", "payment_email": "cliente@example.com.br",})
checkout_url = result["data"]["url"]3.2 Preapproval Subscriptions
Section titled “3.2 Preapproval Subscriptions”Create a Preapproval Plan in Mercado Pago first:
result = await kirak.payments.initiate_payment({ "provider": "mercadopago", "user_id": "usr_800", "amount": 0, # Price defined by preapproval plan "currency": "BRL", "name": "Assinatura Mensal", "type": "subscription", "subscription_plan_id": "2c9380848...", # Mercado Pago Preapproval Plan ID "payment_email": "cliente@example.com.br",})3.3 Subscription Lifecycle Management
Section titled “3.3 Subscription Lifecycle Management”Mercado Pago supports pausing, resuming, and changing subscription amounts:
# Pause billing:await kirak.payments.pause_subscription({"subscription_id": "2c938..."})
# Resume billing:await kirak.payments.resume_subscription({"subscription_id": "2c938..."})
# Cancel subscription (immediate only):await kirak.payments.cancel_subscription({"subscription_id": "2c938..."})[!NOTE] Saved Cards & Off-Session Charges: Mercado Pago requires the CVV/CVC security code to be entered by the customer for every charge. Consequently, fully headless off-session charges (
charge_off_session) and saved cards without buyer interaction are not supported (501 NOT_SUPPORTED).
4. Webhook Event Mapping
Section titled “4. Webhook Event Mapping”Normalized event |
Gateway Events | Description |
|---|---|---|
payment_completed |
payment (status="approved") |
Payment approved and settled |
payment_failed |
payment (status="rejected", "cancelled") |
Payment failed |
subscription_renewed |
subscription_authorized_payment |
Preapproval cycle billed |
subscription_updated |
subscription_preapproval (status="paused") |
Subscription paused or modified |
subscription_cancelled |
subscription_preapproval (status="cancelled") |
Subscription cancelled |
refund_completed |
payment (status="refunded") |
Refund completed |
dispute_created |
topic_chargebacks_wh |
Chargeback opened |