/
customers.js
72 lines (68 loc) · 2.59 KB
/
customers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var vows = require('vows'),
assert = require('assert'),
sys = require('sys');
var api_key = process.env.STRIPE_API;
if (!api_key) {
sys.puts('To run vows, you must have a STRIPE_API environment variable with a test api key');
process.exit(2)
}
var stripe = require('./../lib/main.js')(api_key);
vows.describe("Customer API").addBatch({
'Create customer' : {
topic: function() {
stripe.customers.create({email: "foo@example.com"}, this.callback);
},
'returns a customer': function(err, response) {
assert.isNull(err);
console.log("response", response);
assert.isDefined(response);
assert.equal(response.object, 'customer');
assert.equal(response.email, "foo@example.com");
},
'Retrieve customer' : {
topic: function(create_err, customer) {
stripe.customers.retrieve(customer.id, this.callback);
},
'Got customer' : function(err, response) {
assert.equal( response.email, 'foo@example.com' );
},
},
'Update customer' : {
topic: function(create_err, customer) {
stripe.customers.update(customer.id, {
description: "test",
card: { number: "4111111111111111",
exp_month: 12,
exp_year: 2020,
name: "T. Ester"
}
}, this.callback);
},
'Customer updated' : function (err, response) {
assert.equal(response.description, 'test');
assert.equal(response.active_card.exp_year, 2020);
assert.equal(response.active_card.type, 'Visa');
assert.equal(response.email, 'foo@example.com');
},
'Delete customer' : {
topic: function(create_err, customer) {
console.log("customer for deletion", customer);
stripe.customers.del(customer.id, this.callback);
},
'Customer was deleted': function(err,response) {
console.log("response", response);
assert.isNull(err);
assert.isTrue(response.deleted);
}
},
},
},
'Customer list' : {
topic: function() {
stripe.customers.list(5, 0, this.callback);
},
'Got count': function(err, response) {
assert.isNumber(response.count);
},
}
}).export(module, {error: false});