diff --git a/lib/client.js b/lib/client.js index fa72031..5674df2 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1,6 +1,6 @@ (function () { 'use strict'; - var https = require('https'), + const https = require('https'), pjson = require('../package.json'), Xml2js = require('xml2js'), parser = new Xml2js.Parser({explicitArray: false}); @@ -9,11 +9,11 @@ config.RECURLY_HOST = config.SUBDOMAIN + '.recurly.com'; return { - request: function (route, callback, data) { - var endpoint = route[0]; - var method = route[1]; - var that = this; - var options = { + request: function (route, callback, data,customHeaders) { + const endpoint = route[0]; + const method = route[1]; + const that = this; + const options = { host: config.RECURLY_HOST, port: 443, path: endpoint, @@ -21,19 +21,22 @@ 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, 'utf-8') : 0, 'User-Agent': "node-recurly/" + pjson.version } }; if (method.toLowerCase() === 'post' || method.toLowerCase() === 'put') { - options.headers['Content-Type'] = 'application/xml'; + options.headers['Content-Type'] = 'application/xml; charset=utf-8'; that.debug(data); } + if(endpoint.lastIndexOf('shipping_addresses') !== -1 || (customHeaders &&customHeaders.API_VERSION)) { + options.headers['X-Api-Version'] = (customHeaders && customHeaders.API_VERSION)? customHeaders.API_VERSION:2.4; + } that.debug(options); - var req = https.request(options, function (res) { + const req = https.request(options, function (res) { - var responsedata = ''; + let responsedata = ''; res.on('data', function (d) { responsedata += d; }); @@ -93,7 +96,7 @@ // backward compatibility for not node.js style callbacks // TBD: skip in next version? else if (callback.length === 1) { - var toreturn = {status: 'ok', data: '', headers: res ? res.headers : null }; + let toreturn = {status: 'ok', data: '', headers: res ? res.headers : null }; if (err) { toreturn.status = 'error'; if (!res || err === Error || err instanceof Error) { diff --git a/lib/recurly.js b/lib/recurly.js index 972b4b8..5ba7561 100644 --- a/lib/recurly.js +++ b/lib/recurly.js @@ -1,271 +1,596 @@ -(function(){ - var js2xmlparser = require('js2xmlparser'), - Client = require('./client'), - utils = require('./utils'), - router = require('./routes/'); +(function() { + const js2xmlparser = require('js2xmlparser'), + Client = require('./client'), + utils = require('./utils'), + router = require('./routes/'); - module.exports = function(config){ - var routes = router.routes(config.API_VERSION ? config.API_VERSION : '2'); - var t = Client.create(config); + module.exports = function(config) { + const routes = router.routes(config.API_VERSION ? config.API_VERSION : '2'); + const t = Client.create(config); - //https://dev.recurly.com/docs/list-accounts + this.lib = { + core: t, + utils: utils, + }; + //https://dev.recurly.com/docs/list-accounts this.accounts = { - list: function(filter, callback){ + list: function(filter, callback) { t.request(utils.addQueryParams(routes.accounts.list, filter), callback); }, - get: function(accountcode, callback){ - t.request(utils.addParams(routes.accounts.get, {account_code: accountcode}), callback); + get: function(accountcode, callback) { + t.request( + utils.addParams(routes.accounts.get, { account_code: accountcode }), + callback, + ); }, - create: function(details, callback){ - t.request(routes.accounts.create, callback, js2xmlparser('account',details)); + create: function(details, callback) { + t.request( + routes.accounts.create, + callback, + js2xmlparser('account', details), + ); }, - update: function(accountcode, details, callback){ - t.request(utils.addParams(routes.accounts.update, {account_code: accountcode}), callback, js2xmlparser('account', details)); + update: function(accountcode, details, callback) { + t.request( + utils.addParams(routes.accounts.update, { + account_code: accountcode, + }), + callback, + js2xmlparser('account', details), + ); }, - close: function(accountcode, callback){ - t.request(utils.addParams(routes.accounts.close, {account_code: accountcode}), callback); + close: function(accountcode, callback) { + 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); + reopen: function(accountcode, callback) { + t.request( + utils.addParams(routes.accounts.reopen, { + account_code: accountcode, + }), + callback, + ); }, - notes: function(accountcode, callback){ - t.request(utils.addParams(routes.accounts.notes, {account_code: accountcode}), callback); - } - } + notes: function(accountcode, callback) { + t.request( + utils.addParams(routes.accounts.notes, { account_code: accountcode }), + callback, + ); + }, + }; //https://dev.recurly.com/docs/list-an-accounts-adjustments this.adjustments = { - list: function(accountcode, callback){ - t.request(utils.addParams(routes.adjustments.list, {account_code: accountcode}), callback); + list: function(accountcode, filter, callback) { + t.request( + utils.addParams( + utils.addQueryParams(routes.adjustments.list, filter), + { account_code: accountcode }, + ), + callback, + ); }, - get: function(uuid, callback){ - t.request(utils.addParams(routes.adjustments.get, {uuid: uuid}), callback); + get: function(uuid, callback) { + t.request( + utils.addParams(routes.adjustments.get, { uuid: uuid }), + callback, + ); }, - create: function(accountcode, details, callback){ - t.request(utils.addParams(routes.adjustments.create, {account_code: accountcode}), callback, js2xmlparser('adjustment',details)); + create: function(accountcode, details, callback) { + t.request( + utils.addParams(routes.adjustments.create, { + account_code: accountcode, + }), + callback, + js2xmlparser('adjustment', details), + ); }, - remove: function(uuid, callback){ - t.request(utils.addParams(routes.adjustments.remove, {uuid: uuid}), callback); - } - } + remove: function(uuid, callback) { + t.request( + utils.addParams(routes.adjustments.remove, { uuid: uuid }), + callback, + ); + }, + }; - //https://dev.recurly.com/docs/lookup-an-accounts-billing-info + //https://dev.recurly.com/docs/lookup-an-accounts-billing-info this.billingInfo = { - update: function(accountcode, details, callback){ - t.request(utils.addParams(routes.billingInfo.update, {account_code: accountcode} ), callback, js2xmlparser('billing_info', details)); + update: function(accountcode, details, callback) { + t.request( + utils.addParams(routes.billingInfo.update, { + account_code: accountcode, + }), + callback, + js2xmlparser('billing_info', details), + ); }, - create: function(accountcode, details, callback){ - t.request(utils.addParams(routes.billingInfo.update, {account_code: accountcode} ), callback, js2xmlparser('billing_info', details)); + create: function(accountcode, details, callback) { + t.request( + utils.addParams(routes.billingInfo.update, { + account_code: accountcode, + }), + callback, + js2xmlparser('billing_info', details), + ); + }, + get: function(accountcode, callback) { + t.request( + utils.addParams(routes.billingInfo.get, { + account_code: accountcode, + }), + callback, + ); }, - get: function(accountcode, callback){ - t.request(utils.addParams(routes.billingInfo.get, {account_code: accountcode} ), callback); + remove: function(accountcode, callback) { + t.request( + utils.addParams(routes.billingInfo.remove, { + account_code: accountcode, + }), + callback, + ); }, - remove: function(accountcode, callback){ - t.request(utils.addParams(routes.billingInfo.remove, {account_code: accountcode} ), callback); - } - } + }; //https://dev.recurly.com/docs/list-active-coupons this.coupons = { - list: function(filter, callback){ + list: function(filter, callback) { t.request(utils.addQueryParams(routes.coupons.list, filter), callback); }, - get: function(couponcode, callback){ - t.request(utils.addParams(routes.coupons.get, {coupon_code: couponcode}), callback); + get: function(couponcode, callback) { + t.request( + utils.addParams(routes.coupons.get, { coupon_code: couponcode }), + callback, + ); }, - create: function(details, callback){ - t.request(routes.coupons.create, callback, js2xmlparser('coupon', details)); + create: function(details, callback) { + t.request( + routes.coupons.create, + callback, + js2xmlparser('coupon', details), + ); }, - deactivate: function(couponcode, callback){ - t.request(utils.addParams(routes.coupons.deactivate, {coupon_code: couponcode}), callback); - } - } + deactivate: function(couponcode, callback) { + t.request( + utils.addParams(routes.coupons.deactivate, { + coupon_code: couponcode, + }), + callback, + ); + }, + }; //https://dev.recurly.com/docs/lookup-a-coupon-redemption-on-an-account this.couponRedemption = { - redeem: function(couponcode, details, callback){ - t.request(utils.addParams(routes.couponRedemption.redeem, {coupon_code: couponcode}), callback, js2xmlparser('redemption', details)); + redeem: function(couponcode, details, callback) { + t.request( + utils.addParams(routes.couponRedemption.redeem, { + coupon_code: couponcode, + }), + callback, + js2xmlparser('redemption', details), + ); }, - get: function(accountcode, callback){ - t.request(utils.addParams(routes.couponRedemption.get, {account_code: accountcode}), callback); + get: function(accountcode, callback) { + t.request( + utils.addParams(routes.couponRedemption.get, { + account_code: accountcode, + }), + callback, + ); + }, + remove: function(accountcode, callback) { + t.request( + utils.addParams(routes.couponRedemption.remove, { + account_code: accountcode, + }), + callback, + ); }, - remove: function(accountcode, callback){ - 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, + ); }, - getByInvoice: function(invoicenumber, callback){ - t.request(utils.addParams(routes.couponRedemption.getByInvoice, {invoice_number: invoicenumber}), callback) - } - } + }; //https://dev.recurly.com/docs/list-invoices this.invoices = { - list: function(filter, callback){ + list: function(filter, callback) { t.request(utils.addQueryParams(routes.invoices.list, filter), callback); }, - listByAccount: function(accountcode, filter, callback){ + listByAccount: function(accountcode, filter, callback) { t.request( utils.addParams( - utils.addQueryParams(routes.invoices.listByAccount, filter) - , {account_code: accountcode}) - , callback) + utils.addQueryParams(routes.invoices.listByAccount, filter), + { account_code: accountcode }, + ), + callback, + ); }, - get: function(invoicenumber, callback){ - t.request(utils.addParams(routes.invoices.get, {invoice_number: invoicenumber}), callback); + get: function(invoicenumber, callback) { + t.request( + utils.addParams(routes.invoices.get, { + invoice_number: invoicenumber, + }), + callback, + ); }, - create: function(accountcode, details, callback){ - t.request(utils.addParams(routes.invoices.create, {account_code: accountcode}), callback, js2xmlparser('invoice', details)); + create: function(accountcode, details, callback) { + t.request( + utils.addParams(routes.invoices.create, { + account_code: accountcode, + }), + callback, + js2xmlparser('invoice', details), + ); }, - preview: function(accountcode, callback){ - t.request(utils.addParams(routes.invoices.preview, {account_code: accountcode}), callback); + preview: function(accountcode, callback) { + t.request( + utils.addParams(routes.invoices.preview, { + account_code: accountcode, + }), + callback, + ); }, - refundLineItems: function(invoicenumber, details, callback){ - t.request(utils.addParams(routes.invoices.refundLineItems, {invoice_number: invoicenumber}), callback, js2xmlparser('invoice', details)); + refundLineItems: function(invoicenumber, details, callback) { + t.request( + utils.addParams(routes.invoices.refundLineItems, { + invoice_number: invoicenumber, + }), + callback, + js2xmlparser('invoice', details), + ); }, - refundOpenAmount: function(invoicenumber, details, callback){ - t.request(utils.addParams(routes.invoices.refundOpenAmount, {invoice_number: invoicenumber}), callback, js2xmlparser('invoice', details)); + refundOpenAmount: function(invoicenumber, details, callback) { + t.request( + utils.addParams(routes.invoices.refundOpenAmount, { + invoice_number: invoicenumber, + }), + callback, + js2xmlparser('invoice', details), + ); }, - markSuccessful: function(invoicenumber, callback){ - t.request(utils.addParams(routes.invoices.markSuccessful, {invoice_number: invoicenumber}), callback); + markSuccessful: function(invoicenumber, callback) { + t.request( + utils.addParams(routes.invoices.markSuccessful, { + invoice_number: invoicenumber, + }), + callback, + ); }, - markFailed: function(invoicenumber, callback){ - t.request(utils.addParams(routes.invoices.markFailed, {invoice_number: invoicenumber}), callback); + markFailed: function(invoicenumber, callback) { + t.request( + utils.addParams(routes.invoices.markFailed, { + invoice_number: invoicenumber, + }), + callback, + ); }, - enterOfflinePayment: function(invoicenumber, details, callback){ - t.request(utils.addParams(routes.invoices.enterOfflinePayment, {invoice_number: invoicenumber}), callback, js2xmlparser('transaction', details)); + enterOfflinePayment: function(invoicenumber, details, callback) { + t.request( + utils.addParams(routes.invoices.enterOfflinePayment, { + invoice_number: invoicenumber, + }), + callback, + js2xmlparser('transaction', details), + ); }, - } + }; //https://dev.recurly.com/docs/list-plans this.plans = { - list: function(filter, callback){ + list: function(filter, callback) { t.request(utils.addQueryParams(routes.plans.list, filter), callback); }, - get: function(plancode, callback){ - t.request(utils.addParams(routes.plans.get, {plan_code: plancode}), callback); + get: function(plancode, callback) { + t.request( + utils.addParams(routes.plans.get, { plan_code: plancode }), + callback, + ); }, - create: function(details, callback){ + create: function(details, callback) { t.request(routes.plans.create, callback, js2xmlparser('plan', details)); }, - update: function(plancode, details, callback){ - t.request(utils.addParams(routes.plans.update, {plan_code: plancode}), callback, js2xmlparser('plan', details)); + update: function(plancode, details, callback) { + t.request( + utils.addParams(routes.plans.update, { plan_code: plancode }), + callback, + js2xmlparser('plan', details), + ); }, - remove: function(plancode, callback){ - t.request(utils.addParams(routes.plans.remove, {plan_code: plancode}), callback); - } - } + remove: function(plancode, callback) { + t.request( + utils.addParams(routes.plans.remove, { plan_code: plancode }), + callback, + ); + }, + }; //https://dev.recurly.com/docs/list-add-ons-for-a-plan this.planAddons = { - list: function(plancode, filter, callback){ - t.request(utils.addParams(utils.addQueryParams(routes.planAddons.list, filter), {plan_code: plancode}), callback); + list: function(plancode, filter, callback) { + t.request( + utils.addParams( + utils.addQueryParams(routes.planAddons.list, filter), + { plan_code: plancode }, + ), + callback, + ); + }, + get: function(plancode, addoncode, callback) { + t.request( + utils.addParams(routes.planAddons.get, { + plan_code: plancode, + addon_code: addoncode, + }), + callback, + ); }, - get: function(plancode, addoncode, callback){ - t.request(utils.addParams(routes.planAddons.get, {plan_code: plancode, addon_code: addoncode}), callback); + create: function(plancode, details, callback) { + t.request( + utils.addParams(routes.planAddons.create, { plan_code: plancode }), + callback, + js2xmlparser('add_on', details), + ); }, - create: function(plancode, details, callback){ - t.request(utils.addParams(routes.planAddons.create, {plan_code: plancode}), callback, js2xmlparser('add_on', details)); + update: function(plancode, addoncode, details, callback) { + t.request( + utils.addParams(routes.planAddons.update, { + plan_code: plancode, + add_on_code: addoncode, + }), + callback, + js2xmlparser('add_on', details), + ); }, - update: function(plancode, addoncode, details, callback){ - t.request(utils.addParams( - routes.planAddons.update, - { plan_code: plancode, - add_on_code: addoncode + remove: function(plancode, addoncode, callback) { + t.request( + utils.addParams(routes.planAddons.remove, { + plan_code: plancode, + add_on_code: addoncode, }), - callback, js2xmlparser('add_on', details)); + callback, + ); }, - remove: function(plancode, addoncode, callback){ - t.request(utils.addParams(routes.planAddons.remove, {plan_code: plancode, add_on_code: addoncode}), callback); - } - } + }; //https://dev.recurly.com/docs/list-subscriptions this.subscriptions = { - list: function(filter, callback){ - t.request(utils.addQueryParams(routes.subscriptions.list, filter), callback); + list: function(filter, callback) { + t.request( + utils.addQueryParams(routes.subscriptions.list, filter), + callback, + ); }, - listByAccount: function(accountcode, filter, callback){ + listByAccount: function(accountcode, filter, callback) { t.request( utils.addParams( - utils.addQueryParams(routes.subscriptions.listByAccount, filter) - , {account_code: accountcode}) - , callback) + utils.addQueryParams(routes.subscriptions.listByAccount, filter), + { account_code: accountcode }, + ), + callback, + ); + }, + get: function(uuid, callback) { + t.request( + utils.addParams(routes.subscriptions.get, { uuid: uuid }), + callback, + ); }, - get: function(uuid, callback){ - t.request(utils.addParams(routes.subscriptions.get, {uuid: uuid}), callback); + create: function(details, callback) { + t.request( + routes.subscriptions.create, + callback, + js2xmlparser('subscription', details), + ); }, - create: function(details, callback){ - t.request(routes.subscriptions.create, callback, js2xmlparser('subscription', details)); + preview: function(details, callback) { + t.request( + routes.subscriptions.preview, + callback, + js2xmlparser('subscription', details), + ); }, - preview: function(details, callback){ - t.request(routes.subscriptions.preview, callback, js2xmlparser('subscription', details)); + update: function(uuid, details, callback) { + t.request( + utils.addParams(routes.subscriptions.update, { uuid: uuid }), + callback, + js2xmlparser('subscription', details), + ); }, - update: function(uuid, details, callback){ - t.request(utils.addParams(routes.subscriptions.update, {uuid: uuid}), callback, js2xmlparser('subscription', details)); + updateNotes: function(uuid, details, callback) { + t.request( + utils.addParams(routes.subscriptions.updateNotes, { uuid: uuid }), + callback, + js2xmlparser('subscription', details), + ); }, - updateNotes: function(uuid, details, callback){ - t.request(utils.addParams(routes.subscriptions.updateNotes, {uuid: uuid}), callback, js2xmlparser('subscription', details)); + updatePreview: function(uuid, details, callback) { + t.request( + utils.addParams(routes.subscriptions.updatePreview, { uuid: uuid }), + callback, + js2xmlparser('subscription', details), + ); }, - updatePreview: function(uuid, details, callback){ - t.request(utils.addParams(routes.subscriptions.updatePreview, {uuid: uuid}), callback, js2xmlparser('subscription', details)); + cancel: function(uuid, callback) { + t.request( + utils.addParams(routes.subscriptions.cancel, { uuid: uuid }), + callback, + ); }, - cancel: function(uuid, callback){ - t.request(utils.addParams(routes.subscriptions.cancel, {uuid: uuid}), callback); + reactivate: function(uuid, callback) { + t.request( + utils.addParams(routes.subscriptions.reactivate, { uuid: uuid }), + callback, + ); }, - reactivate: function(uuid, callback){ - t.request(utils.addParams(routes.subscriptions.reactivate, {uuid: uuid}), callback); + terminate: function(uuid, refundType, callback) { + t.request( + utils.addParams(routes.subscriptions.terminate, { + uuid: uuid, + refund_type: refundType, + }), + callback, + ); }, - terminate: function(uuid, refundType, callback){ - t.request(utils.addParams(routes.subscriptions.terminate, {uuid: uuid, refund_type: refundType}), callback); + postpone: function(uuid, nextRenewalDate, callback) { + t.request( + utils.addParams(routes.subscriptions.postpone, { + uuid: uuid, + next_renewal_date: nextRenewalDate, + }), + callback, + ); }, - postpone: function(uuid, nextRenewalDate, callback){ - t.request(utils.addParams(routes.subscriptions.postpone, {uuid: uuid, next_renewal_date: nextRenewalDate}), callback); - } - } + }; //https://dev.recurly.com/docs/list-add-ons-usage this.usage = { list: function(uuid, addOnCode, billingStatus, callback) { billingStatus = billingStatus || 'all'; - t.request(utils.addParams(routes.usage.list, {uuid: uuid, add_on_code: addOnCode, billing_status: billingStatus}), callback); + t.request( + utils.addParams(routes.usage.list, { + uuid: uuid, + add_on_code: addOnCode, + billing_status: billingStatus, + }), + callback, + ); }, log: function(uuid, addOnCode, details, callback) { - t.request(utils.addParams(routes.usage.log, {uuid: uuid, add_on_code: addOnCode}), callback, js2xmlparser('usage', details)); + t.request( + utils.addParams(routes.usage.log, { + uuid: uuid, + add_on_code: addOnCode, + }), + callback, + js2xmlparser('usage', details), + ); }, get: function(uuid, addOnCode, usageId, callback) { - t.request(utils.addParams(routes.usage.get, {uuid: uuid, add_on_code: addOnCode, usage_id: usageId}), callback); + t.request( + utils.addParams(routes.usage.get, { + uuid: uuid, + add_on_code: addOnCode, + usage_id: usageId, + }), + callback, + ); }, update: function(uuid, addOnCode, usageId, details, callback) { - t.request(utils.addParams(routes.usage.update, {uuid: uuid, add_on_code: addOnCode, usage_id: usageId}), callback, js2xmlparser('usage', details)); + t.request( + utils.addParams(routes.usage.update, { + uuid: uuid, + add_on_code: addOnCode, + usage_id: usageId, + }), + callback, + js2xmlparser('usage', details), + ); }, remove: function(uuid, addOnCode, usageId, callback) { - t.request(utils.addParams(routes.usage.remove, {uuid: uuid, add_on_code: addOnCode, usage_id: usageId}), callback); + t.request( + utils.addParams(routes.usage.remove, { + uuid: uuid, + add_on_code: addOnCode, + usage_id: usageId, + }), + callback, + ); }, - } + }; //https://dev.recurly.com/docs/list-transactions this.transactions = { - list: function(filter, callback){ - t.request(utils.addQueryParams(routes.transactions.list, filter), callback); + list: function(filter, callback) { + t.request( + utils.addQueryParams(routes.transactions.list, filter), + callback, + ); }, - listByAccount: function(accountCode, filter, callback){ + listByAccount: function(accountCode, filter, callback) { t.request( utils.addParams( - utils.addQueryParams(routes.transactions.listByAccount, filter), {account_code: accountCode}), - callback); - }, - get: function(id, callback){ - t.request(utils.addParams(routes.transactions.get, {'id': id}), callback); + utils.addQueryParams(routes.transactions.listByAccount, filter), + { account_code: accountCode }, + ), + callback, + ); }, - create: function(details, callback){ - t.request(routes.transactions.create, callback, js2xmlparser('transaction', details)); + get: function(id, callback) { + t.request( + utils.addParams(routes.transactions.get, { id: id }), + callback, + ); }, - refund: function(id, amount, callback){ - var route = utils.addParams(routes.transactions.refund, {id: id}); - if(amount){ + create: function(details, callback) { + t.request( + routes.transactions.create, + callback, + js2xmlparser('transaction', details), + ); + }, + refund: function(id, amount, callback) { + let route = utils.addParams(routes.transactions.refund, { id: id }); + if (amount) { route = utils.addQueryParams(route, { amount_in_cents: amount }); } - t.request(route, callback) - } - } - }//end class + t.request(route, callback); + }, + }; + + //https://dev.recurly.com/docs/list-accounts-shipping-address + this.shippingAddress = { + get: (accountCode, shipping_address_id, cb) => { + t.request( + utils.addParams(routes.shippingAddress.get, { + account_code: accountCode, + shipping_address_id: shipping_address_id, + }), + cb, + ); + }, + listByAccount: (accountCode, filter, cb) => { + t.request( + utils.addParams(routes.shippingAddress.listByAccount, { + account_code: accountCode, + }), + cb, + ); + }, + create: (accountCode, details, cb) => { + t.request( + utils.addParams(routes.shippingAddress.create, { + account_code: accountCode, + }), + cb, + js2xmlparser('shipping_address', details), + ); + }, + update: (accountCode, shipping_address_id, details, cb) => { + t.request( + utils.addParams(routes.shippingAddress.update, { + account_code: accountCode, + shipping_address_id: shipping_address_id, + }), + cb, + js2xmlparser('shipping_address', details), + ); + }, + remove: (accountCode, shipping_address_id, cb) => { + t.request( + utils.addParams(routes.shippingAddress.remove, { + account_code: accountCode, + shipping_address_id: shipping_address_id, + }), + cb, + ); + }, + }; + }; //end class })(); diff --git a/lib/routes/v2.js b/lib/routes/v2.js index 00f34a4..083fd11 100644 --- a/lib/routes/v2.js +++ b/lib/routes/v2.js @@ -1,97 +1,126 @@ exports.accounts = { - list: ['/v2/accounts', 'GET'], - get: ['/v2/accounts/:account_code', 'GET'], - create: ['/v2/accounts', 'POST'], - update: ['/v2/accounts/:account_code', 'PUT'], - close: ['/v2/accounts/:account_code', 'DELETE'], - reopen: ['/v2/accounts/:account_code/reopen', 'PUT'], - notes: ['/v2/accounts/:account_code/notes', 'GET'] -} + list: ['/v2/accounts', 'GET'], + get: ['/v2/accounts/:account_code', 'GET'], + create: ['/v2/accounts', 'POST'], + update: ['/v2/accounts/:account_code', 'PUT'], + close: ['/v2/accounts/:account_code', 'DELETE'], + reopen: ['/v2/accounts/:account_code/reopen', 'PUT'], + notes: ['/v2/accounts/:account_code/notes', 'GET'], +}; exports.adjustments = { - list: ['/v2/accounts/:account_code/adjustments', 'GET'], - get: ['/v2/adjustments/:uuid', 'GET'], - create: ['/v2/accounts/:account_code/adjustments', 'POST'], - remove: ['/v2/adjustments/:uuid', 'DELETE'] -} + list: ['/v2/accounts/:account_code/adjustments', 'GET'], + get: ['/v2/adjustments/:uuid', 'GET'], + create: ['/v2/accounts/:account_code/adjustments', 'POST'], + remove: ['/v2/adjustments/:uuid', 'DELETE'], +}; exports.billingInfo = { - get: ['/v2/accounts/:account_code/billing_info', 'GET'], - update: ['/v2/accounts/:account_code/billing_info', 'PUT'], - create: ['/v2/accounts/:account_code/billing_info', 'POST'], - remove: ['/v2/accounts/:account_code/billing_info', 'DELETE'] -} + get: ['/v2/accounts/:account_code/billing_info', 'GET'], + update: ['/v2/accounts/:account_code/billing_info', 'PUT'], + create: ['/v2/accounts/:account_code/billing_info', 'POST'], + remove: ['/v2/accounts/:account_code/billing_info', 'DELETE'], +}; exports.coupons = { - list: ['/v2/coupons', 'GET'], - get: ['/v2/coupons/:coupon_code', 'GET'], - create: ['/v2/coupons', 'POST'], - deactivate: ['/v2/coupons/:coupon_code', 'DELETE'] -} + list: ['/v2/coupons', 'GET'], + get: ['/v2/coupons/:coupon_code', 'GET'], + create: ['/v2/coupons', 'POST'], + deactivate: ['/v2/coupons/:coupon_code', 'DELETE'], +}; exports.couponRedemption = { - redeem: ['/v2/coupons/:coupon_code/redeem', 'POST'], - get: ['/v2/accounts/:account_code/redemption', 'GET'], - remove: ['/v2/accounts/:account_code/redemption', 'DELETE'], - getByInvoice: ['/v2/invoices/:invoice_number/redemption', 'GET'] -} + redeem: ['/v2/coupons/:coupon_code/redeem', 'POST'], + get: ['/v2/accounts/:account_code/redemption', 'GET'], + remove: ['/v2/accounts/:account_code/redemption', 'DELETE'], + getByInvoice: ['/v2/invoices/:invoice_number/redemption', 'GET'], +}; exports.invoices = { - list: ['/v2/invoices', 'GET'], - listByAccount: ['/v2/accounts/:account_code/invoices', 'GET'], - get: ['/v2/invoices/:invoice_number', 'GET'], - create: ['/v2/accounts/:account_code/invoices', 'POST'], - preview: ['/v2/accounts/:account_code/invoices/preview', 'POST'], - refundLineItems: ['/v2/invoices/:invoice_number/refund', 'POST'], - refundOpenAmount: ['/v2/invoices/:invoice_number/refund', 'POST'], - markSuccessful: ['/v2/invoices/:invoice_number/mark_successful', 'PUT'], - markFailed: ['/v2/invoices/:invoice_number/mark_failed', 'PUT'], - enterOfflinePayment: ['/v2/invoices/:invoice_number/transactions', 'POST'] -} + list: ['/v2/invoices', 'GET'], + listByAccount: ['/v2/accounts/:account_code/invoices', 'GET'], + get: ['/v2/invoices/:invoice_number', 'GET'], + create: ['/v2/accounts/:account_code/invoices', 'POST'], + preview: ['/v2/accounts/:account_code/invoices/preview', 'POST'], + refundLineItems: ['/v2/invoices/:invoice_number/refund', 'POST'], + refundOpenAmount: ['/v2/invoices/:invoice_number/refund', 'POST'], + markSuccessful: ['/v2/invoices/:invoice_number/mark_successful', 'PUT'], + markFailed: ['/v2/invoices/:invoice_number/mark_failed', 'PUT'], + enterOfflinePayment: ['/v2/invoices/:invoice_number/transactions', 'POST'], +}; exports.plans = { - list: ['/v2/plans', 'GET'], - get: ['/v2/plans/:plan_code', 'GET'], - create: ['/v2/plans', 'POST'], - update: ['/v2/plans/:plan_code', 'PUT'], - remove: ['/v2/plans/:plan_code', 'DELETE'] -} + list: ['/v2/plans', 'GET'], + get: ['/v2/plans/:plan_code', 'GET'], + create: ['/v2/plans', 'POST'], + update: ['/v2/plans/:plan_code', 'PUT'], + remove: ['/v2/plans/:plan_code', 'DELETE'], +}; exports.planAddons = { - list: ['/v2/plans/:plan_code/add_ons', 'GET'], - get: ['/v2/plans/:plan_code/add_ons/:addon_code', 'GET'], - create: ['/v2/plans/:plan_code/add_ons', 'POST'], - update: ['/v2/plans/:plan_code/add_ons/:add_on_code', 'PUT'], - remove: ['/v2/plans/:plan_code/add_ons/:add_on_code', 'DELETE'] -} + list: ['/v2/plans/:plan_code/add_ons', 'GET'], + get: ['/v2/plans/:plan_code/add_ons/:addon_code', 'GET'], + create: ['/v2/plans/:plan_code/add_ons', 'POST'], + update: ['/v2/plans/:plan_code/add_ons/:add_on_code', 'PUT'], + remove: ['/v2/plans/:plan_code/add_ons/:add_on_code', 'DELETE'], +}; exports.subscriptions = { - list: ['/v2/subscriptions', 'GET'], - listByAccount: ['/v2/accounts/:account_code/subscriptions', 'GET'], - get: ['/v2/subscriptions/:uuid', 'GET'], - create: ['/v2/subscriptions', 'POST'], - preview: ['/v2/subscriptions/preview', 'POST'], - update: ['/v2/subscriptions/:uuid', 'PUT'], - updateNotes: ['/v2/subscriptions/:uuid/notes', 'PUT'], - updatePreview: ['/v2/subscriptions/:uuid/preview', 'POST'], - cancel: ['/v2/subscriptions/:uuid/cancel', 'PUT'], - reactivate: ['/v2/subscriptions/:uuid/reactivate', 'PUT'], - terminate: ['/v2/subscriptions/:uuid/terminate?refund=:refund_type', 'PUT'], - postpone: ['/v2/subscriptions/:uuid/postpone?next_renewal_date=:next_renewal_date', 'PUT'] -} + list: ['/v2/subscriptions', 'GET'], + listByAccount: ['/v2/accounts/:account_code/subscriptions', 'GET'], + get: ['/v2/subscriptions/:uuid', 'GET'], + create: ['/v2/subscriptions', 'POST'], + preview: ['/v2/subscriptions/preview', 'POST'], + update: ['/v2/subscriptions/:uuid', 'PUT'], + updateNotes: ['/v2/subscriptions/:uuid/notes', 'PUT'], + updatePreview: ['/v2/subscriptions/:uuid/preview', 'POST'], + cancel: ['/v2/subscriptions/:uuid/cancel', 'PUT'], + reactivate: ['/v2/subscriptions/:uuid/reactivate', 'PUT'], + terminate: ['/v2/subscriptions/:uuid/terminate?refund=:refund_type', 'PUT'], + postpone: [ + '/v2/subscriptions/:uuid/postpone?next_renewal_date=:next_renewal_date', + 'PUT', + ], +}; exports.transactions = { - list: ['/v2/transactions', 'GET'], - listByAccount: ['/v2/accounts/:account_code/transactions', 'GET'], - get: ['/v2/transactions/:id', 'GET'], - create: ['/v2/transactions', 'POST'], - refund: ['/v2/transactions/:id', 'DELETE'] -} + list: ['/v2/transactions', 'GET'], + listByAccount: ['/v2/accounts/:account_code/transactions', 'GET'], + get: ['/v2/transactions/:id', 'GET'], + create: ['/v2/transactions', 'POST'], + refund: ['/v2/transactions/:id', 'DELETE'], +}; exports.usage = { - list: ['/v2/subscriptions/:uuid/add_ons/:add_on_code/usage?billing_status=:billing_status', 'GET'], - log: ['/v2/subscriptions/:uuid/add_ons/:add_on_code/usage', 'POST'], - get: ['/v2/subscriptions/:uuid/add_ons/:add_on_code/usage/:usage_id', 'GET'], - update: ['/v2/subscriptions/:uuid/add_ons/:add_on_code/usage/:usage_id', 'PUT'], - remove: ['/v2/subscriptions/:uuid/add_ons/:add_on_code/usage/:usage_id', 'DELETE'] -} \ No newline at end of file + list: [ + '/v2/subscriptions/:uuid/add_ons/:add_on_code/usage?billing_status=:billing_status', + 'GET', + ], + log: ['/v2/subscriptions/:uuid/add_ons/:add_on_code/usage', 'POST'], + get: ['/v2/subscriptions/:uuid/add_ons/:add_on_code/usage/:usage_id', 'GET'], + update: [ + '/v2/subscriptions/:uuid/add_ons/:add_on_code/usage/:usage_id', + 'PUT', + ], + remove: [ + '/v2/subscriptions/:uuid/add_ons/:add_on_code/usage/:usage_id', + 'DELETE', + ], +}; + +exports.shippingAddress = { + create: ['/v2/accounts/:account_code/shipping_addresses', 'POST'], + update: [ + '/v2/accounts/:account_code/shipping_addresses/:shipping_address_id', + 'PUT', + ], + listByAccount: ['/v2/accounts/:account_code/shipping_addresses', 'GET'], + get: [ + '/v2/accounts/:account_code/shipping_addresses/:shipping_address_id', + 'GET', + ], + remove: [ + '/v2/accounts/:account_code/shipping_addresses/:shipping_address_id', + 'DELETE', + ], +}; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..7e4278d --- /dev/null +++ b/package-lock.json @@ -0,0 +1,27 @@ +{ + "name": "node-recurly", + "version": "2.1.2", + "lockfileVersion": 1, + "dependencies": { + "js2xmlparser": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/js2xmlparser/-/js2xmlparser-0.1.7.tgz", + "integrity": "sha1-yKS/m6AFd8SyzgvW5xTug0Glhq4=" + }, + "sax": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", + "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" + }, + "xml2js": { + "version": "0.4.19", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.19.tgz", + "integrity": "sha512-esZnJZJOiJR9wWKMyuvSE1y6Dq5LCuJanqhxslH2bxM6duahNZ+HMpCLhBQGZkbX6xRf8x1Y2eJlgt2q3qo49Q==" + }, + "xmlbuilder": { + "version": "9.0.7", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz", + "integrity": "sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0=" + } + } +} diff --git a/package.json b/package.json index a91e15b..a3ed214 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,22 @@ -{ "name" : "node-recurly" -, "description" : "Library for accessing the api for the Recurly recurring billing service." -, "keywords" : [ "recurly", "e-commerce", "recurring billing" ] -, "version" : "2.1.1" -, "homepage" : "https://github.com/cgerrior/node-recurly" -, "author" : "Charlie Gerrior (http://github.com/cgerrior)" -, "contributors" : [ - "Iván Guardado (http://github.com/IvanGuardado)", - "Rob Righter (http://github.com/robrighter)", - "Dmitriy Shekhovtsov (https://github.com/valorkin)" - ] -, "bugs" : - { "web" : "https://github.com/cgerrior/node-recurly/issues" } -, "directories" : { "lib" : "./lib" } -, "main" : "./lib/recurly.js" -, "dependencies" : { +{ + "name": "node-recurly", + "description": "Library for accessing the api for the Recurly recurring billing service.", + "keywords": [ + "recurly", + "e-commerce", + "recurring billing" + ], + "version": "2.1.2", + "homepage": "https://github.com/codemotion-ninja/node-recurly", + "directories": { + "lib": "./lib" + }, + "main": "./lib/recurly.js", + "dependencies": { "xml2js": ">= 0.4.0", "js2xmlparser": "0.1.7" -} -, "engines" : { "node" : ">= 0.4" } + }, + "engines": { + "node": ">= 0.4" + } }