Socket
Socket
Sign inDemoInstall

mercadopago

Package Overview
Dependencies
38
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mercadopago

Mercadopago SDK module for Payments integration


Version published
Weekly downloads
21K
increased by10.91%
Maintainers
1
Install size
1.73 MB
Created
Weekly downloads
 

Readme

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");

Using Mercadopago Checkout

Create a Checkout preference:

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

mp.createPreference (preference)
	.on ("ok", function (pref){
		console.log (JSON.stringify (pref, null, 4));
	})
	.on ("error", function (error){
		console.log ("ERROR: " + error);
	});

Get an existent Checkout preference:

mp.getPreference ("PREFERENCE_ID")
	.on ("ok", function (pref){
		console.log (JSON.stringify (pref, null, 4));
	})
	.on ("error", function (error){
		console.log ("ERROR: " + error);
	});

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)
	.on ("ok", function (pref){
		console.log (JSON.stringify (pref, null, 4));
	})
	.on ("error", function (error){
		console.log ("ERROR: " + error);
	});

Using Mercadopago Payment collection

Searching:

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

mp.searchCollection (filters)
	.on ("ok", function (result){
		console.log (JSON.stringify (result, null, 4));
	})
	.on ("error", function (error){
		console.log ("ERROR: " + error);
	});

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"])
		.on ("ok", function (result){
			console.log (JSON.stringify (result, null, 4));

			response.writeHead(200, {
				'Content-Type' : 'application/json; charset=utf-8'
			});
			response.write (JSON.stringify (result));
			response.end();
		})
		.on ("error", function (error){
			console.log ("ERROR: " + error);
			
			response.writeHead(200, {
				'Content-Type' : 'application/json; charset=utf-8'
			});
			response.write (JSON.stringify (error));
			response.end();
		});

}

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

Keywords

FAQs

Last updated on 11 Oct 2012

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc