stripe 1.16.0 → 1.16.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +5 -1
- data/History.txt +6 -0
- data/README.rdoc +7 -1
- data/VERSION +1 -1
- data/lib/stripe/api_operations/create.rb +3 -2
- data/lib/stripe/api_operations/delete.rb +3 -3
- data/lib/stripe/api_operations/list.rb +3 -2
- data/lib/stripe/api_resource.rb +1 -2
- data/lib/stripe/application_fee.rb +3 -3
- data/lib/stripe/charge.rb +32 -11
- data/lib/stripe/customer.rb +18 -10
- data/lib/stripe/invoice.rb +0 -1
- data/lib/stripe/list_object.rb +6 -4
- data/lib/stripe/singleton_api_resource.rb +1 -1
- data/lib/stripe/stripe_object.rb +4 -4
- data/lib/stripe/transfer.rb +0 -1
- data/lib/stripe/util.rb +36 -11
- data/lib/stripe/version.rb +1 -1
- data/test/stripe/api_resource_test.rb +31 -1
- data/test/stripe/charge_test.rb +17 -1
- data/test/stripe/coupon_test.rb +10 -1
- data/test/stripe/util_test.rb +31 -1
- data/test/test_data.rb +409 -0
- data/test/test_helper.rb +3 -407
- metadata +4 -2
data/test/stripe/charge_test.rb
CHANGED
@@ -36,6 +36,22 @@ module Stripe
|
|
36
36
|
c.save
|
37
37
|
end
|
38
38
|
|
39
|
+
should "charges should be able to be marked as fraudulent" do
|
40
|
+
@mock.expects(:get).once.returns(test_response(test_charge))
|
41
|
+
@mock.expects(:post).once.returns(test_response(test_charge))
|
42
|
+
c = Stripe::Charge.new("test_charge")
|
43
|
+
c.refresh
|
44
|
+
c.mark_as_fraudulent
|
45
|
+
end
|
46
|
+
|
47
|
+
should "charges should be able to be marked as safe" do
|
48
|
+
@mock.expects(:get).once.returns(test_response(test_charge))
|
49
|
+
@mock.expects(:post).once.returns(test_response(test_charge))
|
50
|
+
c = Stripe::Charge.new("test_charge")
|
51
|
+
c.refresh
|
52
|
+
c.mark_as_safe
|
53
|
+
end
|
54
|
+
|
39
55
|
should "charges should have Card objects associated with their Card property" do
|
40
56
|
@mock.expects(:get).once.returns(test_response(test_charge))
|
41
57
|
c = Stripe::Charge.retrieve("test_charge")
|
@@ -64,4 +80,4 @@ module Stripe
|
|
64
80
|
assert c.paid
|
65
81
|
end
|
66
82
|
end
|
67
|
-
end
|
83
|
+
end
|
data/test/stripe/coupon_test.rb
CHANGED
@@ -7,5 +7,14 @@ module Stripe
|
|
7
7
|
c = Stripe::Coupon.create
|
8
8
|
assert_equal "co_test_coupon", c.id
|
9
9
|
end
|
10
|
+
|
11
|
+
should "coupons should be updateable" do
|
12
|
+
@mock.expects(:get).once.returns(test_response(test_coupon))
|
13
|
+
@mock.expects(:post).once.returns(test_response(test_coupon))
|
14
|
+
c = Stripe::Coupon.new("test_coupon")
|
15
|
+
c.refresh
|
16
|
+
c.metadata['foo'] = 'bar'
|
17
|
+
c.save
|
18
|
+
end
|
10
19
|
end
|
11
|
-
end
|
20
|
+
end
|
data/test/stripe/util_test.rb
CHANGED
@@ -25,5 +25,35 @@ module Stripe
|
|
25
25
|
symbolized = Stripe::Util.symbolize_names(start)
|
26
26
|
assert_equal(finish, symbolized)
|
27
27
|
end
|
28
|
+
|
29
|
+
should "parse a nil opts argument" do
|
30
|
+
api_key, headers = Stripe::Util.parse_opts(nil)
|
31
|
+
assert_equal({}, headers)
|
32
|
+
assert_equal(nil, api_key)
|
33
|
+
end
|
34
|
+
|
35
|
+
should "parse a string opts argument" do
|
36
|
+
api_key, headers = Stripe::Util.parse_opts('foo')
|
37
|
+
assert_equal({}, headers)
|
38
|
+
assert_equal('foo', api_key)
|
39
|
+
end
|
40
|
+
|
41
|
+
should "parse a hash opts argument with just api_key" do
|
42
|
+
api_key, headers = Stripe::Util.parse_opts({:api_key => 'foo'})
|
43
|
+
assert_equal({}, headers)
|
44
|
+
assert_equal('foo', api_key)
|
45
|
+
end
|
46
|
+
|
47
|
+
should "parse a hash opts argument with just idempotency_key" do
|
48
|
+
api_key, headers = Stripe::Util.parse_opts({:idempotency_key => 'foo'})
|
49
|
+
assert_equal({:idempotency_key => 'foo'}, headers)
|
50
|
+
assert_equal(nil, api_key)
|
51
|
+
end
|
52
|
+
|
53
|
+
should "parse a hash opts argument both idempotency_key and api_key" do
|
54
|
+
api_key, headers = Stripe::Util.parse_opts({:api_key => 'bar', :idempotency_key => 'foo'})
|
55
|
+
assert_equal({:idempotency_key => 'foo'}, headers)
|
56
|
+
assert_equal('bar', api_key)
|
57
|
+
end
|
28
58
|
end
|
29
|
-
end
|
59
|
+
end
|
data/test/test_data.rb
ADDED
@@ -0,0 +1,409 @@
|
|
1
|
+
module Stripe
|
2
|
+
module TestData
|
3
|
+
def test_response(body, code=200)
|
4
|
+
# When an exception is raised, restclient clobbers method_missing. Hence we
|
5
|
+
# can't just use the stubs interface.
|
6
|
+
body = JSON.generate(body) if !(body.kind_of? String)
|
7
|
+
m = mock
|
8
|
+
m.instance_variable_set('@stripe_values', { :body => body, :code => code })
|
9
|
+
def m.body; @stripe_values[:body]; end
|
10
|
+
def m.code; @stripe_values[:code]; end
|
11
|
+
m
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_balance(params={})
|
15
|
+
{
|
16
|
+
:pending => [
|
17
|
+
{:amount => 12345, :currency => "usd"}
|
18
|
+
],
|
19
|
+
:available => [
|
20
|
+
{:amount => 6789, :currency => "usd"}
|
21
|
+
],
|
22
|
+
:livemode => false,
|
23
|
+
:object => "balance"
|
24
|
+
}.merge(params)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_balance_transaction(params={})
|
28
|
+
{
|
29
|
+
:amount => 100,
|
30
|
+
:net => 41,
|
31
|
+
:currency => "usd",
|
32
|
+
:type => "charge",
|
33
|
+
:created => 1371945005,
|
34
|
+
:available_on => 1372549805,
|
35
|
+
:status => "pending",
|
36
|
+
:description => "A test balance transaction",
|
37
|
+
:fee => 59,
|
38
|
+
:object => "balance_transaction"
|
39
|
+
}.merge(params)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_balance_transaction_array
|
43
|
+
{
|
44
|
+
:data => [test_balance_transaction, test_balance_transaction, test_balance_transaction],
|
45
|
+
:object => "list",
|
46
|
+
:url => "/v1/balance/history"
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_application_fee(params={})
|
51
|
+
id = params[:id] || 'fee_test_fee'
|
52
|
+
{
|
53
|
+
:refunded => false,
|
54
|
+
:amount => 100,
|
55
|
+
:application => "ca_test_application",
|
56
|
+
:user => "acct_test_user",
|
57
|
+
:charge => "ch_test_charge",
|
58
|
+
:id => id,
|
59
|
+
:livemode => false,
|
60
|
+
:currency => "usd",
|
61
|
+
:object => "application_fee",
|
62
|
+
:refunds => test_application_fee_refund_array(id),
|
63
|
+
:created => 1304114826
|
64
|
+
}.merge(params)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_application_fee_refund(params = {})
|
68
|
+
{
|
69
|
+
:object => 'fee_refund',
|
70
|
+
:amount => 30,
|
71
|
+
:currency => "usd",
|
72
|
+
:created => 1308595038,
|
73
|
+
:id => "ref_test_app_fee_refund",
|
74
|
+
:fee => "ca_test_application",
|
75
|
+
:metadata => {}
|
76
|
+
}.merge(params)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_application_fee_array
|
80
|
+
{
|
81
|
+
:data => [test_application_fee, test_application_fee, test_application_fee],
|
82
|
+
:object => 'list',
|
83
|
+
:url => '/v1/application_fees'
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_application_fee_refund_array(fee_id)
|
88
|
+
{
|
89
|
+
:data => [test_application_fee_refund, test_application_fee_refund, test_application_fee_refund],
|
90
|
+
:object => 'list',
|
91
|
+
:url => '/v1/application_fees/' + fee_id + '/refunds'
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_customer(params={})
|
96
|
+
id = params[:id] || 'c_test_customer'
|
97
|
+
{
|
98
|
+
:subscription_history => [],
|
99
|
+
:bills => [],
|
100
|
+
:charges => [],
|
101
|
+
:livemode => false,
|
102
|
+
:object => "customer",
|
103
|
+
:id => id,
|
104
|
+
:default_card => "cc_test_card",
|
105
|
+
:created => 1304114758,
|
106
|
+
:cards => test_card_array(id),
|
107
|
+
:metadata => {},
|
108
|
+
:subscriptions => test_subscription_array(id)
|
109
|
+
}.merge(params)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_customer_array
|
113
|
+
{
|
114
|
+
:data => [test_customer, test_customer, test_customer],
|
115
|
+
:object => 'list',
|
116
|
+
:url => '/v1/customers'
|
117
|
+
}
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_charge(params={})
|
121
|
+
id = params[:id] || 'ch_test_charge'
|
122
|
+
{
|
123
|
+
:refunded => false,
|
124
|
+
:paid => true,
|
125
|
+
:amount => 100,
|
126
|
+
:card => {
|
127
|
+
:type => "Visa",
|
128
|
+
:last4 => "4242",
|
129
|
+
:exp_month => 11,
|
130
|
+
:country => "US",
|
131
|
+
:exp_year => 2012,
|
132
|
+
:id => "cc_test_card",
|
133
|
+
:object => "card"
|
134
|
+
},
|
135
|
+
:id => id,
|
136
|
+
:reason => "execute_charge",
|
137
|
+
:livemode => false,
|
138
|
+
:currency => "usd",
|
139
|
+
:object => "charge",
|
140
|
+
:created => 1304114826,
|
141
|
+
:refunds => test_refund_array(id),
|
142
|
+
:metadata => {}
|
143
|
+
}.merge(params)
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_charge_array
|
147
|
+
{
|
148
|
+
:data => [test_charge, test_charge, test_charge],
|
149
|
+
:object => 'list',
|
150
|
+
:url => '/v1/charges'
|
151
|
+
}
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_card_array(customer_id)
|
155
|
+
{
|
156
|
+
:data => [test_card, test_card, test_card],
|
157
|
+
:object => 'list',
|
158
|
+
:url => '/v1/customers/' + customer_id + '/cards'
|
159
|
+
}
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_card(params={})
|
163
|
+
{
|
164
|
+
:type => "Visa",
|
165
|
+
:last4 => "4242",
|
166
|
+
:exp_month => 11,
|
167
|
+
:country => "US",
|
168
|
+
:exp_year => 2012,
|
169
|
+
:id => "cc_test_card",
|
170
|
+
:customer => 'c_test_customer',
|
171
|
+
:object => "card"
|
172
|
+
}.merge(params)
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_coupon(params={})
|
176
|
+
{
|
177
|
+
:duration => 'repeating',
|
178
|
+
:duration_in_months => 3,
|
179
|
+
:percent_off => 25,
|
180
|
+
:id => "co_test_coupon",
|
181
|
+
:object => "coupon",
|
182
|
+
:metadata => {},
|
183
|
+
}.merge(params)
|
184
|
+
end
|
185
|
+
|
186
|
+
#FIXME nested overrides would be better than hardcoding plan_id
|
187
|
+
def test_subscription(params = {})
|
188
|
+
plan = params.delete(:plan) || 'gold'
|
189
|
+
{
|
190
|
+
:current_period_end => 1308681468,
|
191
|
+
:status => "trialing",
|
192
|
+
:plan => {
|
193
|
+
:interval => "month",
|
194
|
+
:amount => 7500,
|
195
|
+
:trial_period_days => 30,
|
196
|
+
:object => "plan",
|
197
|
+
:identifier => plan
|
198
|
+
},
|
199
|
+
:current_period_start => 1308595038,
|
200
|
+
:start => 1308595038,
|
201
|
+
:object => "subscription",
|
202
|
+
:trial_start => 1308595038,
|
203
|
+
:trial_end => 1308681468,
|
204
|
+
:customer => "c_test_customer",
|
205
|
+
:id => 's_test_subscription'
|
206
|
+
}.merge(params)
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_refund(params = {})
|
210
|
+
{
|
211
|
+
:object => 'refund',
|
212
|
+
:amount => 30,
|
213
|
+
:currency => "usd",
|
214
|
+
:created => 1308595038,
|
215
|
+
:id => "ref_test_refund",
|
216
|
+
:charge => "ch_test_charge",
|
217
|
+
:metadata => {}
|
218
|
+
}.merge(params)
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_subscription_array(customer_id)
|
222
|
+
{
|
223
|
+
:data => [test_subscription, test_subscription, test_subscription],
|
224
|
+
:object => 'list',
|
225
|
+
:url => '/v1/customers/' + customer_id + '/subscriptions'
|
226
|
+
}
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_refund_array(charge_id)
|
230
|
+
{
|
231
|
+
:data => [test_refund, test_refund, test_refund],
|
232
|
+
:object => 'list',
|
233
|
+
:url => '/v1/charges/' + charge_id + '/refunds'
|
234
|
+
}
|
235
|
+
end
|
236
|
+
|
237
|
+
|
238
|
+
def test_invoice
|
239
|
+
{
|
240
|
+
:id => 'in_test_invoice',
|
241
|
+
:object => 'invoice',
|
242
|
+
:livemode => false,
|
243
|
+
:amount_due => 1000,
|
244
|
+
:attempt_count => 0,
|
245
|
+
:attempted => false,
|
246
|
+
:closed => false,
|
247
|
+
:currency => 'usd',
|
248
|
+
:customer => 'c_test_customer',
|
249
|
+
:date => 1349738950,
|
250
|
+
:lines => {
|
251
|
+
"invoiceitems" => [
|
252
|
+
{
|
253
|
+
:id => 'ii_test_invoice_item',
|
254
|
+
:object => '',
|
255
|
+
:livemode => false,
|
256
|
+
:amount => 1000,
|
257
|
+
:currency => 'usd',
|
258
|
+
:customer => 'c_test_customer',
|
259
|
+
:date => 1349738950,
|
260
|
+
:description => "A Test Invoice Item",
|
261
|
+
:invoice => 'in_test_invoice'
|
262
|
+
},
|
263
|
+
],
|
264
|
+
},
|
265
|
+
:paid => false,
|
266
|
+
:period_end => 1349738950,
|
267
|
+
:period_start => 1349738950,
|
268
|
+
:starting_balance => 0,
|
269
|
+
:subtotal => 1000,
|
270
|
+
:total => 1000,
|
271
|
+
:charge => nil,
|
272
|
+
:discount => nil,
|
273
|
+
:ending_balance => nil,
|
274
|
+
:next_payemnt_attempt => 1349825350,
|
275
|
+
}
|
276
|
+
end
|
277
|
+
|
278
|
+
def test_paid_invoice
|
279
|
+
test_invoice.merge({
|
280
|
+
:attempt_count => 1,
|
281
|
+
:attempted => true,
|
282
|
+
:closed => true,
|
283
|
+
:paid => true,
|
284
|
+
:charge => 'ch_test_charge',
|
285
|
+
:ending_balance => 0,
|
286
|
+
:next_payment_attempt => nil,
|
287
|
+
})
|
288
|
+
end
|
289
|
+
|
290
|
+
def test_invoice_customer_array
|
291
|
+
{
|
292
|
+
:data => [test_invoice],
|
293
|
+
:object => 'list',
|
294
|
+
:url => '/v1/invoices?customer=test_customer'
|
295
|
+
}
|
296
|
+
end
|
297
|
+
|
298
|
+
def test_recipient(params={})
|
299
|
+
id = params[:id] || 'rp_test_recipient'
|
300
|
+
{
|
301
|
+
:name => "Stripe User",
|
302
|
+
:type => "individual",
|
303
|
+
:livemode => false,
|
304
|
+
:object => "recipient",
|
305
|
+
:id => "rp_test_recipient",
|
306
|
+
:cards => test_card_array(id),
|
307
|
+
:default_card => "debit_test_card",
|
308
|
+
:active_account => {
|
309
|
+
:last4 => "6789",
|
310
|
+
:bank_name => "STRIPE TEST BANK",
|
311
|
+
:country => "US",
|
312
|
+
:object => "bank_account"
|
313
|
+
},
|
314
|
+
:created => 1304114758,
|
315
|
+
:verified => true,
|
316
|
+
:metadata => {}
|
317
|
+
}.merge(params)
|
318
|
+
end
|
319
|
+
|
320
|
+
def test_recipient_array
|
321
|
+
{
|
322
|
+
:data => [test_recipient, test_recipient, test_recipient],
|
323
|
+
:object => 'list',
|
324
|
+
:url => '/v1/recipients'
|
325
|
+
}
|
326
|
+
end
|
327
|
+
|
328
|
+
def test_transfer(params={})
|
329
|
+
{
|
330
|
+
:status => 'pending',
|
331
|
+
:amount => 100,
|
332
|
+
:account => {
|
333
|
+
:object => 'bank_account',
|
334
|
+
:country => 'US',
|
335
|
+
:bank_name => 'STRIPE TEST BANK',
|
336
|
+
:last4 => '6789'
|
337
|
+
},
|
338
|
+
:recipient => 'test_recipient',
|
339
|
+
:fee => 0,
|
340
|
+
:fee_details => [],
|
341
|
+
:id => "tr_test_transfer",
|
342
|
+
:livemode => false,
|
343
|
+
:currency => "usd",
|
344
|
+
:object => "transfer",
|
345
|
+
:date => 1304114826,
|
346
|
+
:metadata => {}
|
347
|
+
}.merge(params)
|
348
|
+
end
|
349
|
+
|
350
|
+
def test_transfer_array
|
351
|
+
{
|
352
|
+
:data => [test_transfer, test_transfer, test_transfer],
|
353
|
+
:object => 'list',
|
354
|
+
:url => '/v1/transfers'
|
355
|
+
}
|
356
|
+
end
|
357
|
+
|
358
|
+
def test_canceled_transfer
|
359
|
+
test_transfer.merge({
|
360
|
+
:status => 'canceled'
|
361
|
+
})
|
362
|
+
end
|
363
|
+
|
364
|
+
def test_invalid_api_key_error
|
365
|
+
{
|
366
|
+
:error => {
|
367
|
+
:type => "invalid_request_error",
|
368
|
+
:message => "Invalid API Key provided: invalid"
|
369
|
+
}
|
370
|
+
}
|
371
|
+
end
|
372
|
+
|
373
|
+
def test_invalid_exp_year_error
|
374
|
+
{
|
375
|
+
:error => {
|
376
|
+
:code => "invalid_expiry_year",
|
377
|
+
:param => "exp_year",
|
378
|
+
:type => "card_error",
|
379
|
+
:message => "Your card's expiration year is invalid"
|
380
|
+
}
|
381
|
+
}
|
382
|
+
end
|
383
|
+
|
384
|
+
def test_missing_id_error
|
385
|
+
{
|
386
|
+
:error => {
|
387
|
+
:param => "id",
|
388
|
+
:type => "invalid_request_error",
|
389
|
+
:message => "Missing id"
|
390
|
+
}
|
391
|
+
}
|
392
|
+
end
|
393
|
+
|
394
|
+
def test_api_error
|
395
|
+
{
|
396
|
+
:error => {
|
397
|
+
:type => "api_error"
|
398
|
+
}
|
399
|
+
}
|
400
|
+
end
|
401
|
+
|
402
|
+
def test_delete_discount_response
|
403
|
+
{
|
404
|
+
:deleted => true,
|
405
|
+
:id => "di_test_coupon"
|
406
|
+
}
|
407
|
+
end
|
408
|
+
end
|
409
|
+
end
|