How srossiprieto/next-mercadopago works
This project is a full-stack integration tutorial focused on demonstrating multiple ways to integrate Mercado Pago into Next.js applications. Its purpose is to show different payment flows—involving Checkout Pro, Suscripciones, Checkout Bricks, and Marketplace—using the Next.js App Router and illustrating key configuration steps for creating applications, managing credentials, exposing ports, and handling webhooks.
Main Components Identification
• Integration Applications: There are four distinct Next.js applications under the “integraciones” directory. Each one represents a different payment flow:
• Checkout Pro: Where users pay to post a message, involving payment redirection via Mercado Pago, webhook notifications, and payment verification.
• Suscripciones: Integrates subscriptions (without pre-defined payment plans) along with webhook handling.
• Checkout Bricks: Embedded payment data collection directly within the application.
• Marketplace: Acts as an intermediary allowing a user to post messages on someone else’s “wall” and earning a commission on each message, again using Checkout Pro flow.
• Configuration Toolkit: Located in the “configuracion” folder, these modules provide guidance on:
• Creating a Mercado Pago application.
• Setting up test accounts and credentials.
• Exposing local ports publicly.
• Configuring webhooks for receiving notifications.
• External Systems:
• Mercado Pago’s APIs and webhooks, as the primary external payment service.
• Databases and Utilities:
• Each integration app uses local database files (e.g., message.db and user.db) for persistence.
• Frontend and Backend Elements:
• The Next.js structure (with pages, app folder, API routes) covers both client (user interface for message forms and pages) and server-side aspects (API endpoints for payment processing and webhooks).
Relationships and Data Flow
• Users interact with the frontend of a given integration application (e.g., submitting a message).
• The application backend (Next.js API routes) communicates with Mercado Pago’s API to create payment preferences or subscribe users.
• Depending on the integration type, the user may be redirected externally (e.g., Checkout Pro marketplace) or process payment within the app (Checkout Bricks).
• Webhooks are set up in the project to asynchronously receive notifications about payments or subscriptions from Mercado Pago. These notifications flow into specific API endpoints within the apps for verification and update.
• Local databases are used to store payment statuses, messages, and user data, recording the outcome of transactions and notifications.
Architectural Patterns and Design Choices
• Modular Structure: The project modularizes each integration type into its own directory, facilitating focused development and testing.
• Separation of Concerns: The “configuracion” directory holds all preparatory and helper instructions, separating configuration from core integration logic.
• API-Driven Communication: Each integration app employs API routes for processing payment requests and handling webhooks, reflecting modern RESTful (or sometimes event-driven) design.
• Shared Technologies: All integration apps use Next.js (with App Router), Tailwind CSS for styling, and configuration files (like ESLint, postcss, and TypeScript configurations) for consistency.
Elements
• Component Blocks:
• Databases as separate labeled blocks.
• Asynchronous callback flow via webhooks from Mercado Pago back to the apps.