Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mercadopago

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mercadopago

Mercadopago SDK module for Payments integration

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15K
decreased by-29.59%
Maintainers
1
Weekly downloads
 
Created
Source

MercadoPago SDK module for Payments integration

  • Usage
  • Using MercadoPago Checkout
  • Using MercadoPago Payment collection

Usage:

$ npm install mercadopago
var MP = require ("mercadopago");

var mp = new MP ("CLIENT_ID", "CLIENT_SECRET");

Promises and Callbacks support

Every method supports either promises and callbacks. For example:

var at = mp.getAccessToken ();

at.then (
    function (accessToken) {
        console.log (accessToken);
    },
    function (error) {
        console.log (error);
    });

is the same as:

mp.getAccessToken(function (err, accessToken){
    if (err) {
        console.log (err);
    } else {
        console.log (accessToken);
    }
});

In order to use callbacks, simply pass a function as the last parameter.

Get your Access Token:

mp.getAccessToken();

Using MercadoPago Checkout

Create a Checkout preference:

var preference = {
        "items": [
            {
                "title": "Test",
                "quantity": 1,
                "currency_id": "USD",
                "unit_price": 10.5
            }
        ]
    };

mp.createPreference (preference);

Others items to use

Get an existent Checkout preference:

mp.getPreference ("PREFERENCE_ID");

Update an existent Checkout preference:

var preference = {
        "items": [
            {
                "title": "Test Modified",
                "quantity": 1,
                "currency_id": "USD",
                "unit_price": 20.4
            }
        ]
    };

mp.updatePreference ("PREFERENCE_ID", preference);

Using MercadoPago Payment

Searching:

var filters = {
        "id": null,
        "site_id": null,
        "external_reference": null
    };

mp.searchPayment (filters);

More search examples

Receiving IPN notification:

var MP = require ("mercadopago"),
    http = require("http"),
    url = require('url');

var mp = new MP ("CLIENT_ID", "CLIENT_SECRET");

function onRequest(request, response) {
    var qs = url.parse (request.url, true).query;

    mp.getPayment (qs["id"])
        .then (
            function success (data) {
                console.log (JSON.stringify (data, null, 4));
                response.writeHead(200, {
                    'Content-Type' : 'application/json; charset=utf-8'
                });
                response.write (JSON.stringify (data));
                response.end();
            },
            function error (err) {
                console.log (err);
                response.writeHead(200, {
                    'Content-Type' : 'application/json; charset=utf-8'
                });
                response.write (err);
                response.end();
            }
        });
}

http.createServer(onRequest).listen(8888);

Cancel (only for pending payments):

mp.cancelPayment ("ID");

Refund (only for accredited payments):

mp.refundPayment ("ID");

Generic resources methods

You can access any other resource from the MercadoPago API using the generic methods:

// Get a resource, with optional URL params. Also you can disable authentication for public APIs
mp.get ("/resource/uri", [params], [authenticate=true]);

// Create a resource with "data" and optional URL params.
mp.post ("/resource/uri", data, [params]);

// Update a resource with "data" and optional URL params.
mp.put ("/resource/uri", data, [params]);

For example, if you want to get the Sites list (no params and no authentication):

mp.get ("/sites", null, false)
    .then (function (sites) {
        console.log (sites);
    });

<a href=http://developers.mercadopago.com/documentacion/devolucion-y-cancelacion> About Cancel & Refund

Keywords

FAQs

Package last updated on 10 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc