stripe-ruby-mock 2.5.6 → 3.1.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -1
  3. data/.travis.yml +6 -9
  4. data/CHANGELOG.md +35 -0
  5. data/Gemfile +1 -0
  6. data/README.md +17 -11
  7. data/lib/stripe_mock.rb +11 -0
  8. data/lib/stripe_mock/api/client.rb +1 -1
  9. data/lib/stripe_mock/api/errors.rb +34 -28
  10. data/lib/stripe_mock/api/instance.rb +1 -1
  11. data/lib/stripe_mock/api/webhooks.rb +7 -0
  12. data/lib/stripe_mock/client.rb +2 -1
  13. data/lib/stripe_mock/data.rb +323 -13
  14. data/lib/stripe_mock/data/list.rb +42 -9
  15. data/lib/stripe_mock/instance.rb +52 -5
  16. data/lib/stripe_mock/request_handlers/account_links.rb +15 -0
  17. data/lib/stripe_mock/request_handlers/balance_transactions.rb +2 -2
  18. data/lib/stripe_mock/request_handlers/charges.rb +13 -12
  19. data/lib/stripe_mock/request_handlers/checkout.rb +15 -0
  20. data/lib/stripe_mock/request_handlers/checkout_session.rb +16 -0
  21. data/lib/stripe_mock/request_handlers/customers.rb +35 -18
  22. data/lib/stripe_mock/request_handlers/ephemeral_key.rb +1 -1
  23. data/lib/stripe_mock/request_handlers/express_login_links.rb +15 -0
  24. data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +14 -10
  25. data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +22 -7
  26. data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +1 -1
  27. data/lib/stripe_mock/request_handlers/invoices.rb +11 -5
  28. data/lib/stripe_mock/request_handlers/payment_intents.rb +182 -0
  29. data/lib/stripe_mock/request_handlers/payment_methods.rb +120 -0
  30. data/lib/stripe_mock/request_handlers/plans.rb +1 -1
  31. data/lib/stripe_mock/request_handlers/prices.rb +44 -0
  32. data/lib/stripe_mock/request_handlers/products.rb +44 -0
  33. data/lib/stripe_mock/request_handlers/refunds.rb +6 -3
  34. data/lib/stripe_mock/request_handlers/setup_intents.rb +93 -0
  35. data/lib/stripe_mock/request_handlers/sources.rb +12 -6
  36. data/lib/stripe_mock/request_handlers/subscription_items.rb +36 -0
  37. data/lib/stripe_mock/request_handlers/subscriptions.rb +82 -41
  38. data/lib/stripe_mock/request_handlers/tax_rates.rb +36 -0
  39. data/lib/stripe_mock/request_handlers/tokens.rb +8 -6
  40. data/lib/stripe_mock/request_handlers/validators/param_validators.rb +130 -9
  41. data/lib/stripe_mock/test_strategies/base.rb +68 -8
  42. data/lib/stripe_mock/test_strategies/live.rb +23 -12
  43. data/lib/stripe_mock/test_strategies/mock.rb +6 -2
  44. data/lib/stripe_mock/version.rb +1 -1
  45. data/lib/stripe_mock/webhook_fixtures/balance.available.json +6 -0
  46. data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_reinstated.json +88 -0
  47. data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_withdrawn.json +88 -0
  48. data/lib/stripe_mock/webhook_fixtures/charge.failed.json +166 -38
  49. data/lib/stripe_mock/webhook_fixtures/customer.created.json +1 -0
  50. data/lib/stripe_mock/webhook_fixtures/customer.updated.json +1 -0
  51. data/lib/stripe_mock/webhook_fixtures/invoice.created.json +2 -1
  52. data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +1 -1
  53. data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +2 -1
  54. data/lib/stripe_mock/webhook_fixtures/payment_intent.payment_failed.json +186 -0
  55. data/lib/stripe_mock/webhook_fixtures/payment_intent.succeeded.json +164 -0
  56. data/lib/stripe_mock/webhook_fixtures/product.created.json +34 -0
  57. data/lib/stripe_mock/webhook_fixtures/product.deleted.json +34 -0
  58. data/lib/stripe_mock/webhook_fixtures/product.updated.json +38 -0
  59. data/spec/instance_spec.rb +10 -12
  60. data/spec/list_spec.rb +38 -0
  61. data/spec/server_spec.rb +6 -3
  62. data/spec/shared_stripe_examples/account_examples.rb +1 -1
  63. data/spec/shared_stripe_examples/account_link_examples.rb +16 -0
  64. data/spec/shared_stripe_examples/balance_examples.rb +6 -0
  65. data/spec/shared_stripe_examples/balance_transaction_examples.rb +3 -3
  66. data/spec/shared_stripe_examples/bank_examples.rb +3 -3
  67. data/spec/shared_stripe_examples/card_examples.rb +4 -4
  68. data/spec/shared_stripe_examples/card_token_examples.rb +17 -21
  69. data/spec/shared_stripe_examples/charge_examples.rb +32 -36
  70. data/spec/shared_stripe_examples/checkout_examples.rb +38 -0
  71. data/spec/shared_stripe_examples/coupon_examples.rb +1 -1
  72. data/spec/shared_stripe_examples/customer_examples.rb +103 -53
  73. data/spec/shared_stripe_examples/dispute_examples.rb +2 -2
  74. data/spec/shared_stripe_examples/error_mock_examples.rb +8 -7
  75. data/spec/shared_stripe_examples/express_login_link_examples.rb +12 -0
  76. data/spec/shared_stripe_examples/external_account_examples.rb +3 -3
  77. data/spec/shared_stripe_examples/invoice_examples.rb +43 -41
  78. data/spec/shared_stripe_examples/invoice_item_examples.rb +1 -1
  79. data/spec/shared_stripe_examples/payment_intent_examples.rb +147 -0
  80. data/spec/shared_stripe_examples/payment_method_examples.rb +449 -0
  81. data/spec/shared_stripe_examples/payout_examples.rb +2 -2
  82. data/spec/shared_stripe_examples/plan_examples.rb +135 -77
  83. data/spec/shared_stripe_examples/price_examples.rb +183 -0
  84. data/spec/shared_stripe_examples/product_examples.rb +155 -0
  85. data/spec/shared_stripe_examples/refund_examples.rb +41 -31
  86. data/spec/shared_stripe_examples/setup_intent_examples.rb +68 -0
  87. data/spec/shared_stripe_examples/subscription_examples.rb +546 -295
  88. data/spec/shared_stripe_examples/subscription_items_examples.rb +76 -0
  89. data/spec/shared_stripe_examples/tax_rate_examples.rb +42 -0
  90. data/spec/shared_stripe_examples/transfer_examples.rb +9 -9
  91. data/spec/shared_stripe_examples/webhook_event_examples.rb +11 -11
  92. data/spec/spec_helper.rb +7 -4
  93. data/spec/stripe_mock_spec.rb +4 -4
  94. data/spec/support/shared_contexts/stripe_validator_spec.rb +8 -0
  95. data/spec/support/stripe_examples.rb +12 -2
  96. data/stripe-ruby-mock.gemspec +8 -3
  97. metadata +81 -32
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples 'Checkout API' do
4
+
5
+ it "creates a stripe checkout session" do
6
+ session = Stripe::Checkout::Session.create({
7
+ payment_method_types: ['card'],
8
+ line_items: [{
9
+ name: 'T-shirt',
10
+ quantity: 1,
11
+ amount: 500,
12
+ currency: 'usd',
13
+ }],
14
+ })
15
+ expect(session.id).to match(/^test_cs/)
16
+ expect(session.line_items.count).to eq(1)
17
+ end
18
+
19
+ context 'retrieve a checkout session' do
20
+ let(:checkout_session1) { stripe_helper.create_checkout_session }
21
+
22
+ it 'ca be retrieved by id' do
23
+ checkout_session1
24
+
25
+ checkout_session = Stripe::Checkout::Session.retrieve(checkout_session1.id)
26
+
27
+ expect(checkout_session.id).to eq(checkout_session1.id)
28
+ end
29
+
30
+ it "cannot retrieve a checkout session that doesn't exist" do
31
+ expect { Stripe::Checkout::Session.retrieve('nope') }.to raise_error {|e|
32
+ expect(e).to be_a Stripe::InvalidRequestError
33
+ expect(e.param).to eq('checkout_session')
34
+ expect(e.http_status).to eq(404)
35
+ }
36
+ end
37
+ end
38
+ end
@@ -53,7 +53,7 @@ shared_examples 'Coupon API' do
53
53
  coupon1
54
54
  coupon2
55
55
 
56
- all = Stripe::Coupon.all
56
+ all = Stripe::Coupon.list
57
57
 
58
58
  expect(all.count).to eq(2)
59
59
  expect(all.map &:id).to include('10BUCKS', '11BUCKS')
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  shared_examples 'Customer API' do
4
+ let(:product_params) { {id: "prod_CCC", name: "My Product", type: "service"} }
5
+ let(:product) { stripe_helper.create_product(product_params) }
4
6
 
5
7
  def gen_card_tk
6
8
  stripe_helper.generate_card_token
@@ -15,6 +17,7 @@ shared_examples 'Customer API' do
15
17
  expect(customer.id).to match(/^test_cus/)
16
18
  expect(customer.email).to eq('johnny@appleseed.com')
17
19
  expect(customer.description).to eq('a description')
20
+ expect(customer.preferred_locales).to eq([])
18
21
 
19
22
  expect(customer.sources.count).to eq(1)
20
23
  expect(customer.sources.data.length).to eq(1)
@@ -24,6 +27,17 @@ shared_examples 'Customer API' do
24
27
  expect { customer.source }.to raise_error
25
28
  end
26
29
 
30
+ it "creates a stripe customer with a default payment method" do
31
+ customer = Stripe::Customer.create({
32
+ email: 'johnny@appleseed.com',
33
+ invoice_settings: {
34
+ default_payment_method: "pm_1ExEuFL2DI6wht39WNJgbybl"
35
+ },
36
+ description: "a description"
37
+ })
38
+ expect(customer.invoice_settings.default_payment_method).to eq("pm_1ExEuFL2DI6wht39WNJgbybl")
39
+ end
40
+
27
41
  it "creates a stripe customer with multiple cards and updates the default card" do
28
42
  card_a = gen_card_tk
29
43
  card_b = gen_card_tk
@@ -78,8 +92,17 @@ shared_examples 'Customer API' do
78
92
  expect(customer.sources.data.first.exp_year).to eq 2024
79
93
  end
80
94
 
95
+ it 'creates a customer with name' do
96
+ customer = Stripe::Customer.create(
97
+ source: gen_card_tk,
98
+ name: 'John Appleseed'
99
+ )
100
+ expect(customer.id).to match(/^test_cus/)
101
+ expect(customer.name).to eq('John Appleseed')
102
+ end
103
+
81
104
  it 'creates a customer with a plan' do
82
- plan = stripe_helper.create_plan(id: 'silver')
105
+ plan = stripe_helper.create_plan(id: 'silver', product: product.id)
83
106
  customer = Stripe::Customer.create(id: 'test_cus_plan', source: gen_card_tk, :plan => 'silver')
84
107
 
85
108
  customer = Stripe::Customer.retrieve('test_cus_plan')
@@ -91,24 +114,29 @@ shared_examples 'Customer API' do
91
114
  expect(customer.subscriptions.first.customer).to eq(customer.id)
92
115
  end
93
116
 
94
- it "creates a customer with a plan (string/symbol agnostic)" do
95
- plan = stripe_helper.create_plan(id: 'string_id')
96
- customer = Stripe::Customer.create(id: 'test_cus_plan', source: gen_card_tk, :plan => :string_id)
97
-
98
- customer = Stripe::Customer.retrieve('test_cus_plan')
99
- expect(customer.subscriptions.first.plan.id).to eq('string_id')
117
+ it 'creates a customer with a plan (string/symbol agnostic)' do
118
+ stripe_helper.create_plan(id: 'silver', product: product.id)
100
119
 
101
- plan = stripe_helper.create_plan(:id => :sym_id)
102
- customer = Stripe::Customer.create(id: 'test_cus_plan', source: gen_card_tk, :plan => 'sym_id')
120
+ Stripe::Customer.create(id: 'cust_SLV1', source: gen_card_tk, :plan => 'silver')
121
+ customer = Stripe::Customer.retrieve('cust_SLV1')
122
+ expect(customer.subscriptions.count).to eq(1)
123
+ expect(customer.subscriptions.data.length).to eq(1)
124
+ expect(customer.subscriptions).to_not be_nil
125
+ expect(customer.subscriptions.first.plan.id).to eq('silver')
126
+ expect(customer.subscriptions.first.customer).to eq(customer.id)
103
127
 
104
- customer = Stripe::Customer.retrieve('test_cus_plan')
105
- expect(customer.subscriptions.first.plan.id).to eq('sym_id')
128
+ Stripe::Customer.create(id: 'cust_SLV2', source: gen_card_tk, :plan => :silver)
129
+ customer = Stripe::Customer.retrieve('cust_SLV2')
130
+ expect(customer.subscriptions.count).to eq(1)
131
+ expect(customer.subscriptions.data.length).to eq(1)
132
+ expect(customer.subscriptions).to_not be_nil
133
+ expect(customer.subscriptions.first.plan.id).to eq('silver')
134
+ expect(customer.subscriptions.first.customer).to eq(customer.id)
106
135
  end
107
136
 
108
137
  context "create customer" do
109
-
110
138
  it "with a trial when trial_end is set" do
111
- plan = stripe_helper.create_plan(id: 'no_trial', amount: 999)
139
+ plan = stripe_helper.create_plan(id: 'no_trial', product: product.id, amount: 999)
112
140
  trial_end = Time.now.utc.to_i + 3600
113
141
  customer = Stripe::Customer.create(id: 'test_cus_trial_end', source: gen_card_tk, plan: 'no_trial', trial_end: trial_end)
114
142
 
@@ -124,7 +152,7 @@ shared_examples 'Customer API' do
124
152
  end
125
153
 
126
154
  it 'overrides trial period length when trial_end is set' do
127
- plan = stripe_helper.create_plan(id: 'silver', amount: 999, trial_period_days: 14)
155
+ plan = stripe_helper.create_plan(id: 'silver', product: product.id, amount: 999, trial_period_days: 14)
128
156
  trial_end = Time.now.utc.to_i + 3600
129
157
  customer = Stripe::Customer.create(id: 'test_cus_trial_end', source: gen_card_tk, plan: 'silver', trial_end: trial_end)
130
158
 
@@ -139,7 +167,7 @@ shared_examples 'Customer API' do
139
167
  end
140
168
 
141
169
  it 'creates a customer when trial_end is set and no source', live: true do
142
- plan = stripe_helper.create_plan(id: 'silver', amount: 999)
170
+ plan = stripe_helper.create_plan(id: 'silver', product: product.id, amount: 999)
143
171
  trial_end = Time.now.utc.to_i + 3600
144
172
  customer = Stripe::Customer.create(plan: 'silver', trial_end: trial_end)
145
173
  expect(customer.subscriptions.count).to eq(1)
@@ -152,7 +180,7 @@ shared_examples 'Customer API' do
152
180
  end
153
181
 
154
182
  it "returns no trial when trial_end is set to 'now'" do
155
- plan = stripe_helper.create_plan(id: 'silver', amount: 999, trial_period_days: 14)
183
+ plan = stripe_helper.create_plan(id: 'silver', product: product.id, amount: 999, trial_period_days: 14)
156
184
  customer = Stripe::Customer.create(id: 'test_cus_trial_end', source: gen_card_tk, plan: 'silver', trial_end: "now")
157
185
 
158
186
  customer = Stripe::Customer.retrieve('test_cus_trial_end')
@@ -166,8 +194,8 @@ shared_examples 'Customer API' do
166
194
  expect(customer.subscriptions.first.trial_end).to be_nil
167
195
  end
168
196
 
169
- it "returns an error if trial_end is set to a past time" do
170
- plan = stripe_helper.create_plan(id: 'silver', amount: 999)
197
+ it 'returns an error if trial_end is set to a past time' do
198
+ plan = stripe_helper.create_plan(id: 'silver', product: product.id, amount: 999)
171
199
  expect {
172
200
  Stripe::Customer.create(id: 'test_cus_trial_end', source: gen_card_tk, plan: 'silver', trial_end: Time.now.utc.to_i - 3600)
173
201
  }.to raise_error {|e|
@@ -176,7 +204,7 @@ shared_examples 'Customer API' do
176
204
  }
177
205
  end
178
206
 
179
- it "returns an error if trial_end is set without a plan" do
207
+ it 'returns an error if trial_end is set without a plan' do
180
208
  expect {
181
209
  Stripe::Customer.create(id: 'test_cus_trial_end', source: gen_card_tk, trial_end: "now")
182
210
  }.to raise_error {|e|
@@ -189,7 +217,7 @@ shared_examples 'Customer API' do
189
217
 
190
218
  it 'cannot create a customer with a plan that does not exist' do
191
219
  expect {
192
- customer = Stripe::Customer.create(id: 'test_cus_no_plan', source: gen_card_tk, :plan => 'non-existant')
220
+ Stripe::Customer.create(id: 'test_cus_no_plan', source: gen_card_tk, :plan => 'non-existant')
193
221
  }.to raise_error {|e|
194
222
  expect(e).to be_a(Stripe::InvalidRequestError)
195
223
  expect(e.message).to eq('No such plan: non-existant')
@@ -197,9 +225,9 @@ shared_examples 'Customer API' do
197
225
  end
198
226
 
199
227
  it 'cannot create a customer with an existing plan, but no card token' do
200
- plan = stripe_helper.create_plan(id: 'p')
228
+ plan = stripe_helper.create_plan(id: 'p', product: product.id)
201
229
  expect {
202
- customer = Stripe::Customer.create(id: 'test_cus_no_plan', :plan => 'p')
230
+ Stripe::Customer.create(id: 'test_cus_no_plan', :plan => 'p')
203
231
  }.to raise_error {|e|
204
232
  expect(e).to be_a(Stripe::InvalidRequestError)
205
233
  expect(e.message).to eq('You must supply a valid card')
@@ -207,10 +235,9 @@ shared_examples 'Customer API' do
207
235
  end
208
236
 
209
237
  it 'creates a customer with a coupon discount' do
210
- coupon = Stripe::Coupon.create(id: "10PERCENT", duration: 'once')
238
+ coupon = Stripe::Coupon.create(id: '10PERCENT', duration: 'once')
211
239
 
212
- customer =
213
- Stripe::Customer.create(id: 'test_cus_coupon', coupon: '10PERCENT')
240
+ Stripe::Customer.create(id: 'test_cus_coupon', coupon: '10PERCENT')
214
241
 
215
242
  customer = Stripe::Customer.retrieve('test_cus_coupon')
216
243
  expect(customer.discount).to_not be_nil
@@ -222,40 +249,59 @@ shared_examples 'Customer API' do
222
249
  describe 'repeating coupon with duration limit', live: true do
223
250
  let!(:coupon) { stripe_helper.create_coupon(id: '10OFF', amount_off: 1000, currency: 'usd', duration: 'repeating', duration_in_months: 12) }
224
251
  let!(:customer) { Stripe::Customer.create(coupon: coupon.id) }
252
+
225
253
  it 'creates the discount with the end date', live: true do
226
254
  discount = Stripe::Customer.retrieve(customer.id).discount
227
255
  expect(discount).to_not be_nil
228
256
  expect(discount.coupon).to_not be_nil
229
- expect(discount.end).to be_within(1).of (Time.now + 365 * 24 * 3600).to_i
257
+ expect(discount.end).to be_within(10).of (DateTime.now >> 12).to_time.to_i
230
258
  end
259
+
231
260
  after { Stripe::Coupon.retrieve(coupon.id).delete }
232
261
  after { Stripe::Customer.retrieve(customer.id).delete }
233
262
  end
234
263
 
235
264
  it 'cannot create a customer with a coupon that does not exist' do
236
265
  expect{
237
- customer = Stripe::Customer.create(id: 'test_cus_no_coupon', coupon: '5OFF')
266
+ Stripe::Customer.create(id: 'test_cus_no_coupon', coupon: '5OFF')
238
267
  }.to raise_error {|e|
239
268
  expect(e).to be_a(Stripe::InvalidRequestError)
240
269
  expect(e.message).to eq('No such coupon: 5OFF')
241
270
  }
242
271
  end
243
272
 
273
+ context 'with coupon on customer' do
274
+ before do
275
+ Stripe::Coupon.create(id: '10PERCENT', duration: 'once')
276
+ Stripe::Customer.create(id: 'test_cus_coupon', coupon: '10PERCENT')
277
+ end
278
+
279
+ it 'remove the coupon from customer' do
280
+ customer = Stripe::Customer.retrieve('test_cus_coupon')
281
+ expect(customer.discount).to_not be_nil
282
+ expect(customer.discount.coupon).to_not be_nil
283
+ expect(customer.discount.customer).to eq customer.id
284
+ expect(customer.discount.start).to be_within(1).of Time.now.to_i
285
+
286
+ Stripe::Customer.update('test_cus_coupon', coupon: '')
287
+ customer = Stripe::Customer.retrieve('test_cus_coupon')
288
+ expect(customer.discount).to be_nil
289
+ end
290
+ end
291
+
244
292
  it "stores a created stripe customer in memory" do
245
- customer = Stripe::Customer.create({
246
- email: 'johnny@appleseed.com',
247
- source: gen_card_tk
248
- })
249
- customer2 = Stripe::Customer.create({
250
- email: 'bob@bobbers.com',
251
- source: gen_card_tk
252
- })
293
+ customer = Stripe::Customer.create(email: 'johnny@appleseed.com')
294
+ customer2 = Stripe::Customer.create(email: 'bob@bobbers.com')
253
295
  data = test_data_source(:customers)
254
- expect(data[customer.id]).to_not be_nil
255
- expect(data[customer.id][:email]).to eq('johnny@appleseed.com')
296
+ list = data[data.keys.first]
297
+
298
+ customer_hash = list[customer.id.to_sym] || list[customer.id]
299
+ expect(customer_hash).to_not be_nil
300
+ expect(customer_hash[:email]).to eq('johnny@appleseed.com')
256
301
 
257
- expect(data[customer2.id]).to_not be_nil
258
- expect(data[customer2.id][:email]).to eq('bob@bobbers.com')
302
+ customer2_hash = list[customer2.id.to_sym] || list[customer2.id]
303
+ expect(customer2_hash).to_not be_nil
304
+ expect(customer2_hash[:email]).to eq('bob@bobbers.com')
259
305
  end
260
306
 
261
307
  it "retrieves a stripe customer" do
@@ -267,6 +313,7 @@ shared_examples 'Customer API' do
267
313
 
268
314
  expect(customer.id).to eq(original.id)
269
315
  expect(customer.email).to eq(original.email)
316
+ expect(customer.name).to eq(nil)
270
317
  expect(customer.default_source).to eq(original.default_source)
271
318
  expect(customer.default_source).not_to be_a(Stripe::Card)
272
319
  expect(customer.subscriptions.count).to eq(0)
@@ -297,9 +344,9 @@ shared_examples 'Customer API' do
297
344
  Stripe::Customer.create({ email: 'one@one.com' })
298
345
  Stripe::Customer.create({ email: 'two@two.com' })
299
346
 
300
- all = Stripe::Customer.all
347
+ all = Stripe::Customer.list
301
348
  expect(all.count).to eq(2)
302
- expect(all.map &:email).to include('one@one.com', 'two@two.com')
349
+ expect(all.data.map &:email).to include('one@one.com', 'two@two.com')
303
350
  end
304
351
 
305
352
  it "updates a stripe customer" do
@@ -307,8 +354,9 @@ shared_examples 'Customer API' do
307
354
  email = original.email
308
355
 
309
356
  coupon = Stripe::Coupon.create(id: "10PERCENT", duration: 'once')
310
- original.description = 'new desc'
311
- original.coupon = coupon.id
357
+ original.description = 'new desc'
358
+ original.preferred_locales = %w(fr en)
359
+ original.coupon = coupon.id
312
360
  original.save
313
361
 
314
362
  expect(original.email).to eq(email)
@@ -318,9 +366,19 @@ shared_examples 'Customer API' do
318
366
  customer = Stripe::Customer.retrieve("test_customer_update")
319
367
  expect(customer.email).to eq(original.email)
320
368
  expect(customer.description).to eq('new desc')
369
+ expect(customer.preferred_locales).to eq(%w(fr en))
321
370
  expect(customer.discount.coupon).to be_a Stripe::Coupon
322
371
  end
323
372
 
373
+ it "preserves stripe customer metadata" do
374
+ metadata = {user_id: "38"}
375
+ customer = Stripe::Customer.create(metadata: metadata)
376
+ expect(customer.metadata.to_h).to eq(metadata)
377
+
378
+ updated = Stripe::Customer.update(customer.id, metadata: {fruit: "apples"})
379
+ expect(updated.metadata.to_h).to eq(metadata.merge(fruit: "apples"))
380
+ end
381
+
324
382
  it "retrieves the customer's default source after it was updated" do
325
383
  customer = Stripe::Customer.create()
326
384
  customer.source = gen_card_tk
@@ -381,7 +439,7 @@ shared_examples 'Customer API' do
381
439
  end
382
440
 
383
441
  it "still has subscriptions after save when subscriptions unchanged" do
384
- plan = stripe_helper.create_plan(id: 'silver')
442
+ plan = stripe_helper.create_plan(id: 'silver', product: product.id)
385
443
  original = Stripe::Customer.create(source: gen_card_tk, plan: 'silver')
386
444
  subscription = original.subscriptions.data.first
387
445
  subscription_id = subscription.id
@@ -394,7 +452,7 @@ shared_examples 'Customer API' do
394
452
  end
395
453
 
396
454
  it "should add a customer to a subscription" do
397
- plan = stripe_helper.create_plan(id: 'silver')
455
+ plan = stripe_helper.create_plan(id: 'silver', product: product.id)
398
456
  customer = Stripe::Customer.create(source: gen_card_tk)
399
457
  customer.subscriptions.create(plan: plan.id)
400
458
 
@@ -407,14 +465,6 @@ shared_examples 'Customer API' do
407
465
  expect(customer.deleted).to eq(true)
408
466
  end
409
467
 
410
- it 'works with the update_subscription method' do
411
- stripe_helper.create_plan(id: 'silver')
412
- cus = Stripe::Customer.create(source: gen_card_tk)
413
- expect {
414
- cus.update_subscription(plan: 'silver')
415
- }.not_to raise_error
416
- end
417
-
418
468
  it "deletes a stripe customer discount" do
419
469
  original = Stripe::Customer.create(id: 'test_customer_update')
420
470
 
@@ -71,14 +71,14 @@ shared_examples 'Dispute API' do
71
71
  describe "listing disputes" do
72
72
 
73
73
  it "retrieves all disputes" do
74
- disputes = Stripe::Dispute.all
74
+ disputes = Stripe::Dispute.list
75
75
 
76
76
  expect(disputes.count).to eq(10)
77
77
  expect(disputes.map &:id).to include('dp_05RsQX2eZvKYlo2C0FRTGSSA','dp_15RsQX2eZvKYlo2C0ERTYUIA', 'dp_25RsQX2eZvKYlo2C0ZXCVBNM', 'dp_35RsQX2eZvKYlo2C0QAZXSWE', 'dp_45RsQX2eZvKYlo2C0EDCVFRT', 'dp_55RsQX2eZvKYlo2C0OIKLJUY', 'dp_65RsQX2eZvKYlo2C0ASDFGHJ', 'dp_75RsQX2eZvKYlo2C0EDCXSWQ', 'dp_85RsQX2eZvKYlo2C0UJMCDET', 'dp_95RsQX2eZvKYlo2C0EDFRYUI')
78
78
  end
79
79
 
80
80
  it "retrieves disputes with a limit(3)" do
81
- disputes = Stripe::Dispute.all(limit: 3)
81
+ disputes = Stripe::Dispute.list(limit: 3)
82
82
 
83
83
  expect(disputes.count).to eq(3)
84
84
  expected = ['dp_95RsQX2eZvKYlo2C0EDFRYUI','dp_85RsQX2eZvKYlo2C0UJMCDET', 'dp_75RsQX2eZvKYlo2C0EDCXSWQ']
@@ -6,13 +6,14 @@ def expect_card_error(code, param)
6
6
  expect(e.http_status).to eq(402)
7
7
  expect(e.code).to eq(code)
8
8
  expect(e.param).to eq(param)
9
+ expect(e.http_body).to eq(e.json_body.to_json)
9
10
  }
10
11
  end
11
12
 
12
13
  shared_examples 'Stripe Error Mocking' do
13
14
 
14
15
  it "mocks a manually given stripe card error" do
15
- error = Stripe::CardError.new('Test Msg', 'param_name', 'bad_code', http_status: 444, http_body: 'body', json_body: 'json body')
16
+ error = Stripe::CardError.new('Test Msg', 'param_name', code: 'bad_code', http_status: 444, http_body: 'body', json_body: {})
16
17
  StripeMock.prepare_error(error)
17
18
 
18
19
  expect { Stripe::Customer.create() }.to raise_error {|e|
@@ -23,14 +24,14 @@ shared_examples 'Stripe Error Mocking' do
23
24
 
24
25
  expect(e.http_status).to eq(444)
25
26
  expect(e.http_body).to eq('body')
26
- expect(e.json_body).to eq('json body')
27
+ expect(e.json_body).to eq({})
27
28
  }
28
29
  end
29
30
 
30
31
 
31
32
  it "mocks a manually gives stripe invalid request error" do
32
33
 
33
- error = Stripe::InvalidRequestError.new('Test Invalid', 'param', http_status: 987, http_body: 'ibody', json_body: 'json ibody')
34
+ error = Stripe::InvalidRequestError.new('Test Invalid', 'param', http_status: 987, http_body: 'ibody', json_body: {})
34
35
  StripeMock.prepare_error(error)
35
36
 
36
37
  expect { Stripe::Charge.create(amount: 1, currency: 'usd') }.to raise_error {|e|
@@ -40,22 +41,22 @@ shared_examples 'Stripe Error Mocking' do
40
41
 
41
42
  expect(e.http_status).to eq(987)
42
43
  expect(e.http_body).to eq('ibody')
43
- expect(e.json_body).to eq('json ibody')
44
+ expect(e.json_body).to eq({})
44
45
  }
45
46
  end
46
47
 
47
48
 
48
49
  it "mocks a manually gives stripe invalid auth error" do
49
- error = Stripe::AuthenticationError.new('Bad Auth', http_status: 499, http_body: 'abody', json_body: 'json abody')
50
+ error = Stripe::AuthenticationError.new('Bad Auth', http_status: 499, http_body: 'abody', json_body: {})
50
51
  StripeMock.prepare_error(error)
51
52
 
52
- expect { stripe_helper.create_plan() }.to raise_error {|e|
53
+ expect { stripe_helper.create_plan(id: "test_plan") }.to raise_error {|e|
53
54
  expect(e).to be_a(Stripe::AuthenticationError)
54
55
  expect(e.message).to eq('Bad Auth')
55
56
 
56
57
  expect(e.http_status).to eq(499)
57
58
  expect(e.http_body).to eq('abody')
58
- expect(e.json_body).to eq('json abody')
59
+ expect(e.json_body).to eq({})
59
60
  }
60
61
  end
61
62