ekx-mercadopagolisted
Install: claude install-skill Ekinoxis-evm/claude-skills
# MercadoPago
The Colombian payment rail. **Live in exactly one place** — course enrollment. Stripe does
not serve Colombia well; this is the reason MercadoPago exists in the portfolio at all.
Everything below is extracted from a `mercadopago.ts` / `mpWebhookDecision.ts` pair,
both of which have unit tests.
## Setup
```bash
npm i mercadopago # official SDK v2 — github.com/mercadopago/sdk-nodejs
```
```
MERCADOPAGO_ACCESS_TOKEN= # server-only, never NEXT_PUBLIC_
MERCADOPAGO_WEBHOOK_SECRET= # from the MP dashboard, webhook config
```
```ts
import MercadoPagoConfig, { Preference, Payment } from "mercadopago";
function getClient(): MercadoPagoConfig {
const token = process.env.MERCADOPAGO_ACCESS_TOKEN;
if (!token) throw new Error("MERCADOPAGO_ACCESS_TOKEN is not set");
return new MercadoPagoConfig({ accessToken: token });
}
```
## Checkout — create a Preference, redirect to `init_point`
MP is **redirect-based**, not an embedded element like Stripe's Payment Element. You
create a Preference server-side and send the user to the URL it returns.
```ts
const preference = new Preference(getClient());
const response = await preference.create({
body: {
items: [{
id: `course-${courseId}`,
title: courseName,
quantity: 1,
unit_price: unitPrice, // final price AFTER discount
currency_id: "COP",
}],
payer: { email: buyerEmail },
back_urls: {
success: `${baseUrl}/academia?payment=success`,
failure: `${bas