npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

better-auth-mp

v1.0.0

Published

MercadoPago plugin for Better Auth — subscriptions, payments & webhooks out of the box

Downloads

12

Readme


⚠️ Disclaimer: This plugin is community-maintained and is not officially affiliated with MercadoPago or Better Auth. See DISCLAIMER.md for full details.

Table of Contents

Features

  • 🔐 Authentication-first payments — Payments tied to authenticated Better Auth users
  • 💳 Subscription management — Create and manage recurring subscriptions with MercadoPago
  • 🔔 Webhook handling — Built-in webhook verification and event processing
  • 📦 Type-safe — Full TypeScript support with Zod validation
  • 🔌 Pluggable — Drop-in Better Auth plugin with minimal configuration
  • 🌎 LATAM-ready — Built specifically for MercadoPago's Latin American market

Installation

# npm
npm install better-auth-mp

# yarn
yarn add better-auth-mp

# pnpm
pnpm add better-auth-mp

# bun
bun add better-auth-mp

Peer Dependencies

Make sure you have the required peer dependencies installed:

bun add better-auth @prisma/client

Quick Start

Server Setup

Add the plugin to your Better Auth configuration:

// auth.ts (server)
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { mercadopago } from "better-auth-mp";
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

export const auth = betterAuth({
  database: prismaAdapter(prisma, {
    provider: "postgresql",
  }),
  plugins: [
    mercadopago({
      accessToken: process.env.MP_ACCESS_TOKEN!,
      webhookSecret: process.env.MP_WEBHOOK_SECRET!,
    }),
  ],
});

Client Setup

Add the client plugin to your Better Auth client:

// auth-client.ts (client)
import { createAuthClient } from "better-auth/react";
import { mercadopagoClient } from "better-auth-mp/client";

export const authClient = createAuthClient({
  plugins: [mercadopagoClient()],
});

Environment Variables

# MercadoPago credentials
MP_ACCESS_TOKEN=APP_USR-xxxxxxxxxxxxxxxxxxxx
MP_WEBHOOK_SECRET=your-webhook-secret

# Better Auth
BETTER_AUTH_SECRET=your-auth-secret
BETTER_AUTH_URL=http://localhost:3000

Configuration

Plugin Options

| Option | Type | Required | Description | |--------|------|----------|-------------| | accessToken | string | ✅ | MercadoPago Access Token (production or sandbox) | | webhookSecret | string | ✅ | Secret for webhook signature verification | | sandbox | boolean | ❌ | Enable sandbox mode (default: false) | | notificationUrl | string | ❌ | Override webhook URL (default: auto-detected from BETTER_AUTH_URL) |

mercadopago({
  accessToken: process.env.MP_ACCESS_TOKEN!,
  webhookSecret: process.env.MP_WEBHOOK_SECRET!,
  sandbox: process.env.NODE_ENV !== "production",
  notificationUrl: "https://yourdomain.com/api/auth/mercadopago/webhook",
})

Database Schema (ORM-agnostic)

This plugin is fully ORM-agnostic — it works with Prisma, Drizzle, or any other ORM/database supported by Better Auth.

The required schema is generated automatically using the Better Auth CLI. Run it once after configuring the plugin:

# bun
bunx @better-auth/cli generate

# npm
npx @better-auth/cli@latest generate

# pnpm
pnpm dlx @better-auth/cli@latest generate

# yarn
yarn dlx @better-auth/cli@latest generate

The CLI reads your auth.ts configuration and generates the necessary models/migrations for your configured ORM and database automatically.

Integrations

Next.js App Router

Create the webhook route handler:

// app/api/auth/[...betterauth]/route.ts
import { auth } from "@/lib/auth";
import { toNextJsHandler } from "better-auth/next-js";

export const { POST, GET } = toNextJsHandler(auth);

The plugin automatically registers the webhook endpoint at /api/auth/mercadopago/webhook.

Webhook Events

The plugin handles the following MercadoPago webhook events:

| Event | Description | |-------|-------------| | subscription_preapproval | Subscription created or updated | | payment | Payment received, refunded, or failed |

Client Hooks (React)

import { authClient } from "@/lib/auth-client";

// In your component
const { data: session } = authClient.useSession();
const subscription = authClient.mercadopago.useSubscription();

Roadmap

| Feature | Status | |---------|--------| | ✅ Basic payment webhooks | Released | | ✅ Subscription management | Released | | ✅ Webhook signature verification | Released | | 🔄 One-click checkout via Brick | In progress | | 🔄 Subscription plan management UI | In progress | | 📋 Refund management | Planned | | 📋 Payment analytics endpoints | Planned | | 📋 Multi-currency support | Planned | | 📋 Installment (cuotas) support | Planned |

Contributing

We welcome contributions! Please read our CONTRIBUTING.md guide before submitting a PR.

License

MIT — Copyright © 2025 better-auth-mp contributors.

See DISCLAIMER.md for important legal information.