diff --git a/README.md b/README.md index 73e8ed4..67343bd 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,8 @@ All methods take a callback as their last parameter, it's called with an error, * `.underwrite(account_id, underwriting_info, cb)` - adds extra deatils for underwriting purposes * `.get(account_id, cb)` - returns account details * `.transactions(account_id, cb)` - returns object of credits and debits for the account + * `.assets(account_id, options, cb)` - return all cards and bank accounts for the account + * `options` _(optional)_ - Accepts `card_limit` and `bank_account_limit` keys * `.marketplace` * `.accounts(cb)` - get all of the marketplace's accounts * `.debits(cb)` - get all of the marketplace's debits @@ -78,4 +80,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file +THE SOFTWARE. diff --git a/index.js b/index.js index e9d6cbe..802b14b 100644 --- a/index.js +++ b/index.js @@ -108,6 +108,52 @@ module.exports = function(api_secret, marketplace_id) { client("GET", "/v1/marketplaces/"+marketplace_id+"/accounts/"+account_id+"/transactions", cb) + }, + + assets: function(account_id, opts, cb){ + + if(typeof(opts) !== "object"){ + cb = opts + opts = {} + } + + opts.card_limit = opts.card_limit || 10 + opts.bank_account_limit = opts.bank_account_limit || 10 + + var sentinel = 2 + var completed = 0 + + var assets = {} + var errors = [] + + client("GET", "/v1/marketplaces/"+marketplace_id+"/accounts/"+account_id+"/cards?limit="+opts.card_limit, function(err, res) { + if(err) { + errors.push(err); + } else { + assets.cards = res.items + } + + completed++ + + if(completed >= sentinel && typeof(cb) === "function") { + cb(errors.length > 0 ? errors : false, assets) + } + }) + + client("GET", "/v1/marketplaces/"+marketplace_id+"/accounts/"+account_id+"/bank_accounts?limit="+opts.bank_account_limit, function(err, res) { + if(err) { + errors.push(err); + } else { + assets.bank_accounts = res.items + } + + completed++ + + if(completed >= sentinel && typeof(cb) === "function") { + cb(errors.length >= 0 ? errors : false, assets) + } + }) + } }, diff --git a/tests/index.js b/tests/index.js index a050edb..ba38b7d 100644 --- a/tests/index.js +++ b/tests/index.js @@ -294,6 +294,25 @@ describe('balanced', function(){ }) }) + describe('.assets', function(done){ + + it('should get all the cards/bank accounts for this account', function(done){ + + balanced.account.assets(test.account_id, function(err, res){ + + assert.notEqual(res.cards, null, "res.cards is null") + assert.notEqual(res.bank_accounts, null, "res.bank_accounts is null") + assert.equal(res.cards.length > 0, true, "res.cards doesn't have any content") + assert.equal(res.bank_accounts.length > 0, true, "res.bank_accounts doesn't have any content") + + done() + + }) + + }) + + }) + })