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 - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

102

lib/mercadopago.js

@@ -6,3 +6,3 @@ var package = require("../package"),

var config = {
API_BASE_URL: "https://api.mercadolibre.com",
API_BASE_URL: "https://api.mercadopago.com",
MIME_JSON: "application/json",

@@ -12,5 +12,16 @@ MIME_FORM: "application/x-www-form-urlencoded"

MP = function (clientId, clientSecret) {
this.__clientId = clientId;
this.__clientSecret = clientSecret;
MP = function () {
if (arguments.length > 2 || arguments.length < 1) {
throw "Invalid arguments. Use CLIENT_ID and CLIENT SECRET, or ACCESS_TOKEN";
}
if (arguments.length == 1) {
this.__llAccessToken = arguments[0];
}
if (arguments.length == 2) {
this.__clientId = arguments[0];
this.__clientSecret = arguments[1];
}
this.__sandbox = false;

@@ -35,18 +46,25 @@ };

MP.restClient.post(
"/oauth/token",
{
"client_id": this.__clientId,
"client_secret": this.__clientSecret,
"grant_type": "client_credentials"
},
config.MIME_FORM
)
.then (
if (__self.__llAccessToken) {
next && next(null, __self.__llAccessToken);
deferred.resolve (__self.__llAccessToken);
} else {
MP.restClient.post(
"/oauth/token",
{
"client_id": __self.__clientId,
"client_secret": __self.__clientSecret,
"grant_type": "client_credentials"
},
config.MIME_FORM
).then (
function success (data) {
next && next(null, data.response.access_token);
deferred.resolve (data.response.access_token);
},
function error (err) {
next && next(err);
deferred.reject (err);
});
}
);
}

@@ -338,2 +356,43 @@ return deferred.promise;

/**
Generic resource delete
@param uri
@param params
*/
MP.prototype.delete = function (uri, params) {
var _self = this;
var next = typeof (arguments[arguments.length -1]) == "function" ? arguments[arguments.length -1] : null;
var deferred = Q.defer();
params = params && typeof params == "object" ? params : {};
this.getAccessToken ()
.then (
function success (accessToken) {
params.access_token = accessToken;
if (Object.keys(params).length > 0) {
uri += (uri.indexOf ("?") >= 0 ? "&" : "?") + _self.__build_query(params);
}
MP.restClient.delete(uri, config.MIME_JSON)
.then (
function success (data) {
next && next (null, data);
deferred.resolve (data);
},
function error (err) {
next && next(err);
deferred.reject(err);
});
},
function error (err) {
next && next(err);
deferred.reject(err);
});
return deferred.promise;
};
/*************************************************************************/

@@ -364,6 +423,2 @@ MP.prototype.__build_query = function (params) {

req.agentOptions = {
secureProtocol: 'SSLv3_method'
};
request(req, function(error, response, body) {

@@ -415,2 +470,11 @@ (typeof body == "string") && (body = JSON.parse(body));

return this.__exec (uri, req);
},
delete: function (uri, contentType) {
var req = {
"method": "DELETE"
}
contentType == config.MIME_JSON && (req.json = true);
return this.__exec (uri, req);
}

@@ -417,0 +481,0 @@ };

2

package.json
{
"name" : "mercadopago",
"version" : "0.3.1",
"version" : "0.3.2",
"author" : "Horacio Casatti <horacio.casatti@mercadolibre.com>",

@@ -5,0 +5,0 @@ "description" : "Mercadopago SDK module for Payments integration",

@@ -14,2 +14,4 @@ # MercadoPago SDK module for Payments integration

### ...with your credentials:
* Get your **CLIENT_ID** and **CLIENT_SECRET** in the following address:

@@ -28,2 +30,10 @@ * Argentina: [https://www.mercadopago.com/mla/herramientas/aplicaciones](https://www.mercadopago.com/mla/herramientas/aplicaciones)

### ...with your long live access token:
```javascript
var MP = require ("mercadopago");
var mp = new MP ("LL_ACCESS_TOKEN");
```
### Promises and Callbacks support

@@ -198,2 +208,5 @@

mp.put ("/resource/uri", data, [params]);
// Delete a resource with optional URL params.
mp.delete ("/resource/uri", [params]);
```

@@ -200,0 +213,0 @@

@@ -25,2 +25,20 @@ var MP = require("../lib/mercadopago"),

.addBatch({
"Configure credentials": {
topic: credentials,
"credentials configured": function (credentials) {
assert.notEqual(credentials.clientId, "CLIENT_ID");
assert.notEqual(credentials.clientId, "CLIENT_SECRET");
}
},
"Long Live access token": {
topic: function () {
var _self = this;
var mp = new MP("LONG_LIVE_ACCESS_TOKEN");
mp.getAccessToken(_self.callback);
},
"LLAT configured": function (llAT) {
assert.equal(llAT, "LONG_LIVE_ACCESS_TOKEN");
}
},
"Create Preference": {

@@ -27,0 +45,0 @@ topic: function () {

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