Skip to content

Commit

Permalink
Merge pull request #175 from mercadopago/release/1.3.0
Browse files Browse the repository at this point in the history
Release 1.3.0
  • Loading branch information
delias-silva authored Jan 2, 2020
2 parents ca86295 + be1bfef commit 72e44c1
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 3 deletions.
31 changes: 31 additions & 0 deletions lib/configurations.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ var Promise = require('bluebird');
var clientId;
var clientSecret;
var accessToken;
var platformId;
var corporationId;
var integratorId;
var refreshToken;
var schema = 'https';
var host = 'api.mercadopago.com';
Expand Down Expand Up @@ -45,6 +48,10 @@ configurationsModule.configure = function (configurations) {

// Set accessToken
accessToken = configurations.access_token || accessToken;
// Set headers parameters
platformId = configurations.platform_id;
corporationId = configurations.corporation_id;
integratorId = configurations.integrator_id;
// Use if to prevent false value
this.sandbox = (configurations.sandbox !== undefined) ? configurations.sandbox : this.sandbox;
this.show_promise_error = (configurations.show_promise_error !== undefined) ?
Expand All @@ -71,6 +78,30 @@ configurationsModule.getClientSecret = function () {
return clientSecret;
};

/**
* Get platformId
* @returns {string}
*/
configurationsModule.getPlatformId = function () {
return platformId;
};

/**
* Get corporationId
* @returns {string}
*/
configurationsModule.getCorporationId = function () {
return corporationId;
};

/**
* Get integratorId
* @returns {string}
*/
configurationsModule.getIntegratorId = function () {
return integratorId;
};

/**
* Set accessToken
* @param {string} token
Expand Down
29 changes: 29 additions & 0 deletions lib/models/preferencesModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,35 @@ module.exports = {
}
}
},
tracks: {
type: 'array',
items: {
type: 'object',
properties: {
type: {
type: 'string',
maxLength: 256
},
values: {
type: 'object',
properties: {
conversion_id: {
type: 'string',
},
conversion_label: {
type: 'string',
},
pixel_id: {
type: 'string',
}
}
}
}
}
},
metadata: {
type: 'object',
},
payer: {
type: 'object',
properties: {
Expand Down
16 changes: 16 additions & 0 deletions lib/request-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ requestManager.describe = function (options) {
var missingPayloadProperties = []; // Stores the missing payload path params (if there is any). POST, PUT, PATCH
var schema = this.schema; // Schema from resource
var needIdempotency = !!this.idempotency; // Idempotency from resource
var needPartnersHeaders = !!this.partnersHeaders;
var config = {};
var payload = {};
var error;
Expand Down Expand Up @@ -114,6 +115,9 @@ requestManager.describe = function (options) {
idempotency: needIdempotency, // Needs the idempotency header
// If the merchant provides an access_token, it should override the access_token configured on init
access_token: config.access_token ? config.access_token : accessToken,
platformId: needPartnersHeaders || configurations.getPlatformId(),
corporationId: needPartnersHeaders || configurations.getCorporationId(),
integratorId: needPartnersHeaders || configurations.getIntegratorId(),
});
}).then(function (response) {
resolve(response);
Expand Down Expand Up @@ -260,6 +264,18 @@ requestManager.buildRequest = function (options) {
req.qs = (options.config && options.config.qs) ? options.config.qs : {}; // Always set the querystring object
req.json = true; // Autoparse the response to JSON

if(options.integratorId) {
req.headers['x-integrator-id'] = options.integratorId;
}

if(options.corporationId) {
req.headers['x-corporation-id'] = options.corporationId;
}

if(options.platformId) {
req.headers['x-platform-id'] = options.platformId;
}

if (options.config && options.config.headers && typeof options.config.headers === 'object') {
headersNames = Object.keys(options.config.headers);
for (i = 0; i < headersNames.length; i += 1) {
Expand Down
3 changes: 2 additions & 1 deletion lib/resources/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ var refundModule = require('./refund');

var payment = module.exports = {
schema: paymentModel,
idempotency: true
idempotency: true,
partnersHeaders: true
};

payment.create = requestManager.describe({
Expand Down
3 changes: 2 additions & 1 deletion lib/resources/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ var requestManager = require('../request-manager');
var preferencesModel = require('../models/preferencesModel');

var preferences = module.exports = {
schema: preferencesModel
schema: preferencesModel,
partnersHeaders: true
};

preferences.create = requestManager.describe({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mercadopago",
"version": "1.2.1",
"version": "1.3.0",
"description": "Mercadopago SDK for Node.js",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 72e44c1

Please sign in to comment.