The code is written in JavaScript using Node.js and Express.JS, and it demonstrates basic operations such as generating card tokens and managing payments and preferences.
Before running this project, ensure you have the following installed:
- Node.js (version 20 or higher)
- npm or yarn
Additionally, you will need a Mercado Pago account to obtain your ML_ACCESS_TOKEN
.
Mercado Pago Docs: https://www.mercadopago.com.br/developers/en/reference
Clone the repository:
git clone https://github.com/your-repo/mercadopago-integration.git
cd mercadopago-integration
Install the dependencies:
npm install
Create a .env file in the root directory and add your MercadoPago access token:
ML_ACCESS_TOKEN=your_access_token_here
To start the server, run:
npm start
The server will be running on http://localhost:3000
.
-
GET / Returns a simple message indicating the API is working.
-
GET /card_token Generates a card token using mock credit card details.
-
GET /payment_methods Consult all the available payment methods and obtain a list with the details of each one and its properties.
-
GET /preference Generate a preference with the information of a product or service and obtain the necessary URL to start the payment flow.
-
GET /preference/:preferenceId Retrieves preference details by its ID.
-
GET /payment Creates a payment using the mock credit card and card token.
-
GET /payment/:id Retrieves payment details by its ID.
-
POST /cancel_payment/:id Cancels a payment by its ID.
-
POST /notification Handles incoming notifications from Mercado Pago.
To test the endpoints, you can use tools like Postman or curl. For example, to get a card token:
curl http://localhost:3000/card_token