diff --git a/lib/configurations.js b/lib/configurations.js index dead7e4a..4a804375 100644 --- a/lib/configurations.js +++ b/lib/configurations.js @@ -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'; @@ -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) ? @@ -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 diff --git a/lib/models/preferencesModel.js b/lib/models/preferencesModel.js index f88d50eb..c9d43fea 100644 --- a/lib/models/preferencesModel.js +++ b/lib/models/preferencesModel.js @@ -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: { diff --git a/lib/request-manager.js b/lib/request-manager.js index 83b844ff..19b0cc4e 100644 --- a/lib/request-manager.js +++ b/lib/request-manager.js @@ -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; @@ -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); @@ -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) { diff --git a/lib/resources/payment.js b/lib/resources/payment.js index f6cfc19b..b2b2b4cb 100644 --- a/lib/resources/payment.js +++ b/lib/resources/payment.js @@ -7,7 +7,8 @@ var refundModule = require('./refund'); var payment = module.exports = { schema: paymentModel, - idempotency: true + idempotency: true, + partnersHeaders: true }; payment.create = requestManager.describe({ diff --git a/lib/resources/preferences.js b/lib/resources/preferences.js index e11f373c..f8549e42 100644 --- a/lib/resources/preferences.js +++ b/lib/resources/preferences.js @@ -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({ diff --git a/package.json b/package.json index c1af6496..32da7a3e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mercadopago", - "version": "1.2.1", + "version": "1.3.0", "description": "Mercadopago SDK for Node.js", "main": "index.js", "scripts": {