stripe-ruby-mock 2.3.0 → 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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Gemfile +5 -0
- data/README.md +1 -1
- data/lib/stripe_mock/api/errors.rb +2 -1
- data/lib/stripe_mock/api/instance.rb +10 -0
- data/lib/stripe_mock/api/webhooks.rb +3 -0
- data/lib/stripe_mock/data.rb +203 -21
- data/lib/stripe_mock/instance.rb +14 -3
- data/lib/stripe_mock/request_handlers/accounts.rb +7 -0
- data/lib/stripe_mock/request_handlers/charges.rb +29 -21
- data/lib/stripe_mock/request_handlers/country_spec.rb +22 -0
- data/lib/stripe_mock/request_handlers/customers.rb +3 -3
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +5 -2
- data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +2 -1
- data/lib/stripe_mock/request_handlers/recipients.rb +12 -0
- data/lib/stripe_mock/request_handlers/refunds.rb +88 -0
- data/lib/stripe_mock/request_handlers/subscriptions.rb +48 -23
- data/lib/stripe_mock/request_handlers/validators/param_validators.rb +5 -0
- data/lib/stripe_mock/test_strategies/base.rb +7 -4
- data/lib/stripe_mock/version.rb +1 -1
- data/lib/stripe_mock/webhook_fixtures/account.external_account.created.json +27 -0
- data/lib/stripe_mock/webhook_fixtures/account.external_account.deleted.json +27 -0
- data/lib/stripe_mock/webhook_fixtures/account.external_account.updated.json +27 -0
- data/lib/stripe_mock.rb +2 -0
- data/spec/api/instance_spec.rb +30 -0
- data/spec/list_spec.rb +11 -7
- data/spec/server_spec.rb +1 -1
- data/spec/shared_stripe_examples/account_examples.rb +11 -0
- data/spec/shared_stripe_examples/card_examples.rb +13 -2
- data/spec/shared_stripe_examples/card_token_examples.rb +1 -0
- data/spec/shared_stripe_examples/charge_examples.rb +90 -14
- data/spec/shared_stripe_examples/country_specs_examples.rb +18 -0
- data/spec/shared_stripe_examples/customer_examples.rb +38 -0
- data/spec/shared_stripe_examples/error_mock_examples.rb +12 -2
- data/spec/shared_stripe_examples/plan_examples.rb +19 -0
- data/spec/shared_stripe_examples/recipient_examples.rb +7 -1
- data/spec/shared_stripe_examples/refund_examples.rb +447 -84
- data/spec/shared_stripe_examples/subscription_examples.rb +28 -0
- data/spec/support/stripe_examples.rb +1 -0
- data/stripe-ruby-mock.gemspec +3 -3
- metadata +24 -21
@@ -2,102 +2,465 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
shared_examples 'Refund API' do
|
4
4
|
|
5
|
-
|
6
|
-
charge
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
72
|
-
|
226
|
+
refund.metadata[:order_id] = 6735
|
227
|
+
refund.save
|
73
228
|
|
74
|
-
|
229
|
+
updated = Stripe::Refund.retrieve(original.id)
|
75
230
|
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
-
|
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
|
-
|
87
|
-
|
88
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
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
|
-
|
95
|
-
|
96
|
-
|
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
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
@@ -203,6 +203,7 @@ shared_examples 'Customer Subscriptions' do
|
|
203
203
|
expect(customer.subscriptions.data.first.id).to eq(sub.id)
|
204
204
|
expect(customer.subscriptions.data.first.plan.to_hash).to eq(plan.to_hash)
|
205
205
|
expect(customer.subscriptions.data.first.customer).to eq(customer.id)
|
206
|
+
expect(customer.charges.count).to eq(0)
|
206
207
|
end
|
207
208
|
|
208
209
|
it "subscribes a customer with no card to a free plan" do
|
@@ -288,6 +289,19 @@ shared_examples 'Customer Subscriptions' do
|
|
288
289
|
end
|
289
290
|
|
290
291
|
context "updating a subscription" do
|
292
|
+
it 'raises invalid request exception when subscription is cancelled' do
|
293
|
+
stripe_helper.create_plan(id: 'the truth')
|
294
|
+
customer = Stripe::Customer.create(source: gen_card_tk, plan: 'the truth')
|
295
|
+
|
296
|
+
subscription = Stripe::Subscription.retrieve(customer.subscriptions.data.first.id)
|
297
|
+
subscription.delete
|
298
|
+
|
299
|
+
expect { subscription.save }.to raise_error { |e|
|
300
|
+
expect(e).to be_a(Stripe::InvalidRequestError)
|
301
|
+
expect(e.http_status).to eq(404)
|
302
|
+
expect(e.message).to eq("No such subscription: #{subscription.id}")
|
303
|
+
}
|
304
|
+
end
|
291
305
|
|
292
306
|
it "updates a stripe customer's existing subscription" do
|
293
307
|
silver = stripe_helper.create_plan(id: 'silver')
|
@@ -347,6 +361,20 @@ shared_examples 'Customer Subscriptions' do
|
|
347
361
|
|
348
362
|
end
|
349
363
|
|
364
|
+
it 'when coupon is removed' do
|
365
|
+
plan = stripe_helper.create_plan(id: 'plan_with_coupon3', name: 'One More Test Plan', amount: 777)
|
366
|
+
customer = Stripe::Customer.create(source: gen_card_tk, plan: plan.id)
|
367
|
+
coupon = stripe_helper.create_coupon
|
368
|
+
subscription = Stripe::Subscription.retrieve(customer.subscriptions.data.first.id)
|
369
|
+
|
370
|
+
subscription.coupon = coupon.id
|
371
|
+
subscription.save
|
372
|
+
subscription.coupon = nil
|
373
|
+
subscription.save
|
374
|
+
|
375
|
+
expect(subscription.discount).to be_nil
|
376
|
+
end
|
377
|
+
|
350
378
|
it "throws an error when plan does not exist" do
|
351
379
|
free = stripe_helper.create_plan(id: 'free', amount: 0)
|
352
380
|
customer = Stripe::Customer.create(id: 'cardless', plan: 'free')
|
@@ -25,6 +25,7 @@ def it_behaves_like_stripe(&block)
|
|
25
25
|
it_behaves_like 'Stripe Error Mocking', &block
|
26
26
|
it_behaves_like 'Customer Subscriptions', &block
|
27
27
|
it_behaves_like 'Webhook Events API', &block
|
28
|
+
it_behaves_like 'Country Spec API', &block
|
28
29
|
|
29
30
|
# Integration tests
|
30
31
|
it_behaves_like 'Multiple Customer Cards'
|
data/stripe-ruby-mock.gemspec
CHANGED
@@ -17,11 +17,11 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ['lib']
|
19
19
|
|
20
|
-
gem.add_dependency 'stripe',
|
21
|
-
gem.add_dependency 'multi_json', '
|
20
|
+
gem.add_dependency 'stripe', '~> 1.31'
|
21
|
+
gem.add_dependency 'multi_json', '~> 1.0'
|
22
22
|
gem.add_dependency 'dante', '>= 0.2.0'
|
23
23
|
|
24
24
|
gem.add_development_dependency 'rspec', '~> 3.1.0'
|
25
25
|
gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
|
26
|
-
gem.add_development_dependency 'thin'
|
26
|
+
gem.add_development_dependency 'thin', '~> 1.6.4'
|
27
27
|
end
|