Skip to content

Repository files navigation

Mercado Pago Subscription

This project integrates Mercado Pago subscriptions to gate chat access.

Environment Variables

Add the following to your .env.local:

# Mercado Pago
MP_ACCESS_TOKEN=YOUR_ACCESS_TOKEN_FROM_MP_DASHBOARD
APP_URL=http://localhost:3000
MP_WEBHOOK_SECRET=YOUR_WEBHOOK_SECRET_OPTIONAL

Setup

  1. Create a Test Account: Go to Mercado Pago Developers and create a test account (Seller and Buyer).
  2. Get Credentials: Use the Seller account's Access Token.
  3. Run Application: Ensure APP_URL matches your running instance (use ngrok for local webhook testing).
  4. Webhooks: Configure Webhooks in MP Dashboard to point to ${APP_URL}/api/mercadopago/webhook and subscribe to subscription_preapproval events.

Flow

  1. User logs in.
  2. If not subscribed, they are redirected to /subscribe.
  3. Clicking "Subscribe" creates a pending PreApproval and redirects to Mercado Pago.
  4. After payment, MP sends a webhook to /api/mercadopago/webhook.
  5. The webhook updates the user's subscription status in the database.
  6. User gains access to chats.

Releases

Packages

Contributors

Languages