Skip to content

Commit

Permalink
Add customer.list function
Browse files Browse the repository at this point in the history
  • Loading branch information
abh committed Sep 28, 2011
1 parent f991200 commit aa8d3f8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
7 changes: 4 additions & 3 deletions README.md
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions lib/main.js
Expand Up @@ -95,13 +95,19 @@ 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) {
post("/v1/customers/" + customer_id, data, cb);
},
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: {
Expand Down
10 changes: 9 additions & 1 deletion test/customers.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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});

0 comments on commit aa8d3f8

Please sign in to comment.