Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
});
Expand Down
37 changes: 20 additions & 17 deletions lib/recurly.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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){
Expand All @@ -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 = {
Expand All @@ -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){
Expand All @@ -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){
Expand All @@ -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());
},
Expand All @@ -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){
Expand All @@ -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){
Expand All @@ -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){
Expand Down Expand Up @@ -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){
Expand All @@ -204,8 +207,8 @@
if(amount){
route = utils.addQueryParams(route, { amount_in_cents: amount });
}
t.request(route, callback)
t.request(route, callback);
}
}
};
}//end class
})();
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <robrighter@gmail.com> (http://github.com/robrighter)"
, "contributors" : [
, "contributors" : [
"Iván Guardado <dev.ivangc@gmail.com> (http://github.com/IvanGuardado)",
"Rob Righter <robrighter@gmail.com> (http://github.com/robrighter)",
"Dmitriy Shekhovtsov <valorkin@gmail.com> (https://github.com/valorkin)"
Expand All @@ -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" }
}