$ npm install mercadopago
- Get your CLIENT_ID and CLIENT_SECRET in the following address:
varMP=require("mercadopago");varmp=newMP("CLIENT_ID","CLIENT_SECRET");mp.getAccessToken(function(err,accessToken){console.log(accessToken);});varpreference={"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));}});mp.getPreference("PREFERENCE_ID",function(err,data){if(err){console.log(err);}else{console.log(JSON.stringify(data,null,4));}});varpreference={"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));}});Searching:
varfilters={"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));}});- Go to Mercadopago IPN configuration:
varMP=require("mercadopago"),http=require("http"),url=require('url');varmp=newMP("CLIENT_ID","CLIENT_SECRET");functiononRequest(request,response){varqs=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);mp.cancelPayment("ID",function(err,data){if(err){console.log(err);}else{console.log(JSON.stringify(data,null,4));}});mp.refundPayment("ID",function(err,data){if(err){console.log(err);}else{console.log(JSON.stringify(data,null,4));}});