Ninjas Practicing Multidimensionality
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    mercadopago-ideamepublic

    MercadoPago SDK module for Payments integration

    Usage:

    $ npm install mercadopago
    
    var MP = require ("mercadopago");
     
    var mp = new MP ("CLIENT_ID", "CLIENT_SECRET");

    Get your Access Token:

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

    Using MercadoPago Checkout

    Create a Checkout preference:

    var preference = {
            "items": [
                {
                    "title": "Test",
                    "quantity": 1,
                    "currency_id": "USD",
                    "unit_price": 10.5
                }
            ]
        };
     
    mp.createPreference (preference, function (err, data){
            if (err) {
                console.log (err);
            } else {
                console.log (JSON.stringify (data, null, 4));
            }
        });

    Others items to use

    Get an existent Checkout preference:

    mp.getPreference ("PREFERENCE_ID", function (err, data){
            if (err) {
                console.log (err);
            } else {
                console.log (JSON.stringify (data, null, 4));
            }
        });

    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, function (err, data){
            if (err) {
                console.log (err);
            } else {
                console.log (JSON.stringify (data, null, 4));
            }
        });

    Using MercadoPago Payment

    Searching:

    var filters = {
            "id": null,
            "site_id": null,
            "external_reference": null
        };
     
    mp.searchPayment (filters, function (err, data){
            if (err) {
                console.log (err);
            } else {
                console.log (JSON.stringify (data, null, 4));
            }
        });

    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.getPaymentInfo (qs["id"], function (err, data){
            if (err) {
                console.log (err);
                response.writeHead(200, {
                    'Content-Type' : 'application/json; charset=utf-8'
                });
                response.write (err);
                response.end();
            } else {
                console.log (JSON.stringify (data, null, 4));
                response.writeHead(200, {
                    'Content-Type' : 'application/json; charset=utf-8'
                });
                response.write (JSON.stringify (data));
                response.end();
            }
        });
    }
     
    http.createServer(onRequest).listen(8888);

    Cancel (only for pending payments):

    mp.cancelPayment ("ID", function (err, data){
            if (err) {
                console.log (err);
            } else {
                console.log (JSON.stringify (data, null, 4));
            }
        });

    Refund (only for accredited payments):

    mp.refundPayment ("ID", function (err, data){
            if (err) {
                console.log (err);
            } else {
                console.log (JSON.stringify (data, null, 4));
            }
        });

    About Cancel & Refund

    install

    npm i mercadopago-ideame

    Downloadsweekly downloads

    9

    version

    0.1.6

    license

    none

    repository

    githubgithub

    last publish

    collaborators

    • avatar
    • avatar