forked from stripe/stripe-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharges.js
132 lines (127 loc) · 4.48 KB
/
charges.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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("Charges API").addBatch({
'Create charge' : {
topic: function() {
stripe.charges.create({
amount: "50",
currency: "usd",
card: { number: "4242424242424242",
exp_month: 12,
exp_year: 2020,
name: "T. Ester",
}
}, this.callback);
},
'returns a charge' : function(err, response) {
assert.isNull(err);
assert.isDefined(response);
assert.equal(response.object, 'charge');
assert.isDefined(response.id);
},
'Retrieve a charge' : {
topic: function(create_err, charge) {
stripe.charges.retrieve(charge.id, this.callback);
},
'Got a charge' : function(err, response) {
assert.isNull(err);
assert.isDefined(response);
assert.equal(response.object, 'charge');
assert.isDefined(response.id);
},
},
'Refund a charge' : {
topic: function(create_err, charge) {
stripe.charges.refund(charge.id, 50, this.callback);
},
'Got a refund' : function(err, response) {
assert.isNull(err);
assert.isDefined(response);
assert.isTrue(response.refunded);
},
},
},
'Create an uncaptured charge' : {
topic: function() {
stripe.charges.create({
amount: "50",
capture: false,
currency: "usd",
card: { number: "4242424242424242",
exp_month: 12,
exp_year: 2020,
name: "T. Ester"
}
}, this.callback);
},
'returns an uncaptured charge' : function(err, response) {
assert.isNull(err);
assert.isDefined(response);
assert.equal(response.object, 'charge');
assert.isDefined(response.id);
assert.equal(response.captured, false);
},
'Capture a charge fully' : {
topic: function(create_err, charge) {
stripe.charges.capture(charge.id, this.callback);
},
'Got a charge' : function(err, response) {
assert.isNull(err);
assert.isDefined(response);
assert.equal(response.object, 'charge');
assert.isDefined(response.id);
assert.equal(response.amount_refunded, 0);
assert.equal(response.captured, true);
}
}
},
'Create an other uncaptured charge' : {
topic: function() {
stripe.charges.create({
amount: "100",
capture: false,
currency: "usd",
card: { number: "4242424242424242",
exp_month: 12,
exp_year: 2020,
name: "T. Ester"
}
}, this.callback);
},
'returns an uncaptured charge' : function(err, response) {
assert.isNull(err);
assert.isDefined(response);
assert.equal(response.object, 'charge');
assert.isDefined(response.id);
assert.equal(response.captured, false);
},
'Capture part of a charge' : {
topic: function(create_err, charge) {
stripe.charges.capture(charge.id, {amount: 50}, this.callback);
},
'Got a charge' : function(err, response) {
assert.isNull(err);
assert.isDefined(response);
assert.equal(response.object, 'charge');
assert.isDefined(response.id);
assert.equal(response.amount_refunded, 50);
assert.equal(response.captured, true);
}
}
},
'Charge list' : {
topic: function() {
stripe.charges.list({}, this.callback);
},
'Got count': function(err, response) {
assert.isNumber(response.count);
},
}
}).export(module, {error: false});