New:Microsoft Teams Notifications Are Now Available in Socket.Learn more
Get Started

cobroya

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cobroya

Mercado Pago payment links from Telegram, WhatsApp, and AI agents. Cobra en 10 segundos.

Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
23
-11.54%
Maintainers
1
Weekly downloads
 
Created
Source

mercadopago-tool

Mercado Pago tool connector for AI agents. Exposes Mercado Pago API actions through a simple, typed interface that AI agents can call via MCP-style tool registries.

Setup

npm install
npm run build
cp .env.example .env
# Edit .env with your real token
export MERCADO_PAGO_ACCESS_TOKEN="APP_USR-..."

Get your token from Mercado Pago Developers.

Actions

ActionDescription
create_payment_preferenceCreate a checkout payment link with optional back_urls and notification_url
get_paymentRetrieve a payment by ID
create_refundFull or partial refund of a payment
search_paymentsSearch payments with filters (status, sort, pagination)
get_merchant_infoGet merchant user profile

Agent Usage

import { createMercadoPagoTools } from "mercadopago-tool";

const mp = createMercadoPagoTools(process.env.MERCADO_PAGO_ACCESS_TOKEN!);

// Create a payment link
const pref = await mp.tools.create_payment_preference({
  title: "Premium Plan",
  quantity: 1,
  currency: "ARS",
  unit_price: 5000,
  back_urls: {
    success: "https://myapp.com/success",
    failure: "https://myapp.com/failure",
  },
  notification_url: "https://myapp.com/webhooks/mp",
});
// pref.init_point -> checkout URL to share with the buyer

// Search approved payments
const payments = await mp.tools.search_payments({ status: "approved", limit: 10 });

// Refund a payment
const refund = await mp.tools.create_refund({ payment_id: "123456789" });

// Partial refund
const partial = await mp.tools.create_refund({ payment_id: "123456789", amount: 500 });

// Get payment details
const payment = await mp.tools.get_payment({ payment_id: "123456789" });

// List schemas for AI agent tool registration
console.log(mp.schemas);

Error Handling

import { MercadoPagoError } from "mercadopago-tool";

try {
  await mp.tools.get_payment({ payment_id: "invalid" });
} catch (err) {
  if (err instanceof MercadoPagoError) {
    console.log(err.status);        // 404
    console.log(err.isNotFound);     // true
    console.log(err.isUnauthorized); // false
    console.log(err.isRateLimited);  // false
  }
}

Integration Test

Test against the real API:

MERCADO_PAGO_ACCESS_TOKEN=APP_USR-... npm run integration

Curl Examples

Create preference:

curl -X POST https://api.mercadopago.com/checkout/preferences \
  -H "Authorization: Bearer $MERCADO_PAGO_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"items":[{"title":"Test","quantity":1,"currency_id":"ARS","unit_price":1000}],"back_urls":{"success":"https://myapp.com/ok"},"notification_url":"https://myapp.com/webhooks/mp"}'

Get payment:

curl https://api.mercadopago.com/v1/payments/123456789 \
  -H "Authorization: Bearer $MERCADO_PAGO_ACCESS_TOKEN"

Refund payment:

curl -X POST https://api.mercadopago.com/v1/payments/123456789/refunds \
  -H "Authorization: Bearer $MERCADO_PAGO_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{}'

Search payments:

curl "https://api.mercadopago.com/v1/payments/search?status=approved&limit=10" \
  -H "Authorization: Bearer $MERCADO_PAGO_ACCESS_TOKEN"

Merchant info:

curl https://api.mercadopago.com/users/me \
  -H "Authorization: Bearer $MERCADO_PAGO_ACCESS_TOKEN"

WhatsApp Business Integration

Setup

  • Create a Meta app at Meta for Developers
  • Enable WhatsApp Business API
  • Get your access token, phone number ID, and set a verify token
# Add to .env
WHATSAPP_ACCESS_TOKEN=your-meta-graph-api-token
WHATSAPP_PHONE_NUMBER_ID=your-phone-number-id
WHATSAPP_VERIFY_TOKEN=your-webhook-verify-token

Run the WhatsApp server

npm run whatsapp
# Server starts on http://localhost:3000/webhook
# Use ngrok to expose: ngrok http 3000

Then configure the webhook URL in Meta Dashboard: https://your-ngrok-url/webhook

Supported commands

Users send plain text messages to your WhatsApp number:

cobrar 5000 curso python
→ 💳 Link de pago generado
  https://www.mercadopago.com/checkout/v1/redirect?pref_id=...

pagos
→ ✅ Aprobado
  $5000
  ID: 123456

estado 123456
→ Pago #123456
  Estado: ✅ Aprobado
  Monto: $5000

devolver 123456
→ Devolucion total realizada
  Monto devuelto: $5000

devolver 123456 2000
→ Devolucion parcial realizada
  Monto devuelto: $2000

ayuda
→ Lista de comandos

Payment notifications

When a payment is confirmed via the Mercado Pago webhook, you can forward it to WhatsApp:

import { createWhatsAppWebhookHandler, WhatsAppClient, createPaymentNotifier, createWebhookHandler } from "mercadopago-tool";

const wa = new WhatsAppClient({
  accessToken: process.env.WHATSAPP_ACCESS_TOKEN!,
  phoneNumberId: process.env.WHATSAPP_PHONE_NUMBER_ID!,
});

// Notify merchant on WhatsApp when payment is approved
const notifier = createPaymentNotifier(wa, "5491155551234");

const mpWebhook = createWebhookHandler({
  accessToken: process.env.MERCADO_PAGO_ACCESS_TOKEN!,
  onPayment: notifier,
});

Programmatic usage

import { WhatsAppClient } from "mercadopago-tool";

const wa = new WhatsAppClient({
  accessToken: process.env.WHATSAPP_ACCESS_TOKEN!,
  phoneNumberId: process.env.WHATSAPP_PHONE_NUMBER_ID!,
});

await wa.sendMessage("5491155551234", "Tu pago fue recibido!");

Testing

npm test

License

MIT

Keywords

mercadopago

FAQs

Package last updated on 06 Mar 2026

Related posts