This project integrates Mercado Pago subscriptions to gate chat access.
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- Create a Test Account: Go to Mercado Pago Developers and create a test account (Seller and Buyer).
- Get Credentials: Use the Seller account's Access Token.
- Run Application: Ensure
APP_URLmatches your running instance (use ngrok for local webhook testing). - Webhooks: Configure Webhooks in MP Dashboard to point to
${APP_URL}/api/mercadopago/webhookand subscribe tosubscription_preapprovalevents.
- User logs in.
- If not subscribed, they are redirected to
/subscribe. - Clicking "Subscribe" creates a pending PreApproval and redirects to Mercado Pago.
- After payment, MP sends a webhook to
/api/mercadopago/webhook. - The webhook updates the user's subscription status in the database.
- User gains access to chats.