### Full Getting Started Example Source: https://github.com/mercadopago/sdk-nodejs/blob/master/README.md A complete example demonstrating the initialization of the SDK client, API object, request body creation, and making the order creation request. ```javascript // Step 1: Import the parts of the module you want to use import { MercadoPagoConfig, Order } from "mercadopago"; // Step 2: Initialize the client object const client = new MercadoPagoConfig({ accessToken: "", options: { timeout: 5000 }, }); // Step 3: Initialize the API object const order = new Order(client); // Step 4: Create the request object const body = { type: "online", processing_mode: "automatic", total_amount: "1000.00", external_reference: "ext_ref_1234", payer: { email: "", }, transactions: { payments: [ { amount: "1000.00", payment_method: { id: "master", type: "credit_card", token: "", installments: 1, statement_descriptor: "Store name", }, }, ], }, }; // Step 5: Create request options object - Optional const requestOptions = { idempotencyKey: "", }; // Step 6: Make the request order.create({ body, requestOptions }).then(console.log).catch(console.error); ``` -------------------------------- ### Resource Methods (Create, Update, Get, Remove) Source: https://github.com/mercadopago/sdk-nodejs/wiki/Usage The SDK dynamically creates basic methods for each resource, such as create (POST), update (PUT), get (GET), and remove (DELETE). These methods can be invoked with configurations and a callback, or using promises. ```APIDOC ## Resource Methods ### Description Basic methods for resources like Payment and Preference are dynamically created by the SDK. ### Methods - `create` (POST) - `update` (PUT) - `get` (GET) - `remove` (DELETE) ### Usage with Callback ```javascript mercadopago.resource.create( ..., configurations, callback ); ``` ### Usage with Promises ```javascript mercadopago.resource.create( ..., configurations ).then().catch(); ``` ``` -------------------------------- ### Get Pre-Approval by ID with SDK Source: https://github.com/mercadopago/sdk-nodejs/wiki/Pre-Approval Use the `get` method to retrieve a specific pre-approval by its ID. Requires ID and configurations. ```javascript mercadopago.preapproval.get(id, configurations, callback); ``` -------------------------------- ### Install Mercado Pago NodeJS SDK Source: https://github.com/mercadopago/sdk-nodejs/blob/master/README.md Install the Mercado Pago SDK for NodeJS using npm. This command adds the SDK as a dependency to your project. ```sh $ npm install --save mercadopago ``` -------------------------------- ### Manual Pagination Example Source: https://github.com/mercadopago/sdk-nodejs/wiki/Pagination Demonstrates how to manually fetch the next page of results by specifying the offset in the query parameters. ```javascript mercadopago.payment.search({ qs: { 'collector.id': 'me', pagination: { offset: 30 } } }).then(function (mpResponse) { console.log(mpResponse); }); ``` -------------------------------- ### Get a Preference by ID using get Source: https://github.com/mercadopago/sdk-nodejs/wiki/Preferences Retrieve a preference using its ID with the `get` method. This method requires the preference ID, configurations, and a callback. ```javascript mercadopago.preferences.get(id, configurations, callback); ``` -------------------------------- ### Install pre-commit Git Hooks Source: https://github.com/mercadopago/sdk-nodejs/blob/master/CODING_GUIDELINES.md Set up the git hook scripts for the project to automatically enforce code style and formatting before each commit. Ensure you are in the SDK project folder. ```bash $ pre-commit install ``` -------------------------------- ### Call Payment Get API Source: https://github.com/mercadopago/sdk-nodejs/wiki/Usage Demonstrates how to call the GET method for payments, passing the ID as a parameter. ```javascript mercadopago.payment.get(1, {}, function (){}); ``` -------------------------------- ### Check pre-commit Version Source: https://github.com/mercadopago/sdk-nodejs/blob/master/CODING_GUIDELINES.md Verify that the pre-commit tool is installed by checking its version. This is a prerequisite for setting up git hooks. ```bash $ pre-commit --version pre-commit 2.17.0 ``` -------------------------------- ### Get Preference Source: https://github.com/mercadopago/sdk-nodejs/wiki/Preferences Retrieves a preference by its ID. This can be done using either `get` or `findById`. ```APIDOC ## Get Preference ### Description Retrieves a preference by its ID. ### Method GET (implied) ### Endpoint /checkout/preferences/{id} (implied) ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the preference to retrieve. #### Query Parameters None #### Request Body None ### Request Example ```javascript mercadopago.preferences.get('123456789', { // configurations }, (response) => { // callback }); ``` ### Response #### Success Response (200) - **response** (object) - The preference object. #### Response Example ```json { "response": { ... } } ``` ``` -------------------------------- ### Using hasNext and next with Callbacks Source: https://github.com/mercadopago/sdk-nodejs/wiki/Pagination Checks if a next page of results exists using `hasNext()` and fetches it using `next()` if available. This example uses callbacks. ```javascript mercadopago.payment.search({ qs: { 'collector.id': 'me' } }, function(err, mpResponse) { if (mpResponse.hasNext()) { return mpRepsonse.next(function (nextPage) { console.log(nextPage); }); } }); ``` -------------------------------- ### Get Payment with Callback Source: https://github.com/mercadopago/sdk-nodejs/wiki/Usage Demonstrates retrieving a payment by its ID using a callback function for handling the response. ```javascript mercadopago.payment.get(1, {}, function(error, response){ if (error) return console.log('An error ocurred: ' + error.message); console.log(response); }); ``` -------------------------------- ### Using hasNext and next with Promises Source: https://github.com/mercadopago/sdk-nodejs/wiki/Pagination Checks if a next page of results exists using `hasNext()` and fetches it using `next()` if available. This example utilizes Promise chaining. ```javascript mercadopago.payment.search({ qs: { 'collector.id': 'me' } }).then(function (mpResponse) { if (mpResponse.hasNext()) { return mpRepsonse.next(); } }).then(function (nextPage) { console.log(nextPage); }); ``` -------------------------------- ### Example IPN Response Body Source: https://github.com/mercadopago/sdk-nodejs/wiki/IPN-Notifications This is an example of the response body received after managing an IPN notification. It contains detailed information about the payment, including status, transaction details, and payer information. ```javascript mercadopagoIpnResponse { body: { id: 2556382, date_created: '2017-01-19T17:00:21.000-04:00', date_approved: null, date_last_updated: '2017-01-19T17:00:21.000-04:00', money_release_date: null, operation_type: 'regular_payment', issuer_id: null, payment_method_id: 'rapipago', payment_type_id: 'ticket', status: 'pending', status_detail: 'pending_waiting_payment', currency_id: 'ARS', description: 'Descripción', live_mode: false, sponsor_id: null, authorization_code: null, collector_id: 239656545, payer: { type: 'guest', id: null, email: 'test_user_3931694@testuser.com', identification: [Object], phone: [Object], first_name: 'Test', last_name: 'Test', entity_type: null }, metadata: {}, order: {}, external_reference: null, transaction_amount: 10, transaction_amount_refunded: 0, coupon_amount: 0, differential_pricing_id: null, deduction_schema: null, transaction_details: { net_received_amount: 0, total_paid_amount: 10, overpaid_amount: 0, external_resource_url: 'http://www.mercadopago.com/mla/sandbox/payments/ticket/helper?payment_method=rapipago', installment_amount: 0, financial_institution: null, payment_method_reference_id: '2556383' }, fee_details: [], captured: true, binary_mode: false, call_for_authorize_id: null, statement_descriptor: null, installments: 1, card: {}, notification_url: null, refunds: [] }, status: 200, topic: 'payment' } ``` -------------------------------- ### Example Payment Response Source: https://github.com/mercadopago/sdk-nodejs/wiki/Architecture Illustrates the structure of the response object received after attempting to create a payment. Includes details like payment ID, status, and transaction information. ```javascript mercadopagoResponse { body: { id: 2556382, date_created: '2017-01-19T17:00:21.000-04:00', date_approved: null, date_last_updated: '2017-01-19T17:00:21.000-04:00', money_release_date: null, operation_type: 'regular_payment', issuer_id: null, payment_method_id: 'rapipago', payment_type_id: 'ticket', status: 'pending', status_detail: 'pending_waiting_payment', currency_id: 'ARS', description: 'Descripción', live_mode: false, sponsor_id: null, authorization_code: null, collector_id: 239656545, payer: { type: 'guest', id: null, email: 'test_user_3931694@testuser.com', identification: [Object], phone: [Object], first_name: 'Test', last_name: 'Test', entity_type: null }, metadata: {}, order: {}, external_reference: null, transaction_amount: 10, transaction_amount_refunded: 0, coupon_amount: 0, differential_pricing_id: null, deduction_schema: null, transaction_details: { net_received_amount: 0, total_paid_amount: 10, overpaid_amount: 0, external_resource_url: 'http://www.mercadopago.com/mla/sandbox/payments/ticket/helper?payment_method=rapipago', installment_amount: 0, financial_institution: null, payment_method_reference_id: '2556383' }, fee_details: [], captured: true, binary_mode: false, call_for_authorize_id: null, statement_descriptor: null, installments: 1, card: {}, notification_url: null, refunds: [] }, status: 201, idempotency: '7fea2db6-fc84-436f-b6f4-457f7f5f151e', pagination: undefined } ``` -------------------------------- ### Get Payment Details Source: https://github.com/mercadopago/sdk-nodejs/wiki/IPN-Notifications To retrieve payment information, make a GET request to the payments endpoint using the payment ID and your access token. ```http /v1/payments/[ID]?access_token=[ACCESS_TOKEN] ``` -------------------------------- ### Get Payment with Promises Source: https://github.com/mercadopago/sdk-nodejs/wiki/Usage Illustrates retrieving a payment by its ID using promises, with separate .then() for success and error handling. ```javascript mercadopago.payment.get(1).then(function (response) { console.log(response); }).then(function (error) { console.log('An error ocurred: ' + error.message); }); ``` -------------------------------- ### Call Customer Card Get API Source: https://github.com/mercadopago/sdk-nodejs/wiki/Usage Demonstrates how to retrieve a specific card for a customer using their IDs. ```javascript mercadopago.customers.cards.get(1, 10, {}, function () {}); ``` -------------------------------- ### Get Pre Approval Source: https://github.com/mercadopago/sdk-nodejs/wiki/Pre-Approval Retrieves a specific pre-approval agreement by its ID. ```APIDOC ## Get Pre Approval ### Description Retrieves a specific pre-approval agreement by its ID. ### Method GET (inferred from SDK usage) ### Endpoint /v1/preapproval/{id} (inferred from SDK usage) ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the pre-approval to retrieve. #### Request Body - **configurations** (object) - Optional - Configuration settings. ### Request Example ```javascript mercadopago.preapproval.get(123, configurations, callback); ``` ``` -------------------------------- ### Get Card - Node.js Source: https://github.com/mercadopago/sdk-nodejs/wiki/Customers-&-Cards Use this method to retrieve a specific card for a customer. Requires the customer ID, configurations, and a callback function. ```javascript mercadopago.customers.cards.get(customer_id, configurations, callback); ``` -------------------------------- ### Get Customer by ID - Node.js Source: https://github.com/mercadopago/sdk-nodejs/wiki/Customers-&-Cards Use this method to retrieve a specific customer using their ID. Requires the customer ID, configurations, and a callback function. ```javascript mercadopago.customers.get(id, configurations, callback); ``` -------------------------------- ### Get Merchant Order by ID - Node.js SDK Source: https://github.com/mercadopago/sdk-nodejs/wiki/Merchant-Orders Retrieve a specific Merchant Order using its ID with the `get` method. Requires ID and callback. ```javascript mercadopago.merchant_orders.get(id, configurations, callback); ``` -------------------------------- ### Find Pre Approval By ID Source: https://github.com/mercadopago/sdk-nodejs/wiki/Pre-Approval Retrieves a specific pre-approval agreement by its ID. This is an alternative to the `get` method. ```APIDOC ## Find Pre Approval By ID ### Description Retrieves a specific pre-approval agreement by its ID. This is an alternative to the `get` method. ### Method GET (inferred from SDK usage) ### Endpoint /v1/preapproval/{id} (inferred from SDK usage) ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the pre-approval to retrieve. #### Request Body - **configurations** (object) - Optional - Configuration settings. ### Request Example ```javascript mercadopago.preapproval.findById(123, configurations, callback); ``` ``` -------------------------------- ### Get Merchant Order Details Source: https://github.com/mercadopago/sdk-nodejs/wiki/IPN-Notifications To retrieve merchant order information, make a GET request to the merchant orders endpoint using the order ID and your access token. ```http /merchant_orders/[ID]?access_token=[ACCESS_TOKEN] ``` -------------------------------- ### Get All Cards for Customer - Node.js Source: https://github.com/mercadopago/sdk-nodejs/wiki/Customers-&-Cards Use this method to retrieve all cards associated with a specific customer. Requires the customer ID, card ID, configurations, and a callback function. ```javascript mercadopago.customers.cards.all(customer_id, card_id, configurations, callback); ``` -------------------------------- ### Get Payment Source: https://github.com/mercadopago/sdk-nodejs/wiki/Payment Retrieves details of a specific payment by its ID. ```APIDOC ## get Payment ### Description Retrieves the details of a specific payment using its ID. ### Method GET (inferred from context of retrieving a resource) ### Endpoint /v1/payments/{id} (inferred from common REST patterns and SDK usage) ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the payment to retrieve. #### Query Parameters None #### Request Body None ### Request Example ```javascript mercadopago.payment.get(id, configurations, callback); ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the payment. - **status** (string) - The current status of the payment. (Other fields may be present based on API response) ``` -------------------------------- ### Chained Payment Operations Source: https://github.com/mercadopago/sdk-nodejs/wiki/Usage Shows a sequence of operations: getting payment details and then cancelling the payment, using promises. ```javascript mercadolibre.payment.get(1).then(function (mpResponse) { // Cancelling a payment return mercadolibre.payment.update({ id: mpResponse.body.id, status: 'cancelled' }); }).catch(function (error) { console.log('An error ocurred updating the payment'); }); ``` -------------------------------- ### Get a Payment by ID with mercadopago.payment.get Source: https://github.com/mercadopago/sdk-nodejs/wiki/Payment Use this method to retrieve a specific payment by its ID. Requires the payment ID, configurations, and a callback function. ```javascript mercadopago.payment.get(id, configurations, callback); ``` -------------------------------- ### Get a Money Request by ID Source: https://github.com/mercadopago/sdk-nodejs/wiki/Money-Requests Retrieve a specific Money Request using its ID. Requires the ID, configurations, and a callback function. ```javascript mercadopago.money_requests.get(id, configurations, callback); ``` -------------------------------- ### Find a Money Request by ID Source: https://github.com/mercadopago/sdk-nodejs/wiki/Money-Requests Use findById to get a Money Request. This method requires the request ID, configurations, and a callback. ```javascript mercadopago.money_requests.findById(id, configurations, callback); ``` -------------------------------- ### Basic Resource Creation (Callback) Source: https://github.com/mercadopago/sdk-nodejs/wiki/Usage Illustrates the basic syntax for creating a resource using a callback function for handling the response. ```javascript mercadopago.resource.create( ..., configurations, callback ); ``` -------------------------------- ### Configure with Access Token and Sandbox Mode Source: https://github.com/mercadopago/sdk-nodejs/wiki/Configure Enable sandbox mode for testing purposes while providing an access token. ```javascript mercadopago.configure({ sandbox: true, access_token: 'ACCESS_TOKEN' }); ``` -------------------------------- ### Create Pre-Approval with SDK Source: https://github.com/mercadopago/sdk-nodejs/wiki/Pre-Approval Use the `create` method to initiate a new pre-approval. Requires payload and configurations. ```javascript mercadopago.preapproval.create(payload, configurations, callback); ``` -------------------------------- ### Create a Preference using create Source: https://github.com/mercadopago/sdk-nodejs/wiki/Preferences Use the `create` method to initiate a new preference. It requires payload, configurations, and a callback function. ```javascript mercadopago.preferences.create(payload, configurations, callback); ``` -------------------------------- ### Get Merchant Order Source: https://github.com/mercadopago/sdk-nodejs/wiki/Merchant-Orders Retrieves a Merchant Order by its ID. This can be done using either `get` or `findById`. ```APIDOC ## Get Merchant Order ### Description Retrieves a Merchant Order by its ID. ### Method GET (inferred) ### Endpoint /merchant_orders/{id} (inferred) ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the merchant order to retrieve. #### Query Parameters None #### Request Body None ### Request Example ```javascript mercadopago.merchant_orders.get('order_id', {}, (callback) => { // handle response }); ``` ### Response #### Success Response (200) - **id** (string) - The ID of the merchant order. - **மையான** (string) - Other fields related to the merchant order. ``` -------------------------------- ### Basic Resource Creation (Promises) Source: https://github.com/mercadopago/sdk-nodejs/wiki/Usage Demonstrates creating a resource using promises for asynchronous operations, allowing for chaining with .then() and .catch(). ```javascript mercadopago.resource.create( ..., configurations ).then().catch(); ``` -------------------------------- ### Get Money Request Source: https://github.com/mercadopago/sdk-nodejs/wiki/Money-Requests Retrieves a specific Money Request by its ID. This method can be invoked using either `get` or `findById`. ```APIDOC ## Get Money Request ### Description Retrieves a specific Money Request by its ID. ### Method GET (inferred) ### Endpoint /v1/money-requests/{id} (inferred) ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the money request to retrieve. #### Query Parameters None #### Request Body None ### Request Example ```javascript mercadopago.money_requests.get('YOUR_MONEY_REQUEST_ID', { // configurations details }, (callback) => { // handle response }); ``` ### Response #### Success Response (200) - **id** (string) - The ID of the money request. - **status** (string) - The status of the money request. - **amount** (number) - The requested amount. ``` -------------------------------- ### Search Payments with Query String Source: https://github.com/mercadopago/sdk-nodejs/wiki/Usage Shows how to use the 'qs' configuration to send parameters in the query string for the payment search API. ```javascript var configurations = { qs: { 'payer.id': 'me' } }; mercadopago.payment.search(configurations, callback); ``` -------------------------------- ### Search Pre-Approvals with SDK Source: https://github.com/mercadopago/sdk-nodejs/wiki/Pre-Approval Use the `search` method to find pre-approvals. Requires configurations. ```javascript mercadopago.preapproval.search(configurations, callback); ``` -------------------------------- ### Initialize Mercado Pago SDK Client Source: https://github.com/mercadopago/sdk-nodejs/blob/master/README.md Initialize the MercadoPagoConfig client with your access token and optional request options like timeout and idempotency key. ```javascript const client = new MercadoPagoConfig({ accessToken: "", options: { timeout: 5000 }, }); ``` -------------------------------- ### Configure SDK Source: https://github.com/mercadopago/sdk-nodejs/wiki/SDK-Instantiation Use this method to configure the SDK with your access token. Configuration is done once and cached by Node.js for subsequent module loads. ```javascript var mercadopago = require('mercadopago'); mercadopago.configure({ access_token: 'ACCESS_TOKEN' }); ``` -------------------------------- ### Configure with Access Token Source: https://github.com/mercadopago/sdk-nodejs/wiki/Configure Use this configuration when you have an access token. ```javascript mercadopago.configure({ access_token: 'ACCESS_TOKEN' }); ``` -------------------------------- ### Invalid Configuration: Sandbox Only Source: https://github.com/mercadopago/sdk-nodejs/wiki/Configure Providing only the sandbox option without authentication credentials is not a valid configuration. ```javascript mercadopago.configure({ sandbox: true }); ``` -------------------------------- ### Configure with Client ID and Client Secret Source: https://github.com/mercadopago/sdk-nodejs/wiki/Configure Use this configuration when you have a client ID and client secret. ```javascript mercadopago.configure({ client_id: 'CLIENT_ID', client_secret: 'CLIENT_SECRET' }); ``` -------------------------------- ### Instantiate SDK (Deprecated) Source: https://github.com/mercadopago/sdk-nodejs/wiki/SDK-Instantiation This method is deprecated and intended for backward compatibility with older SDK versions. Avoid using it in new integrations. ```javascript var mercadopago = require('mercadopago'); var sdk = new mercadopago({ access_token: 'ACCESS_TOKEN' }); ``` -------------------------------- ### Initialize Mercado Pago SDK Client with Idempotency Source: https://github.com/mercadopago/sdk-nodejs/blob/master/README.md Initialize the MercadoPagoConfig client, including the idempotencyKey option for safe request retries. ```javascript const client = new MercadoPagoConfig({ accessToken: "", options: { timeout: 5000, idempotencyKey: "" }, }); ``` -------------------------------- ### Create Customer - Node.js Source: https://github.com/mercadopago/sdk-nodejs/wiki/Customers-&-Cards Use this method to create a new customer. Requires payload, configurations, and a callback function. ```javascript mercadopago.customers.create(payload, configurations, callback); ``` -------------------------------- ### Invalid Configuration: Empty Object Source: https://github.com/mercadopago/sdk-nodejs/wiki/Configure An empty configuration object is invalid. You must provide authentication credentials. ```javascript mercadopago.configure({}); ``` -------------------------------- ### Import Mercado Pago SDK Modules Source: https://github.com/mercadopago/sdk-nodejs/blob/master/README.md Import necessary classes like MercadoPagoConfig and Order from the mercadopago module for SDK usage. ```javascript import { MercadoPagoConfig, Order } from "mercadopago"; ``` -------------------------------- ### Create a Payment Source: https://github.com/mercadopago/sdk-nodejs/wiki/Architecture Use the 'payment.create' method to initiate a payment. Provide transaction details, payment method, and payer information. Handles success and error responses via Promises. ```javascript mercadopago.payment.create({ description: 'Buying a PS4', transaction_amount: 10500, payment_method_id: 'rapipago', payer: { email: 'test_user_3931694@testuser.com', identification: { type: 'DNI', number: '34123123' } } }).then(function (mpResponse) { console.log(mpResponse); }).catch(function (mpError) { console.log(err); }); ``` -------------------------------- ### Access SDK Resources Source: https://github.com/mercadopago/sdk-nodejs/wiki/Architecture Import the SDK and access its exposed resources like 'payment'. This allows you to see available methods for each resource. ```javascript var mercadopago = require('mercadopago'); console.log(mercadopago.payment); /* ... create: [Function], update: [Function], get: [Function], search: [Function], ... */ ``` -------------------------------- ### Search Customers - Node.js Source: https://github.com/mercadopago/sdk-nodejs/wiki/Customers-&-Cards Use this method to search for customers. Requires configurations and a callback function. ```javascript mercadopago.customers.search(configurations, callback); ``` -------------------------------- ### Save Pre-Approval with SDK Source: https://github.com/mercadopago/sdk-nodejs/wiki/Pre-Approval Use the `save` method to create a new pre-approval. Requires payload and configurations. ```javascript mercadopago.preapproval.save(payload, configurations, callback); ``` -------------------------------- ### Create a Money Request Source: https://github.com/mercadopago/sdk-nodejs/wiki/Money-Requests Use the create method to initiate a new Money Request. Requires payload, configurations, and a callback function. ```javascript mercadopago.money_requests.create(payload, configurations, callback); ``` -------------------------------- ### Create Merchant Order - Node.js SDK Source: https://github.com/mercadopago/sdk-nodejs/wiki/Merchant-Orders Use the `create` method to initiate a new Merchant Order. Requires payload and callback. ```javascript mercadopago.merchant_orders.create(payload, configurations, callback); ``` -------------------------------- ### Create a Payment with mercadopago.payment.create Source: https://github.com/mercadopago/sdk-nodejs/wiki/Payment Use this method to create a new payment. Requires payload, configurations, and a callback function. ```javascript mercadopago.payment.create(payload, configurations, callback); ``` -------------------------------- ### Initialize Order API Object Source: https://github.com/mercadopago/sdk-nodejs/blob/master/README.md Initialize the Order API object by passing the previously configured client object. ```javascript const order = new Order(client); ``` -------------------------------- ### Create Card - Node.js Source: https://github.com/mercadopago/sdk-nodejs/wiki/Customers-&-Cards Use this method to create a card for a customer. The payload must include the customer's ID. Requires payload, configurations, and a callback function. ```javascript mercadopago.customers.cards.create(payload, configurations, callback); ``` -------------------------------- ### Manual Retry of Payment Creation Source: https://github.com/mercadopago/sdk-nodejs/wiki/Response-&-Error Demonstrates how to manually retry a payment creation request if the initial attempt fails, by reusing the payment object and providing the idempotency key from the error. ```javascript var payment = { description: 'Descripción', transaction_amount: 10, payment_method_id: 'rapipago', payer: { email: 'test_user_3931694@testuser.com', identification: { type: 'DNI', number: '34214577' } } }; mercadopago.payment.create(payment).then(function (response) { console.log(response); }).catch(function (err) { // Manually retry mercadopago.payment.create(payment, { idempotency: err.idempotency }).then(function (response) { console.log(response); }).catch(function () { // Another Error }); }); ``` -------------------------------- ### Find Pre-Approval by ID with SDK Source: https://github.com/mercadopago/sdk-nodejs/wiki/Pre-Approval Use the `findById` method to retrieve a specific pre-approval by its ID. Requires ID and configurations. ```javascript mercadopago.preapproval.findById(id, configurations, callback); ``` -------------------------------- ### Invalid Configuration: Client ID Only Source: https://github.com/mercadopago/sdk-nodejs/wiki/Configure Providing only the client ID without the client secret is an invalid configuration. ```javascript mercadopago.configure({ client_id: 'CLIENT_ID' }); ``` -------------------------------- ### Save a Preference using save Source: https://github.com/mercadopago/sdk-nodejs/wiki/Preferences The `save` method is used to create a preference. It takes payload, configurations, and a callback. ```javascript mercadopago.preferences.save(payload, configurations, callback); ``` -------------------------------- ### Make Order Creation Request Source: https://github.com/mercadopago/sdk-nodejs/blob/master/README.md Make the API request to create an order using the order object and the prepared request body. Handles success and error logging. ```javascript order.create({ body }).then(console.log).catch(console.error); ``` -------------------------------- ### Create Preference Source: https://github.com/mercadopago/sdk-nodejs/wiki/Preferences Creates a new preference. This method can be called using either `create` or `save`. ```APIDOC ## Create Preference ### Description Creates a new preference. ### Method POST (implied) ### Endpoint /checkout/preferences (implied) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **payload** (object) - Required - The preference data. - **configurations** (object) - Optional - Configuration settings. ### Request Example ```javascript mercadopago.preferences.create({ // preference data }, { // configurations }, (response) => { // callback }); ``` ### Response #### Success Response (200) - **id** (string) - The ID of the created preference. - **response** (object) - The full response object. #### Response Example ```json { "id": "123456789", "response": { ... } } ``` ``` -------------------------------- ### Invalid Configuration: Client Secret Only Source: https://github.com/mercadopago/sdk-nodejs/wiki/Configure Providing only the client secret without the client ID is an invalid configuration. ```javascript mercadopago.configure({ client_secret: 'CLIENT_SECRET' }); ``` -------------------------------- ### Save Customer - Node.js Source: https://github.com/mercadopago/sdk-nodejs/wiki/Customers-&-Cards Use this method to save a customer. Requires payload, configurations, and a callback function. ```javascript mercadopago.customers.save(payload, configurations, callback); ``` -------------------------------- ### Find Customer by ID - Node.js Source: https://github.com/mercadopago/sdk-nodejs/wiki/Customers-&-Cards Use this method to find a specific customer by their ID. Requires the customer ID, configurations, and a callback function. ```javascript mercadopago.customers.findById(id, configurations, callback); ``` -------------------------------- ### Create Pre Approval Source: https://github.com/mercadopago/sdk-nodejs/wiki/Pre-Approval Creates a new pre-approval agreement. This method can be invoked using either `create` or `save`. ```APIDOC ## Create Pre Approval ### Description Creates a new pre-approval agreement. ### Method POST (inferred from SDK usage) ### Endpoint /v1/preapproval (inferred from SDK usage) ### Parameters #### Request Body - **payload** (object) - Required - The data for the pre-approval. - **configurations** (object) - Optional - Configuration settings. ### Request Example ```javascript mercadopago.preapproval.create({ // payload details }, configurations, callback); ``` ## Save Pre Approval ### Description Creates a new pre-approval agreement. This method can be invoked using either `create` or `save`. ### Method POST (inferred from SDK usage) ### Endpoint /v1/preapproval (inferred from SDK usage) ### Parameters #### Request Body - **payload** (object) - Required - The data for the pre-approval. - **configurations** (object) - Optional - Configuration settings. ### Request Example ```javascript mercadopago.preapproval.save({ // payload details }, configurations, callback); ``` ``` -------------------------------- ### Pause Pre-Approval with SDK Source: https://github.com/mercadopago/sdk-nodejs/wiki/Pre-Approval Use the `pause` wrapper method to easily pause a pre-approval. Requires ID. ```javascript mercadopago.preapproval.pause(id, configurations, callback); ``` -------------------------------- ### Update Pre-Approval with SDK Source: https://github.com/mercadopago/sdk-nodejs/wiki/Pre-Approval Use the `update` method to modify an existing pre-approval. Requires payload and configurations. ```javascript mercadopago.preapproval.update(payload, configurations, callback); ``` -------------------------------- ### Configurations Parameter Source: https://github.com/mercadopago/sdk-nodejs/wiki/Usage The optional configurations parameter is a JSON object that allows specifying query string parameters, idempotency keys, and overriding access tokens. ```APIDOC ## Configurations Parameter ### Description An optional JSON object to customize request behavior. ### Options - `qs` (Object): Parameters to send in the querystring. Example: ```javascript var configurations = { qs: { 'payer.id': 'me' } }; mercadopago.payment.search(configurations, callback); ``` This will generate a URL like: `https://api.mercadopago.com/v1/payments/search?payer.id=me` - `idempotency` (string): Custom UUID for idempotency to prevent duplicate operations. Example: ```javascript mercadopago.payment.create(payment).then(function (mpResponse) { // ... }).catch(function (mpError) { return mercadopago.payment.create(payment, { qs: { idempotency: mpError.idempotency } }); }); ``` - `access_token` (string): Override the default `access_token` for a specific operation. Example: ```javascript mercadopago.payment.create(payment, { access_token: 'MY_MERCHANT_ACCESS_TOKEN', }).then(function (mpResponse) { // ... }); ``` ``` -------------------------------- ### Idempotency for Safe Retries Source: https://github.com/mercadopago/sdk-nodejs/wiki/Usage Demonstrates how to use idempotency keys to prevent duplicate operations when retrying failed requests. The SDK automatically generates an 'Idempotency-Key' header. ```javascript var payment = { description: 'Buying a PS4', transaction_amount: 10500, payment_method_id: 'rapipago', payer: { email: 'test_user_3931694@testuser.com', identification: { type: 'DNI', number: '34123123' } } }; mercadopago.payment.create(payment).then(function (mpResponse) { console.log(mpResponse); }).catch(function (mpError) { return mercadopago.payment.create(payment, { qs: { idempotency: mpError.idempotency } }); }).then(function(mpResponse){ console.log(mpResponse); }); ``` ```javascript mercadopagoError { name: 'MercadoPagoError', message: 'Lost Connection', cause: 'Unknown Cause', status: 500, idempotency: '7fea2db6-fc84-436f-b6f4-457f7f5f151e' } ``` -------------------------------- ### Update Customer - Node.js Source: https://github.com/mercadopago/sdk-nodejs/wiki/Customers-&-Cards Use this method to update an existing customer. Requires payload, configurations, and a callback function. ```javascript mercadopago.customers.update(payload, configurations, callback); ``` -------------------------------- ### Simplified Pre-Approval Cancellation Source: https://github.com/mercadopago/sdk-nodejs/wiki/Pre-Approval Shows the simplified usage of the `cancel` wrapper method for pre-approvals. ```javascript mercadopago.preapproval.cancel(1).then.catch(); ``` -------------------------------- ### Create Order Request Body Source: https://github.com/mercadopago/sdk-nodejs/blob/master/README.md Construct the request body for creating an order, specifying payment details, payer information, and external references. ```javascript const body = { type: "online", processing_mode: "automatic", total_amount: "1000.00", external_reference: "ext_ref_1234", payer: { email: "", }, transactions: { payments: [ { amount: "1000.00", payment_method: { id: "master", type: "credit_card", token: "", installments: 1, statement_descriptor: "Store name", }, }, ], }, }; ``` -------------------------------- ### Overriding Access Token Source: https://github.com/mercadopago/sdk-nodejs/wiki/Usage Shows how to override the default 'access_token' for a specific operation, useful for impersonating merchants with MP Connect. ```javascript var payment = { description: 'Buying a PS4', transaction_amount: 10500, payment_method_id: 'rapipago', payer: { email: 'test_user_3931694@testuser.com', identification: { type: 'DNI', number: '34123123' } } }; mercadopago.payment.create(payment, { access_token: 'MY_MERCHANT_ACCESS_TOKEN', }).then(function (mpResponse) { }); ``` -------------------------------- ### Using Callbacks Source: https://github.com/mercadopago/sdk-nodejs/wiki/Callbacks-&-Promises Handle asynchronous operations using the traditional Node.js callback pattern. Ensure to check for errors first. ```javascript library.method(function (err, res) { if (err) return console.log(err); console.log(res); }) ``` -------------------------------- ### MIT License Information Source: https://github.com/mercadopago/sdk-nodejs/blob/master/README.md This snippet displays the license under which the Mercado Pago SDK for Node.js is distributed. It is the MIT license. ```plaintext MIT license. Copyright (c) 2024 - Mercado Pago / Mercado Libre For more information, see the LICENSE file. ``` -------------------------------- ### Cancel Pre-Approval using Update Source: https://github.com/mercadopago/sdk-nodejs/wiki/Pre-Approval Demonstrates canceling a pre-approval by updating its status to 'cancelled'. This is an alternative to the `cancel` wrapper method. ```javascript mercadopago.preapproval.update({ id: 1, status: 'cancelled' }).then().catch(); ``` -------------------------------- ### Create Money Request Source: https://github.com/mercadopago/sdk-nodejs/wiki/Money-Requests Creates a new Money Request. This method can be invoked using either `create` or `save`. ```APIDOC ## Create Money Request ### Description Creates a new Money Request. ### Method POST (inferred) ### Endpoint /v1/money-requests (inferred) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **payload** (object) - Required - The data for the money request. - **configurations** (object) - Optional - Configuration options for the request. ### Request Example ```javascript mercadopago.money_requests.create({ // payload details }, { // configurations details }, (callback) => { // handle response }); ``` ### Response #### Success Response (200) - **id** (string) - The ID of the created money request. - **status** (string) - The status of the money request. ``` -------------------------------- ### Using Promises Source: https://github.com/mercadopago/sdk-nodejs/wiki/Callbacks-&-Promises Handle asynchronous operations using promises for a more modern approach. Chain .then() for success and .catch() for errors. ```javascript library.method().then(function (res) { console.log(res); }).catch(function (err) { console.log(err); }); ``` -------------------------------- ### Find Card by ID - Node.js Source: https://github.com/mercadopago/sdk-nodejs/wiki/Customers-&-Cards Use this method to find a specific card for a customer. Requires the customer ID, configurations, and a callback function. ```javascript mercadopago.customers.cards.findById(customer_id, configurations, callback); ``` -------------------------------- ### Create Payment Source: https://github.com/mercadopago/sdk-nodejs/wiki/Payment Creates a new payment transaction. ```APIDOC ## create Payment ### Description Creates a new payment. ### Method POST (inferred from context of creating a resource) ### Endpoint /v1/payments (inferred from common REST patterns and SDK usage) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **payload** (object) - Required - The payment details. - **configurations** (object) - Optional - SDK configurations. - **callback** (function) - Optional - Callback function for asynchronous operations. ### Request Example ```javascript mercadopago.payment.create(payload, configurations, callback); ``` ### Response #### Success Response (200 or 201) - **id** (string) - The unique identifier for the payment. - **status** (string) - The current status of the payment. (Other fields may be present based on API response) ``` -------------------------------- ### Cancel Pre-Approval with SDK Source: https://github.com/mercadopago/sdk-nodejs/wiki/Pre-Approval Use the `cancel` wrapper method to easily cancel a pre-approval. Requires ID. ```javascript mercadopago.preapproval.cancel(id, configurations, callback); ``` -------------------------------- ### Save Card - Node.js Source: https://github.com/mercadopago/sdk-nodejs/wiki/Customers-&-Cards Use this method to save a card for a customer. The payload must include the customer's ID. Requires payload, configurations, and a callback function. ```javascript mercadopago.customers.cards.save(payload, configurations, callback); ``` -------------------------------- ### Retry Payment Creation with Error Object's Retry Method Source: https://github.com/mercadopago/sdk-nodejs/wiki/Response-&-Error Shows how to use the 'retry' function available on the mercadopagoError object to re-execute a failed request, simplifying the error handling process. ```javascript mercadopago.payment.create({ description: 'Descripción', transaction_amount: 10, payment_method_id: 'rapipago', payer: { email: 'test_user_3931694@testuser.com', identification: { type: 'DNI', number: '34214577' } } }).then(function (response) { console.log(response); }).catch(function (err) { err.retry().then(function (response) { console.log(response); }).catch(function () { // Another Error }); }); ``` -------------------------------- ### Delete Customer - Node.js Source: https://github.com/mercadopago/sdk-nodejs/wiki/Customers-&-Cards Use this method to remove a customer. Requires the customer ID, configurations, and a callback function. ```javascript mercadopago.customers.delete(id, configurations, callback); ``` -------------------------------- ### Customer Management Source: https://github.com/mercadopago/sdk-nodejs/wiki/Customers-&-Cards Methods for managing customer resources. ```APIDOC ## create Customer ### Description Creates a new customer. ### Method `mercadopago.customers.create(payload, configurations, callback)` ``` ```APIDOC ## save Customer ### Description Creates a new customer. ### Method `mercadopago.customers.save(payload, configurations, callback)` ``` ```APIDOC ## update Customer ### Description Updates an existing customer. ### Method `mercadopago.customers.update(payload, configurations, callback)` ``` ```APIDOC ## get Customer ### Description Retrieves a customer by their ID. ### Method `mercadopago.customers.get(id, configurations, callback)` ``` ```APIDOC ## findById Customer ### Description Retrieves a customer by their ID. ### Method `mercadopago.customers.findById(id, configurations, callback)` ``` ```APIDOC ## search Customers ### Description Searches for customers. ### Method `mercadopago.customers.search(configurations, callback)` ``` ```APIDOC ## delete Customer ### Description Removes a customer. ### Method `mercadopago.customers.delete(id, configurations, callback)` ``` -------------------------------- ### Search Payments with mercadopago.payment.search Source: https://github.com/mercadopago/sdk-nodejs/wiki/Payment Use this method to search for payments. Requires configurations and a callback function. ```javascript mercadopago.payment.search(configurations, callback); ``` -------------------------------- ### Save a Money Request Source: https://github.com/mercadopago/sdk-nodejs/wiki/Money-Requests The save method is used to create a Money Request. It takes payload, configurations, and a callback. ```javascript mercadopago.money_requests.save(payload, configurations, callback); ``` -------------------------------- ### Cancel Payment using Update Method Source: https://github.com/mercadopago/sdk-nodejs/wiki/Payment This demonstrates how to cancel a payment by updating its status. It's an alternative to the direct `cancel` method. ```javascript mercadopago.payment.update({ id: 1, status: 'cancelled' }).then().catch(); ``` -------------------------------- ### Search Pre Approvals Source: https://github.com/mercadopago/sdk-nodejs/wiki/Pre-Approval Searches for pre-approval agreements based on specified criteria. ```APIDOC ## Search Pre Approvals ### Description Searches for pre-approval agreements based on specified criteria. ### Method GET (inferred from SDK usage) ### Endpoint /v1/preapproval/search (inferred from SDK usage) ### Parameters #### Request Body - **configurations** (object) - Optional - Configuration settings. ### Request Example ```javascript mercadopago.preapproval.search(configurations, callback); ``` ``` -------------------------------- ### Update a Preference Source: https://github.com/mercadopago/sdk-nodejs/wiki/Preferences Use the `update` method to modify an existing preference. It requires the payload, configurations, and a callback. ```javascript mercadopago.preferences.update(payload, configurations, callback); ``` -------------------------------- ### Save a Payment with mercadopago.payment.save Source: https://github.com/mercadopago/sdk-nodejs/wiki/Payment Use this method to save a payment. Requires payload, configurations, and a callback function. ```javascript mercadopago.payment.save(payload, configurations, callback); ``` -------------------------------- ### Find a Preference by ID using findById Source: https://github.com/mercadopago/sdk-nodejs/wiki/Preferences The `findById` method retrieves a preference by its ID. It accepts the preference ID, configurations, and a callback function. ```javascript mercadopago.preferences.findById(id, configurations, callback); ``` -------------------------------- ### Search Payments with Pagination Source: https://github.com/mercadopago/sdk-nodejs/wiki/Pagination Initiates a search for payments with a specified collector ID. The response includes pagination details. ```javascript mercadopago.payment.search({ qs: { 'collector.id': 'me' } }).then(function (mpResponse) { console.log(mpResponse); }); ``` -------------------------------- ### Update Card - Node.js Source: https://github.com/mercadopago/sdk-nodejs/wiki/Customers-&-Cards Use this method to update a card associated with a customer. The payload must include the customer's ID. Requires payload, configurations, and a callback function. ```javascript mercadopago.customers.cards.update(payload, configurations, callback); ``` -------------------------------- ### getCredentials Source: https://github.com/mercadopago/sdk-nodejs/wiki/MercadoPago-Connect Retrieves personal Mercado Pago API credentials using an access token and authorization code. ```APIDOC ## getCredentials ### Description Get your personal credentials from MercadoPago API. ### Method Signature `mercadopago.connect.getCredentials(access_token, authorization_code, redirect_uri, callback);` ### Parameters * **access_token** (string) - The access token for your application. * **authorization_code** (string) - The authorization code received from Mercado Pago. * **redirect_uri** (string) - The redirect URI used during the authorization process. * **callback** (function) - Optional callback function to handle the response. ### Request Example ```javascript mercadopago.connect.getCredentials('ACCESS_TOKEN','AUTHORIZATION_CODE', 'http://www.mywebsite.com/mercadopago/webhook').then(function (response) { console.log(response); }); ``` ### Response Example ```json { "access_token": "USER_AT", "public_key": "USER_PK", "refresh_token": "USER_RT", "live_mode": false, "user_id": 123456789, "token_type": "bearer", "expires_in": 15768000, "scope": "offline_access read write" } ``` ``` -------------------------------- ### Find a Payment by ID with mercadopago.payment.findById Source: https://github.com/mercadopago/sdk-nodejs/wiki/Payment Use this method to find a specific payment by its ID. Requires the payment ID, configurations, and a callback function. ```javascript mercadopago.payment.findById(id, configurations, callback); ``` -------------------------------- ### Create Merchant Order Source: https://github.com/mercadopago/sdk-nodejs/wiki/Merchant-Orders Creates a new Merchant Order. This method can be invoked using either `create` or `save`. ```APIDOC ## Create Merchant Order ### Description Creates a new Merchant Order. ### Method POST (inferred) ### Endpoint /merchant_orders (inferred) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **payload** (object) - Required - The data for the merchant order. - **configurations** (object) - Optional - Configuration settings. ### Request Example ```javascript mercadopago.merchant_orders.create({ "மையான": "some_value" }, {}, (callback) => { // handle response }); ``` ### Response #### Success Response (200) - **id** (string) - The ID of the created merchant order. - **மையான** (string) - Other fields related to the merchant order. ``` -------------------------------- ### Describe Payment API Endpoints Source: https://github.com/mercadopago/sdk-nodejs/wiki/Usage Defines the paths and methods for payment-related API operations. ```javascript payment.create = requestManager.describe({ path: '/v1/payments', method: 'POST' }); payment.update = requestManager.describe({ path: '/v1/payments/:id', method: 'PUT' }); payment.get = requestManager.describe({ path: '/v1/payments/:id', method: 'GET' }); ``` -------------------------------- ### Refund Partial Amount with mercadopago.payment.refundPartial Source: https://github.com/mercadopago/sdk-nodejs/wiki/Payment Use this method to refund a partial amount from a payment. Requires a refund object and configurations. ```javascript mercadopago.payment.refundPartial(refundObject, configurations, callback); ``` -------------------------------- ### Call Payment Update API Source: https://github.com/mercadopago/sdk-nodejs/wiki/Usage Demonstrates how to update a payment by providing the ID and payload. ```javascript mercadopago.payment.update({ id: 1, status: 'cancelled' }, function (){}); ``` -------------------------------- ### Call Customer Card Update API Source: https://github.com/mercadopago/sdk-nodejs/wiki/Usage Demonstrates how to update a customer's card details by providing IDs and payload. ```javascript mercadopago.customers.cards.update({ id: 1, card_id: 10, expiration_year: 2020 }, function (){}); ``` -------------------------------- ### Update a Payment with mercadopago.payment.update Source: https://github.com/mercadopago/sdk-nodejs/wiki/Payment Use this method to update an existing payment. Requires payload, configurations, and a callback function. ```javascript mercadopago.payment.update(payload, configurations, callback); ``` -------------------------------- ### Manage IPN Notifications with IPN Manager Source: https://github.com/mercadopago/sdk-nodejs/wiki/IPN-Notifications Use the IPN Manager to simplify handling IPN notifications. Pass the incoming request object to the manage function to automatically retrieve and process the notification data. ```javascript mercadopago.ipn.manage(request).then(function (response) { console.log(response); }).then(function (error) { console.log(error); }); ``` -------------------------------- ### Save Merchant Order - Node.js SDK Source: https://github.com/mercadopago/sdk-nodejs/wiki/Merchant-Orders The `save` method is an alternative for creating a Merchant Order. It also requires payload and callback. ```javascript mercadopago.merchant_orders.save(payload, configurations, callback); ```