stripe-ruby-mock 2.3.1 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/stripe_mock.rb +2 -0
  4. data/lib/stripe_mock/api/errors.rb +2 -1
  5. data/lib/stripe_mock/api/instance.rb +10 -0
  6. data/lib/stripe_mock/api/webhooks.rb +3 -0
  7. data/lib/stripe_mock/data.rb +196 -17
  8. data/lib/stripe_mock/instance.rb +14 -3
  9. data/lib/stripe_mock/request_handlers/accounts.rb +7 -0
  10. data/lib/stripe_mock/request_handlers/charges.rb +24 -21
  11. data/lib/stripe_mock/request_handlers/country_spec.rb +22 -0
  12. data/lib/stripe_mock/request_handlers/customers.rb +3 -3
  13. data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +5 -2
  14. data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +2 -1
  15. data/lib/stripe_mock/request_handlers/recipients.rb +12 -0
  16. data/lib/stripe_mock/request_handlers/refunds.rb +88 -0
  17. data/lib/stripe_mock/request_handlers/subscriptions.rb +7 -6
  18. data/lib/stripe_mock/request_handlers/validators/param_validators.rb +5 -0
  19. data/lib/stripe_mock/test_strategies/base.rb +7 -4
  20. data/lib/stripe_mock/version.rb +1 -1
  21. data/lib/stripe_mock/webhook_fixtures/account.external_account.created.json +27 -0
  22. data/lib/stripe_mock/webhook_fixtures/account.external_account.deleted.json +27 -0
  23. data/lib/stripe_mock/webhook_fixtures/account.external_account.updated.json +27 -0
  24. data/spec/api/instance_spec.rb +30 -0
  25. data/spec/list_spec.rb +11 -7
  26. data/spec/server_spec.rb +1 -1
  27. data/spec/shared_stripe_examples/account_examples.rb +11 -0
  28. data/spec/shared_stripe_examples/card_examples.rb +13 -2
  29. data/spec/shared_stripe_examples/card_token_examples.rb +1 -0
  30. data/spec/shared_stripe_examples/charge_examples.rb +64 -15
  31. data/spec/shared_stripe_examples/country_specs_examples.rb +18 -0
  32. data/spec/shared_stripe_examples/customer_examples.rb +38 -0
  33. data/spec/shared_stripe_examples/error_mock_examples.rb +12 -2
  34. data/spec/shared_stripe_examples/plan_examples.rb +11 -0
  35. data/spec/shared_stripe_examples/recipient_examples.rb +7 -1
  36. data/spec/shared_stripe_examples/refund_examples.rb +447 -84
  37. data/spec/shared_stripe_examples/subscription_examples.rb +15 -0
  38. data/spec/support/stripe_examples.rb +1 -0
  39. metadata +12 -3
@@ -64,7 +64,10 @@ shared_examples 'Stripe Error Mocking' do
64
64
  custom_error = StandardError.new("Please knock first.")
65
65
  StripeMock.prepare_error(custom_error, :new_customer)
66
66
 
67
- expect { Stripe::Charge.create(amount: 1, currency: 'usd') }.to_not raise_error
67
+ expect {
68
+ Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token)
69
+ }.to_not raise_error
70
+
68
71
  expect { Stripe::Customer.create }.to raise_error {|e|
69
72
  expect(e).to be_a StandardError
70
73
  expect(e.message).to eq("Please knock first.")
@@ -89,7 +92,9 @@ shared_examples 'Stripe Error Mocking' do
89
92
 
90
93
  it "mocks a card error with a given handler" do
91
94
  StripeMock.prepare_card_error(:incorrect_cvc, :new_customer)
92
- expect { Stripe::Charge.create(amount: 1, currency: 'usd') }.to_not raise_error
95
+ expect {
96
+ Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token)
97
+ }.to_not raise_error
93
98
 
94
99
  expect { Stripe::Customer.create() }.to raise_error {|e|
95
100
  expect(e).to be_a(Stripe::CardError)
@@ -149,4 +154,9 @@ shared_examples 'Stripe Error Mocking' do
149
154
  expect_card_error 'processing_error', nil
150
155
  end
151
156
 
157
+ it "mocks an incorrect zip code card error" do
158
+ StripeMock.prepare_card_error(:incorrect_zip)
159
+ expect_card_error 'incorrect_zip', 'address_zip'
160
+ end
161
+
152
162
  end
@@ -118,6 +118,17 @@ shared_examples 'Plan API' do
118
118
  expect(all.count).to eq(100)
119
119
  end
120
120
 
121
+ it 'validates the amount' do
122
+ expect {
123
+ Stripe::Plan.create(
124
+ :id => 'pid_1',
125
+ :name => 'The Mock Plan',
126
+ :amount => 99.99,
127
+ :currency => 'USD',
128
+ :interval => 'month'
129
+ )
130
+ }.to raise_error(Stripe::InvalidRequestError, "Invalid integer: 99.99")
131
+ end
121
132
 
122
133
  describe "Validation", :live => true do
123
134
  let(:params) { stripe_helper.create_plan_params }
@@ -28,6 +28,13 @@ shared_examples 'Recipient API' do
28
28
  expect { recipient.card }.to raise_error
29
29
  end
30
30
 
31
+ it "raises a error if params are invalid" do
32
+ expect { Stripe::Recipient.create(name: "foo") }.to raise_error
33
+ expect { Stripe::Recipient.create(type: "individual") }.to raise_error
34
+ expect { Stripe::Recipient.create(name: "foo", type: "bar") }.to raise_error
35
+ expect { Stripe::Recipient.create(name: "foo", type: "individual") }.not_to raise_error
36
+ end
37
+
31
38
  it "creates a stripe recipient without a card" do
32
39
  recipient = Stripe::Recipient.create({
33
40
  type: "corporation",
@@ -109,4 +116,3 @@ shared_examples 'Recipient API' do
109
116
  end
110
117
 
111
118
  end
112
-
@@ -2,102 +2,465 @@ require 'spec_helper'
2
2
 
3
3
  shared_examples 'Refund API' do
4
4
 
5
- it "refunds a stripe charge item" do
6
- charge = Stripe::Charge.create(
7
- amount: 999,
8
- currency: 'USD',
9
- card: stripe_helper.generate_card_token,
10
- description: 'card charge'
11
- )
12
-
13
- charge = charge.refund(amount: 999)
14
-
15
- expect(charge.refunded).to eq(true)
16
- expect(charge.refunds.data.first.amount).to eq(999)
17
- expect(charge.amount_refunded).to eq(999)
18
- end
5
+ describe 'standard API' do
6
+ it "refunds a stripe charge item" do
7
+ charge = Stripe::Charge.create(
8
+ amount: 999,
9
+ currency: 'USD',
10
+ source: stripe_helper.generate_card_token,
11
+ description: 'card charge'
12
+ )
19
13
 
20
- it "creates a stripe refund with the charge ID", :live => true do
21
- charge = Stripe::Charge.create(
22
- amount: 999,
23
- currency: 'USD',
24
- card: stripe_helper.generate_card_token,
25
- description: 'card charge'
26
- )
27
- refund = charge.refund
28
-
29
- expect(charge.id).to match(/^(test_)?ch/)
30
- expect(refund.id).to eq(charge.id)
31
- end
14
+ Stripe::Refund.create(
15
+ charge: charge.id
16
+ )
32
17
 
33
- it "creates a stripe refund with a refund ID" do
34
- charge = Stripe::Charge.create(
35
- amount: 999,
36
- currency: 'USD',
37
- card: stripe_helper.generate_card_token,
38
- description: 'card charge'
39
- )
40
- refund = charge.refund
41
-
42
- expect(refund.refunds.data.count).to eq 1
43
- expect(refund.refunds.data.first.id).to match(/^test_re/)
44
- end
18
+ charge = Stripe::Charge.retrieve(charge.id)
45
19
 
46
- it "creates a stripe refund with a status" do
47
- charge = Stripe::Charge.create(
48
- amount: 999,
49
- currency: 'USD',
50
- card: stripe_helper.generate_card_token,
51
- description: 'card charge'
52
- )
53
- refund = charge.refund
54
-
55
- expect(refund.refunds.data.count).to eq 1
56
- expect(refund.refunds.data.first.status).to eq("succeeded")
57
- end
58
-
59
- it "creates a stripe refund with a different balance transaction than the charge" do
60
- charge = Stripe::Charge.create(
61
- amount: 999,
62
- currency: 'USD',
63
- card: stripe_helper.generate_card_token,
64
- description: 'card charge'
65
- )
66
- refund = charge.refund
67
-
68
- expect(charge.balance_transaction).not_to eq(refund.refunds.data.first.balance_transaction)
69
- end
20
+ expect(charge.refunded).to eq(true)
21
+ expect(charge.refunds.data.first.amount).to eq(999)
22
+ expect(charge.amount_refunded).to eq(999)
23
+ end
24
+
25
+ it "creates a stripe refund with a status" do
26
+ charge = Stripe::Charge.create(
27
+ amount: 999,
28
+ currency: 'USD',
29
+ source: stripe_helper.generate_card_token,
30
+ description: 'card charge'
31
+ )
32
+
33
+ Stripe::Refund.create(
34
+ charge: charge.id
35
+ )
36
+
37
+ charge = Stripe::Charge.retrieve(charge.id)
38
+
39
+ expect(charge.refunds.data.count).to eq 1
40
+ expect(charge.refunds.data.first.status).to eq("succeeded")
41
+ end
42
+
43
+ it "creates a stripe refund with a different balance transaction than the charge" do
44
+ charge = Stripe::Charge.create(
45
+ amount: 999,
46
+ currency: 'USD',
47
+ source: stripe_helper.generate_card_token,
48
+ description: 'card charge'
49
+ )
50
+
51
+ Stripe::Refund.create(
52
+ charge: charge.id
53
+ )
54
+
55
+ charge = Stripe::Charge.retrieve(charge.id)
56
+
57
+ expect(charge.balance_transaction).not_to eq(charge.refunds.data.first.balance_transaction)
58
+ end
59
+
60
+ it "creates a refund off a charge", :live => true do
61
+ original = Stripe::Charge.create(
62
+ amount: 555,
63
+ currency: 'USD',
64
+ source: stripe_helper.generate_card_token
65
+ )
66
+
67
+ charge = Stripe::Charge.retrieve(original.id)
68
+
69
+ refund = Stripe::Refund.create(
70
+ charge: charge.id,
71
+ amount: 555
72
+ )
73
+
74
+ expect(refund.amount).to eq 555
75
+ expect(refund.charge).to eq charge.id
76
+ end
77
+
78
+ it "handles multiple refunds", :live => true do
79
+ original = Stripe::Charge.create(
80
+ amount: 1100,
81
+ currency: 'USD',
82
+ source: stripe_helper.generate_card_token
83
+ )
84
+
85
+ charge = Stripe::Charge.retrieve(original.id)
86
+
87
+ refund_1 = Stripe::Refund.create(
88
+ charge: charge.id,
89
+ amount: 300
90
+ )
91
+ expect(refund_1.amount).to eq 300
92
+ expect(refund_1.charge).to eq charge.id
93
+
94
+ refund_2 = Stripe::Refund.create(
95
+ charge: charge.id,
96
+ amount: 400
97
+ )
98
+ expect(refund_2.amount).to eq 400
99
+ expect(refund_2.charge).to eq charge.id
100
+
101
+ expect(charge.refunds.count).to eq 0
102
+ expect(charge.refunds.total_count).to eq 0
103
+ expect(charge.amount_refunded).to eq 0
104
+
105
+ charge = Stripe::Charge.retrieve(original.id)
106
+ expect(charge.refunds.count).to eq 2
107
+ expect(charge.refunds.total_count).to eq 2
108
+ expect(charge.amount_refunded).to eq 700
109
+ end
110
+
111
+ it 'returns Stripe::Refund object', live: true do
112
+ charge = Stripe::Charge.create(
113
+ amount: 999,
114
+ currency: 'USD',
115
+ source: stripe_helper.generate_card_token,
116
+ description: 'card charge'
117
+ )
118
+ refund = Stripe::Refund.create(
119
+ charge: charge.id,
120
+ amount: 500
121
+ )
122
+
123
+ expect(refund).to be_a(Stripe::Refund)
124
+ expect(refund.amount).to eq(500)
125
+ end
126
+
127
+ it 'refunds entire charge if amount is not set', live: true do
128
+ charge = Stripe::Charge.create(
129
+ amount: 999,
130
+ currency: 'USD',
131
+ source: stripe_helper.generate_card_token,
132
+ description: 'card charge'
133
+ )
134
+ refund = Stripe::Refund.create(charge: charge.id)
135
+
136
+ expect(refund.amount).to eq(charge.amount)
137
+ end
138
+
139
+ it "stores a created stripe refund in memory" do
140
+ charge_1 = Stripe::Charge.create({
141
+ amount: 333,
142
+ currency: 'USD',
143
+ source: stripe_helper.generate_card_token
144
+ })
145
+ refund_1 = Stripe::Refund.create(
146
+ charge: charge_1.id,
147
+ )
148
+ charge_2 = Stripe::Charge.create({
149
+ amount: 777,
150
+ currency: 'USD',
151
+ source: stripe_helper.generate_card_token
152
+ })
153
+ refund_2 = Stripe::Refund.create(
154
+ charge: charge_2.id,
155
+ )
156
+
157
+ data = test_data_source(:refunds)
158
+ expect(data[refund_1.id]).to_not be_nil
159
+ expect(data[refund_1.id][:amount]).to eq(333)
160
+
161
+ expect(data[refund_2.id]).to_not be_nil
162
+ expect(data[refund_2.id][:amount]).to eq(777)
163
+ end
164
+
165
+ it "creates a balance transaction" do
166
+ charge = Stripe::Charge.create({
167
+ amount: 300,
168
+ currency: 'USD',
169
+ source: stripe_helper.generate_card_token
170
+ })
171
+ refund = Stripe::Refund.create(
172
+ charge: charge.id,
173
+ )
174
+ bal_trans = Stripe::BalanceTransaction.retrieve(refund.balance_transaction)
175
+ expect(bal_trans.amount).to eq(charge.amount * -1)
176
+ expect(bal_trans.fee).to eq(-39)
177
+ expect(bal_trans.source).to eq(refund.id)
178
+ end
179
+
180
+ it "can expand balance transaction" do
181
+ charge = Stripe::Charge.create({
182
+ amount: 300,
183
+ currency: 'USD',
184
+ source: stripe_helper.generate_card_token
185
+ })
186
+ refund = Stripe::Refund.create(
187
+ charge: charge.id,
188
+ expand: ['balance_transaction']
189
+ )
190
+ expect(refund.balance_transaction).to be_a(Stripe::BalanceTransaction)
191
+ end
192
+
193
+ it "retrieves a stripe refund" do
194
+ charge = Stripe::Charge.create({
195
+ amount: 777,
196
+ currency: 'USD',
197
+ source: stripe_helper.generate_card_token
198
+ })
199
+ original = Stripe::Refund.create(
200
+ charge: charge.id
201
+ )
202
+ refund = Stripe::Refund.retrieve(original.id)
203
+
204
+ expect(refund.id).to eq(original.id)
205
+ expect(refund.amount).to eq(original.amount)
206
+ end
207
+
208
+ it "cannot retrieve a refund that doesn't exist" do
209
+ expect { Stripe::Refund.retrieve('nope') }.to raise_error {|e|
210
+ expect(e).to be_a Stripe::InvalidRequestError
211
+ expect(e.param).to eq('refund')
212
+ expect(e.http_status).to eq(404)
213
+ }
214
+ end
215
+
216
+ it "updates a stripe charge" do
217
+ charge = Stripe::Charge.create({
218
+ amount: 777,
219
+ currency: 'USD',
220
+ source: stripe_helper.generate_card_token,
221
+ description: 'Original description',
222
+ })
223
+ original = Stripe::Refund.create(charge: charge.id)
224
+ refund = Stripe::Refund.retrieve(original.id)
70
225
 
71
- it "creates a refund off a charge", :live => true do
72
- original = Stripe::Charge.create(amount: 555, currency: 'USD', card: stripe_helper.generate_card_token)
226
+ refund.metadata[:order_id] = 6735
227
+ refund.save
73
228
 
74
- charge = Stripe::Charge.retrieve(original.id)
229
+ updated = Stripe::Refund.retrieve(original.id)
75
230
 
76
- refund = charge.refunds.create(amount: 555)
77
- expect(refund.amount).to eq 555
78
- expect(refund.charge).to eq charge.id
231
+ expect(updated.metadata.to_hash).to eq(refund.metadata.to_hash)
232
+ end
233
+
234
+ it "disallows most parameters on updating a stripe charge" do
235
+ charge = Stripe::Charge.create({
236
+ amount: 777,
237
+ currency: 'USD',
238
+ source: stripe_helper.generate_card_token,
239
+ description: 'Original description',
240
+ })
241
+ original = Stripe::Refund.create(charge: charge.id)
242
+
243
+ refund = Stripe::Refund.retrieve(original.id)
244
+ refund.reason = "customer changed is mind"
245
+ refund.amount = 777
246
+
247
+ expect { refund.save }.to raise_error(Stripe::InvalidRequestError) do |error|
248
+ expect(error.message).to match(/Received unknown parameters/)
249
+ expect(error.message).to match(/reason/)
250
+ expect(error.message).to match(/amount/)
251
+ end
252
+ end
253
+
254
+ context "retrieving a list of charges" do
255
+ before do
256
+ customer = Stripe::Customer.create(email: 'johnny@appleseed.com')
257
+ customer2 = Stripe::Customer.create(email: 'johnny2@appleseed.com')
258
+ charge = Stripe::Charge.create(amount: 15, currency: 'usd', customer: customer.id)
259
+ @refund = Stripe::Refund.create(charge: charge.id)
260
+ charge2 = Stripe::Charge.create(amount: 27, currency: 'usd', customer: customer2.id)
261
+ @refund2 = Stripe::Refund.create(charge: charge2.id)
262
+ end
263
+
264
+ it "stores all charges in memory" do
265
+ expect(Stripe::Refund.all.data.map(&:id)).to eq([@refund.id, @refund2.id])
266
+ end
267
+
268
+ it "defaults count to 10 charges" do
269
+ 11.times do
270
+ charge = Stripe::Charge.create(
271
+ amount: 1,
272
+ currency: 'usd',
273
+ source: stripe_helper.generate_card_token
274
+ )
275
+ Stripe::Refund.create(charge: charge.id)
276
+ end
277
+
278
+ expect(Stripe::Refund.all.data.count).to eq(10)
279
+ end
280
+
281
+ it "is marked as having more when more objects exist" do
282
+ 11.times do
283
+ charge = Stripe::Charge.create(
284
+ amount: 1,
285
+ currency: 'usd',
286
+ source: stripe_helper.generate_card_token
287
+ )
288
+ Stripe::Refund.create(charge: charge.id)
289
+ end
290
+
291
+ expect(Stripe::Refund.all.has_more).to eq(true)
292
+ end
293
+
294
+ context "when passing limit" do
295
+ it "gets that many charges" do
296
+ expect(Stripe::Refund.all(limit: 1).count).to eq(1)
297
+ end
298
+ end
299
+ end
300
+
301
+ it 'when use starting_after param', live: true do
302
+ customer = Stripe::Customer.create(
303
+ description: 'Customer for test@example.com',
304
+ source: {
305
+ object: 'card',
306
+ number: '4242424242424242',
307
+ exp_month: 12,
308
+ exp_year: 2024,
309
+ cvc: 123
310
+ }
311
+ )
312
+ 12.times do
313
+ charge = Stripe::Charge.create(
314
+ customer: customer.id,
315
+ amount: 100,
316
+ currency: 'usd'
317
+ )
318
+ Stripe::Refund.create(charge: charge.id)
319
+ end
320
+
321
+ all = Stripe::Refund.all
322
+ default_limit = 10
323
+ half = Stripe::Refund.all(starting_after: all.data.at(1).id)
324
+
325
+ expect(half).to be_a(Stripe::ListObject)
326
+ expect(half.data.count).to eq(default_limit)
327
+ expect(half.data.first.id).to eq(all.data.at(2).id)
328
+ end
329
+
330
+ describe "idempotency" do
331
+ let(:customer) { Stripe::Customer.create(email: 'johnny@appleseed.com') }
332
+ let(:charge) do
333
+ Stripe::Charge.create(
334
+ customer: customer.id,
335
+ amount: 777,
336
+ currency: 'USD',
337
+ capture: true
338
+ )
339
+ end
340
+ let(:idempotent_refund_params) {{
341
+ charge: charge.id,
342
+ idempotency_key: 'onceisenough'
343
+ }}
344
+
345
+ it "returns the original refund if the same idempotency_key is passed in" do
346
+ refund1 = Stripe::Refund.create(idempotent_refund_params)
347
+ refund2 = Stripe::Refund.create(idempotent_refund_params)
348
+
349
+ expect(refund1).to eq(refund2)
350
+ end
351
+
352
+ it "returns different charges if different idempotency_keys are used for each charge" do
353
+ idempotent_refund_params2 = idempotent_refund_params.clone
354
+ idempotent_refund_params2[:idempotency_key] = 'thisoneisdifferent'
355
+
356
+ refund1 = Stripe::Refund.create(idempotent_refund_params)
357
+ refund2 = Stripe::Refund.create(idempotent_refund_params2)
358
+
359
+ expect(refund1).not_to eq(refund2)
360
+ end
361
+ end
79
362
  end
80
363
 
81
- it "handles multiple refunds", :live => true do
82
- original = Stripe::Charge.create(amount: 1100, currency: 'USD', card: stripe_helper.generate_card_token)
83
364
 
84
- charge = Stripe::Charge.retrieve(original.id)
365
+ describe 'charge refund API' do
366
+
367
+ it "refunds a stripe charge item" do
368
+ charge = Stripe::Charge.create(
369
+ amount: 999,
370
+ currency: 'USD',
371
+ source: stripe_helper.generate_card_token,
372
+ description: 'card charge'
373
+ )
374
+
375
+ charge = charge.refund(amount: 999)
376
+
377
+ expect(charge.refunded).to eq(true)
378
+ expect(charge.refunds.data.first.amount).to eq(999)
379
+ expect(charge.amount_refunded).to eq(999)
380
+ end
381
+
382
+ it "creates a stripe refund with the charge ID", :live => true do
383
+ charge = Stripe::Charge.create(
384
+ amount: 999,
385
+ currency: 'USD',
386
+ source: stripe_helper.generate_card_token,
387
+ description: 'card charge'
388
+ )
389
+ refund = charge.refund
390
+
391
+ expect(charge.id).to match(/^(test_)?ch/)
392
+ expect(refund.id).to eq(charge.id)
393
+ end
394
+
395
+ it "creates a stripe refund with a refund ID" do
396
+ charge = Stripe::Charge.create(
397
+ amount: 999,
398
+ currency: 'USD',
399
+ source: stripe_helper.generate_card_token,
400
+ description: 'card charge'
401
+ )
402
+ refund = charge.refund
403
+
404
+ expect(refund.refunds.data.count).to eq 1
405
+ expect(refund.refunds.data.first.id).to match(/^test_re/)
406
+ end
407
+
408
+ it "creates a stripe refund with a status" do
409
+ charge = Stripe::Charge.create(
410
+ amount: 999,
411
+ currency: 'USD',
412
+ source: stripe_helper.generate_card_token,
413
+ description: 'card charge'
414
+ )
415
+ refund = charge.refund
416
+
417
+ expect(refund.refunds.data.count).to eq 1
418
+ expect(refund.refunds.data.first.status).to eq("succeeded")
419
+ end
420
+
421
+ it "creates a stripe refund with a different balance transaction than the charge" do
422
+ charge = Stripe::Charge.create(
423
+ amount: 999,
424
+ currency: 'USD',
425
+ source: stripe_helper.generate_card_token,
426
+ description: 'card charge'
427
+ )
428
+ refund = charge.refund
429
+
430
+ expect(charge.balance_transaction).not_to eq(refund.refunds.data.first.balance_transaction)
431
+ end
432
+
433
+ it "creates a refund off a charge", :live => true do
434
+ original = Stripe::Charge.create(amount: 555, currency: 'USD', source: stripe_helper.generate_card_token)
435
+
436
+ charge = Stripe::Charge.retrieve(original.id)
437
+
438
+ refund = charge.refunds.create(amount: 555)
439
+ expect(refund.amount).to eq 555
440
+ expect(refund.charge).to eq charge.id
441
+ end
442
+
443
+ it "handles multiple refunds", :live => true do
444
+ original = Stripe::Charge.create(amount: 1100, currency: 'USD', source: stripe_helper.generate_card_token)
445
+
446
+ charge = Stripe::Charge.retrieve(original.id)
85
447
 
86
- refund_1 = charge.refunds.create(amount: 300)
87
- expect(refund_1.amount).to eq 300
88
- expect(refund_1.charge).to eq charge.id
448
+ refund_1 = charge.refunds.create(amount: 300)
449
+ expect(refund_1.amount).to eq 300
450
+ expect(refund_1.charge).to eq charge.id
89
451
 
90
- refund_2 = charge.refunds.create(amount: 400)
91
- expect(refund_2.amount).to eq 400
92
- expect(refund_2.charge).to eq charge.id
452
+ refund_2 = charge.refunds.create(amount: 400)
453
+ expect(refund_2.amount).to eq 400
454
+ expect(refund_2.charge).to eq charge.id
93
455
 
94
- expect(charge.refunds.count).to eq 0
95
- expect(charge.refunds.total_count).to eq 0
96
- expect(charge.amount_refunded).to eq 0
456
+ expect(charge.refunds.count).to eq 0
457
+ expect(charge.refunds.total_count).to eq 0
458
+ expect(charge.amount_refunded).to eq 0
97
459
 
98
- charge = Stripe::Charge.retrieve(original.id)
99
- expect(charge.refunds.count).to eq 2
100
- expect(charge.refunds.total_count).to eq 2
101
- expect(charge.amount_refunded).to eq 700
460
+ charge = Stripe::Charge.retrieve(original.id)
461
+ expect(charge.refunds.count).to eq 2
462
+ expect(charge.refunds.total_count).to eq 2
463
+ expect(charge.amount_refunded).to eq 700
464
+ end
102
465
  end
103
466
  end