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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
THE SOFTWARE.
46 changes: 46 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})

}
},

Expand Down
19 changes: 19 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

})

})

})

})


Expand Down