From aa8d3f8f0aad8241465e85523e876e9f86430dfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ask=20Bj=C3=B8rn=20Hansen?= Date: Wed, 28 Sep 2011 03:13:02 -0700 Subject: [PATCH] Add customer.list function --- README.md | 7 ++++--- lib/main.js | 6 ++++++ test/customers.js | 10 +++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f775900278..7b3b710754 100644 --- a/README.md +++ b/README.md @@ -27,14 +27,15 @@ Access to the [Stripe](https://stripe.com/) [API](http://stripe.com/api). ## API -All methods takes a callback as their last parameter. The callback is called with an error code (if any) and then -the response. +All methods takes a callback as their last parameter. The callback is +called with an error code (if any) and then the response. * `stripe.customers` - create, retrieve, update and delete customers * `.create(customer)` - create a customer, takes the data as an object - * `.retrieve(customer_id)` - retrieve a customer by customer id + * `.retrieve(customer_id)` - retrieve a customer by customer id. * `.update(customer_id, updates)` - update a customer; `updates` is an object with new parameters * `.del(customer_id)` - mark the customer deleted + * `.list(count, offset)` - [List customers](https://stripe.com/api/docs#list_customers) * `stripe.tokens` - [Tokens API](https://stripe.com/api/docs#tokens) * `.create(card_data)` - [create a token](https://stripe.com/api/docs#create_token) * `.retrieve(token_id)` - [retrieve a card token](https://stripe.com/api/docs#retrieve_token) diff --git a/lib/main.js b/lib/main.js index 01130ee781..64f77b5547 100644 --- a/lib/main.js +++ b/lib/main.js @@ -95,6 +95,9 @@ module.exports = function (api_key, options) { post("/v1/customers", data, cb); }, retrieve: function(customer_id, cb) { + if (!(customer_id && typeof customer_id === 'string')) { + cb("customer_id required"); + } get("/v1/customers/" + customer_id, {}, cb); }, update: function(customer_id, data, cb) { @@ -102,6 +105,9 @@ module.exports = function (api_key, options) { }, del: function(customer_id, cb) { del("/v1/customers/" + customer_id, {}, cb); + }, + list: function(count, offset, cb) { + get("/v1/customers", { count: count, offset: offset}, cb ); } }, token: { diff --git a/test/customers.js b/test/customers.js index e30236998f..8d55d3af98 100644 --- a/test/customers.js +++ b/test/customers.js @@ -13,7 +13,7 @@ var stripe = require('./../lib/main.js')(api_key); vows.describe("Customer API").addBatch({ 'Create customer' : { - topic: function() { + topic: function() { stripe.customers.create({email: "foo@example.com"}, this.callback); }, 'returns a customer': function(err, response) { @@ -61,4 +61,12 @@ vows.describe("Customer API").addBatch({ }, }, }, + 'Customer list' : { + topic: function() { + stripe.customers.list(5, 0, this.callback); + }, + 'Got count': function(err, response) { + assert.isNumber(response.count); + }, + } }).export(module, {error: false});