diff --git a/lib/client.js b/lib/client.js index 9106023..602bcc1 100644 --- a/lib/client.js +++ b/lib/client.js @@ -8,7 +8,7 @@ config.RECURLY_HOST = config.SUBDOMAIN + '.recurly.com'; return { - request: function (route, callback, data) { + request: function (route, callback, data, headers) { var endpoint = route[0]; var method = route[1]; var that = this; @@ -20,10 +20,14 @@ headers: { Authorization: "Basic " + (new Buffer(config.API_KEY)).toString('base64'), Accept: 'application/xml', - 'Content-Length': (data) ? data.length : 0 + 'Content-Length': (data) ? Buffer.byteLength(data) : 0 } }; - + if (headers) { + for (var attr in headers) { + options.headers[attr] = headers[attr]; + } + } if (method.toLowerCase() === 'post' || method.toLowerCase() === 'put') { options.headers['Content-Type'] = 'application/xml'; that.debug(data); @@ -45,6 +49,9 @@ if (responsedata === '') { return _cb(res); } + if (headers) { + return _cb(res, null, responsedata); + } return parser.parseString(responsedata, function (err, result) { return _cb(res, null, result); }); diff --git a/lib/recurly.js b/lib/recurly.js index 81e4cce..7eee6a7 100644 --- a/lib/recurly.js +++ b/lib/recurly.js @@ -26,9 +26,9 @@ t.request(utils.addParams(routes.accounts.close, {account_code: accountcode}), callback); }, reopen: function(accountcode, callback){ - t.request(utils.addParams(routes.accounts.reopen, {account_code: accountcode}), callback) + t.request(utils.addParams(routes.accounts.reopen, {account_code: accountcode}), callback); } - } + }; this.adjustments = { get: function(accountcode, callback){ @@ -40,8 +40,8 @@ remove: function(uuid, callback){ t.request(utils.addParams(routes.adjustments.remove, {uuid: uuid}), callback); } - } - + }; + //http://docs.recurly.com/api/billing-info this.billingInfo = { update: function(accountcode, details, callback){ @@ -53,7 +53,7 @@ remove: function(accountcode, callback){ t.request(utils.addParams(routes.billingInfo.remove, {account_code: accountcode} ), callback); } - } + }; //http://docs.recurly.com/api/coupons this.coupons = { @@ -69,7 +69,7 @@ deactivate: function(couponcode, callback){ t.request(utils.addParams(routes.coupons.deactivate, {coupon_code: couponcode}), callback); } - } + }; this.couponRedemption = { redeem: function(couponcode, details, callback){ @@ -82,9 +82,9 @@ t.request(utils.addParams(routes.couponRedemption.remove, {account_code: accountcode}), callback); }, getByInvoice: function(invoicenumber, callback){ - t.request(utils.addParams(routes.couponRedemption.getByInvoice, {invoice_number: invoicenumber}), callback) + t.request(utils.addParams(routes.couponRedemption.getByInvoice, {invoice_number: invoicenumber}), callback); } - } + }; this.invoices = { list: function(callback, filter){ @@ -95,11 +95,14 @@ utils.addParams( utils.addQueryParams(routes.invoices.listByAccount, filter) , {account_code: accountcode}) - , callback) + , callback); }, get: function(invoicenumber, callback){ t.request(utils.addParams(routes.invoices.get, {invoice_number: invoicenumber}), callback); }, + getPdf: function(invoicenumber, callback){ + t.request(utils.addParams(routes.invoices.get, {invoice_number: invoicenumber}), callback, null, { Accept: 'application/pdf' }); + }, create: function(accountcode, details, callback){ t.request(utils.addParams(routes.invoices.create, {account_code: accountcode}), callback, new Js2xml('invoice', details).toString()); }, @@ -109,7 +112,7 @@ markFailed: function(invoicenumber, callback){ t.request(utils.addParams(routes.invoices.markFailed, {invoice_number: invoicenumber}), callback); } - } + }; this.plans = { list: function(callback, filter){ @@ -127,7 +130,7 @@ remove: function(plancode, callback){ t.request(utils.addParams(routes.plans.remove, {plan_code: plancode}), callback); } - } + }; this.planAddons = { list: function(plancode, callback, filter){ @@ -141,16 +144,16 @@ }, update: function(plancode, addoncode, details, callback){ t.request(utils.addParams( - routes.planAddons.update, + routes.planAddons.update, { plan_code: plancode, add_on_code: addoncode - }), + }), callback, new Js2xml('add_on', details).toString()); }, remove: function(plancode, addoncode, callback){ t.request(utils.addParams(routes.planAddons.remove, {plan_code: plancode, add_on_code: addoncode}), callback); } - } + }; this.subscriptions = { list: function(callback, filter){ @@ -181,7 +184,7 @@ postpone: function(uuid, nextRenewalDate, callback){ t.request(utils.addParams(routes.subscriptions.postpone, {uuid: uuid, next_renewal_date: nextRenewalDate}), callback); } - } + }; this.transactions = { list: function(callback, filter){ @@ -204,8 +207,8 @@ if(amount){ route = utils.addQueryParams(route, { amount_in_cents: amount }); } - t.request(route, callback) + t.request(route, callback); } - } + }; }//end class })(); diff --git a/package.json b/package.json index d869925..5e40ddd 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name" : "node-recurly" , "description" : "Library for accessing the api for the Recurly recurring billing service." , "keywords" : [ "recurly", "e-commerce", "recurring billing" ] -, "version" : "2.1.0" +, "version" : "2.2.1" , "homepage" : "https://github.com/robrighter/node-recurly" , "author" : "Rob Righter (http://github.com/robrighter)" -, "contributors" : [ +, "contributors" : [ "Iván Guardado (http://github.com/IvanGuardado)", "Rob Righter (http://github.com/robrighter)", "Dmitriy Shekhovtsov (https://github.com/valorkin)" @@ -14,8 +14,8 @@ , "directories" : { "lib" : "./lib" } , "main" : "./lib/recurly.js" , "dependencies" : { - "xml2js": ">= 0.4.0", - "js2xml": "valorkin/js2xml" + "xml2js": "0.4.5", + "js2xml": "philjackson/js2xml" } , "engines" : { "node" : ">= 0.4" } }