stripe-ruby-mock 2.2.4 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/stripe_mock/api/bank_tokens.rb +5 -5
  4. data/lib/stripe_mock/api/card_tokens.rb +4 -4
  5. data/lib/stripe_mock/api/client.rb +6 -3
  6. data/lib/stripe_mock/api/errors.rb +4 -4
  7. data/lib/stripe_mock/api/server.rb +0 -1
  8. data/lib/stripe_mock/client.rb +12 -7
  9. data/lib/stripe_mock/data.rb +48 -2
  10. data/lib/stripe_mock/error_queue.rb +5 -1
  11. data/lib/stripe_mock/instance.rb +5 -3
  12. data/lib/stripe_mock/request_handlers/balance_transactions.rb +21 -0
  13. data/lib/stripe_mock/request_handlers/charges.rb +17 -10
  14. data/lib/stripe_mock/request_handlers/customers.rb +1 -0
  15. data/lib/stripe_mock/request_handlers/helpers/card_helpers.rb +35 -0
  16. data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +2 -2
  17. data/lib/stripe_mock/request_handlers/sources.rb +1 -1
  18. data/lib/stripe_mock/request_handlers/subscriptions.rb +79 -17
  19. data/lib/stripe_mock/request_handlers/tokens.rb +14 -4
  20. data/lib/stripe_mock/server.rb +21 -15
  21. data/lib/stripe_mock/test_strategies/base.rb +15 -0
  22. data/lib/stripe_mock/version.rb +1 -1
  23. data/lib/stripe_mock.rb +2 -1
  24. data/spec/server_spec.rb +1 -1
  25. data/spec/shared_stripe_examples/balance_transaction_examples.rb +35 -0
  26. data/spec/shared_stripe_examples/bank_examples.rb +202 -0
  27. data/spec/shared_stripe_examples/bank_token_examples.rb +8 -0
  28. data/spec/shared_stripe_examples/card_token_examples.rb +10 -0
  29. data/spec/shared_stripe_examples/charge_examples.rb +27 -1
  30. data/spec/shared_stripe_examples/customer_examples.rb +2 -1
  31. data/spec/shared_stripe_examples/invoice_examples.rb +12 -12
  32. data/spec/shared_stripe_examples/refund_examples.rb +13 -0
  33. data/spec/shared_stripe_examples/subscription_examples.rb +47 -56
  34. data/spec/support/stripe_examples.rb +5 -3
  35. data/stripe-ruby-mock.gemspec +2 -2
  36. metadata +14 -9
@@ -21,6 +21,21 @@ module StripeMock
21
21
  stripe_token.id
22
22
  end
23
23
 
24
+ def generate_bank_token(bank_account_params={})
25
+ bank_account = {
26
+ :country => "US",
27
+ :currency => "usd",
28
+ :account_holder_name => "Jane Austen",
29
+ :account_holder_type => "individual",
30
+ :routing_number => "110000000",
31
+ :account_number => "000123456789"
32
+ }.merge(bank_account_params)
33
+ bank_account[:fingerprint] = StripeMock::Util.fingerprint(bank_account[:account_number]) if StripeMock.state == 'local'
34
+
35
+ stripe_token = Stripe::Token.create(:bank_account => bank_account)
36
+ stripe_token.id
37
+ end
38
+
24
39
  def create_coupon_params(params = {})
25
40
  {
26
41
  id: '10BUCKS',
@@ -1,4 +1,4 @@
1
1
  module StripeMock
2
2
  # stripe-ruby-mock version
3
- VERSION = "2.2.4"
3
+ VERSION = "2.3.0"
4
4
  end
data/lib/stripe_mock.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'ostruct'
2
- require 'jimson-temp'
2
+ require 'multi_json'
3
3
  require 'dante'
4
4
 
5
5
  require 'stripe'
@@ -44,6 +44,7 @@ require 'stripe_mock/request_handlers/helpers/token_helpers.rb'
44
44
  require 'stripe_mock/request_handlers/validators/param_validators.rb'
45
45
 
46
46
  require 'stripe_mock/request_handlers/accounts.rb'
47
+ require 'stripe_mock/request_handlers/balance_transactions.rb'
47
48
  require 'stripe_mock/request_handlers/charges.rb'
48
49
  require 'stripe_mock/request_handlers/cards.rb'
49
50
  require 'stripe_mock/request_handlers/sources.rb'
data/spec/server_spec.rb CHANGED
@@ -128,7 +128,7 @@ describe 'StripeMock Server', :mock_server => true do
128
128
  # We should never get here
129
129
  expect(false).to eq(true)
130
130
  rescue StripeMock::ServerTimeoutError => e
131
- expect(e.associated_error).to be_a(Errno::ECONNREFUSED)
131
+ expect(e).to be_a StripeMock::ServerTimeoutError
132
132
  end
133
133
  end
134
134
 
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples 'Balance Transaction API' do
4
+
5
+ it "returns an error if balance transaction does not exist" do
6
+ txn_id = 'txn_xxxxxxxxxxxxxxxxxxxxxxxx'
7
+
8
+ expect {
9
+ Stripe::BalanceTransaction.retrieve(txn_id)
10
+ }.to raise_error { |e|
11
+ expect(e).to be_a(Stripe::InvalidRequestError)
12
+ expect(e.message).to eq('No such balance_transaction: ' + txn_id)
13
+ }
14
+ end
15
+
16
+ it "retrieves a single balance transaction" do
17
+ txn_id = 'txn_05RsQX2eZvKYlo2C0FRTGSSA'
18
+ txn = Stripe::BalanceTransaction.retrieve(txn_id)
19
+
20
+ expect(txn).to be_a(Stripe::BalanceTransaction)
21
+ expect(txn.id).to eq(txn_id)
22
+ end
23
+
24
+ describe "listing balance transactions" do
25
+
26
+ it "retrieves all balance transactions" do
27
+ disputes = Stripe::BalanceTransaction.all
28
+
29
+ expect(disputes.count).to eq(10)
30
+ expect(disputes.map &:id).to include('txn_05RsQX2eZvKYlo2C0FRTGSSA','txn_15RsQX2eZvKYlo2C0ERTYUIA', 'txn_25RsQX2eZvKYlo2C0ZXCVBNM', 'txn_35RsQX2eZvKYlo2C0QAZXSWE', 'txn_45RsQX2eZvKYlo2C0EDCVFRT', 'txn_55RsQX2eZvKYlo2C0OIKLJUY', 'txn_65RsQX2eZvKYlo2C0ASDFGHJ', 'txn_75RsQX2eZvKYlo2C0EDCXSWQ', 'txn_85RsQX2eZvKYlo2C0UJMCDET', 'txn_95RsQX2eZvKYlo2C0EDFRYUI')
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,202 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples 'Bank API' do
4
+
5
+ it 'creates/returns a bank when using customer.sources.create given a bank token' do
6
+ customer = Stripe::Customer.create(id: 'test_customer_sub')
7
+ bank_token = stripe_helper.generate_bank_token(last4: "1123", exp_month: 11, exp_year: 2099)
8
+ bank = customer.sources.create(source: bank_token)
9
+
10
+ expect(bank.customer).to eq('test_customer_sub')
11
+ expect(bank.last4).to eq("1123")
12
+ expect(bank.exp_month).to eq(11)
13
+ expect(bank.exp_year).to eq(2099)
14
+
15
+ customer = Stripe::Customer.retrieve('test_customer_sub')
16
+ expect(customer.sources.count).to eq(1)
17
+ bank = customer.sources.data.first
18
+ expect(bank.customer).to eq('test_customer_sub')
19
+ expect(bank.last4).to eq("1123")
20
+ expect(bank.exp_month).to eq(11)
21
+ expect(bank.exp_year).to eq(2099)
22
+ end
23
+
24
+ it 'creates/returns a bank when using customer.sources.create given bank params' do
25
+ customer = Stripe::Customer.create(id: 'test_customer_sub')
26
+ bank = customer.sources.create(bank: {
27
+ number: '4242424242424242',
28
+ exp_month: '11',
29
+ exp_year: '3031',
30
+ cvc: '123'
31
+ })
32
+
33
+ expect(bank.customer).to eq('test_customer_sub')
34
+ expect(bank.last4).to eq("6789")
35
+
36
+ customer = Stripe::Customer.retrieve('test_customer_sub')
37
+ expect(customer.sources.count).to eq(1)
38
+ bank = customer.sources.data.first
39
+ expect(bank.customer).to eq('test_customer_sub')
40
+ expect(bank.last4).to eq("6789")
41
+ end
42
+
43
+ it "creates a single bank with a generated bank token", :live => true do
44
+ customer = Stripe::Customer.create
45
+ expect(customer.sources.count).to eq 0
46
+
47
+ customer.sources.create :source => stripe_helper.generate_bank_token
48
+ # Yes, stripe-ruby does not actually add the new bank to the customer instance
49
+ expect(customer.sources.count).to eq 0
50
+
51
+ customer2 = Stripe::Customer.retrieve(customer.id)
52
+ expect(customer2.sources.count).to eq 1
53
+ expect(customer2.default_source).to eq customer2.sources.first.id
54
+ end
55
+
56
+ it 'create does not change the customers default bank if already set' do
57
+ customer = Stripe::Customer.create(id: 'test_customer_sub', default_source: "test_cc_original")
58
+ bank_token = stripe_helper.generate_bank_token(last4: "1123", exp_month: 11, exp_year: 2099)
59
+ bank = customer.sources.create(source: bank_token)
60
+
61
+ customer = Stripe::Customer.retrieve('test_customer_sub')
62
+ expect(customer.default_source).to eq("test_cc_original")
63
+ end
64
+
65
+ it 'create updates the customers default bank if not set' do
66
+ customer = Stripe::Customer.create(id: 'test_customer_sub')
67
+ bank_token = stripe_helper.generate_bank_token(last4: "1123", exp_month: 11, exp_year: 2099)
68
+ bank = customer.sources.create(source: bank_token)
69
+
70
+ customer = Stripe::Customer.retrieve('test_customer_sub')
71
+ expect(customer.default_source).to_not be_nil
72
+ end
73
+
74
+ describe "retrieval and deletion with customers" do
75
+ let!(:customer) { Stripe::Customer.create(id: 'test_customer_sub') }
76
+ let!(:bank_token) { stripe_helper.generate_bank_token(last4: "1123", exp_month: 11, exp_year: 2099) }
77
+ let!(:bank) { customer.sources.create(source: bank_token) }
78
+
79
+ it "can retrieve all customer's banks" do
80
+ retrieved = customer.sources.all
81
+ expect(retrieved.count).to eq(1)
82
+ end
83
+
84
+ it "retrieves a customers bank" do
85
+ retrieved = customer.sources.retrieve(bank.id)
86
+ expect(retrieved.to_s).to eq(bank.to_s)
87
+ end
88
+
89
+ it "retrieves a customer's bank after re-fetching the customer" do
90
+ retrieved = Stripe::Customer.retrieve(customer.id).sources.retrieve(bank.id)
91
+ expect(retrieved.id).to eq bank.id
92
+ end
93
+
94
+ it "deletes a customers bank" do
95
+ bank.delete
96
+ retrieved_cus = Stripe::Customer.retrieve(customer.id)
97
+ expect(retrieved_cus.sources.data).to be_empty
98
+ end
99
+
100
+ it "deletes a customers bank then set the default_bank to nil" do
101
+ bank.delete
102
+ retrieved_cus = Stripe::Customer.retrieve(customer.id)
103
+ expect(retrieved_cus.default_source).to be_nil
104
+ end
105
+
106
+ it "updates the default bank if deleted" do
107
+ bank.delete
108
+ retrieved_cus = Stripe::Customer.retrieve(customer.id)
109
+ expect(retrieved_cus.default_source).to be_nil
110
+ end
111
+
112
+ context "deletion when the user has two banks" do
113
+ let!(:bank_token_2) { stripe_helper.generate_bank_token(last4: "1123", exp_month: 11, exp_year: 2099) }
114
+ let!(:bank_2) { customer.sources.create(source: bank_token_2) }
115
+
116
+ it "has just one bank anymore" do
117
+ bank.delete
118
+ retrieved_cus = Stripe::Customer.retrieve(customer.id)
119
+ expect(retrieved_cus.sources.data.count).to eq 1
120
+ expect(retrieved_cus.sources.data.first.id).to eq bank_2.id
121
+ end
122
+
123
+ it "sets the default_bank id to the last bank remaining id" do
124
+ bank.delete
125
+ retrieved_cus = Stripe::Customer.retrieve(customer.id)
126
+ expect(retrieved_cus.default_source).to eq bank_2.id
127
+ end
128
+ end
129
+ end
130
+
131
+ describe "Errors", :live => true do
132
+ it "throws an error when the customer does not have the retrieving bank id" do
133
+ customer = Stripe::Customer.create
134
+ bank_id = "bank_123"
135
+ expect { customer.sources.retrieve(bank_id) }.to raise_error {|e|
136
+ expect(e).to be_a Stripe::InvalidRequestError
137
+ expect(e.message).to match /no.*source/i
138
+ expect(e.message).to include bank_id
139
+ expect(e.param).to eq 'id'
140
+ expect(e.http_status).to eq 404
141
+ }
142
+ end
143
+ end
144
+
145
+ context "update bank" do
146
+ let!(:customer) { Stripe::Customer.create(id: 'test_customer_sub') }
147
+ let!(:bank_token) { stripe_helper.generate_bank_token(last4: "1123", exp_month: 11, exp_year: 2099) }
148
+ let!(:bank) { customer.sources.create(source: bank_token) }
149
+
150
+ it "updates the bank" do
151
+ exp_month = 10
152
+ exp_year = 2098
153
+
154
+ bank.exp_month = exp_month
155
+ bank.exp_year = exp_year
156
+ bank.save
157
+
158
+ retrieved = customer.sources.retrieve(bank.id)
159
+
160
+ expect(retrieved.exp_month).to eq(exp_month)
161
+ expect(retrieved.exp_year).to eq(exp_year)
162
+ end
163
+ end
164
+
165
+ context "retrieve multiple banks" do
166
+
167
+ it "retrieves a list of multiple banks" do
168
+ customer = Stripe::Customer.create(id: 'test_customer_bank')
169
+
170
+ bank_token = stripe_helper.generate_bank_token(last4: "1123", exp_month: 11, exp_year: 2099)
171
+ bank1 = customer.sources.create(source: bank_token)
172
+ bank_token = stripe_helper.generate_bank_token(last4: "1124", exp_month: 12, exp_year: 2098)
173
+ bank2 = customer.sources.create(source: bank_token)
174
+
175
+ customer = Stripe::Customer.retrieve('test_customer_bank')
176
+
177
+ list = customer.sources.all
178
+
179
+ expect(list.object).to eq("list")
180
+ expect(list.count).to eq(2)
181
+ expect(list.data.length).to eq(2)
182
+
183
+ expect(list.data.first.object).to eq("bank_account")
184
+ expect(list.data.first.to_hash).to eq(bank1.to_hash)
185
+
186
+ expect(list.data.last.object).to eq("bank_account")
187
+ expect(list.data.last.to_hash).to eq(bank2.to_hash)
188
+ end
189
+
190
+ it "retrieves an empty list if there's no subscriptions" do
191
+ Stripe::Customer.create(id: 'no_banks')
192
+ customer = Stripe::Customer.retrieve('no_banks')
193
+
194
+ list = customer.sources.all
195
+
196
+ expect(list.object).to eq("list")
197
+ expect(list.count).to eq(0)
198
+ expect(list.data.length).to eq(0)
199
+ end
200
+ end
201
+
202
+ end
@@ -2,6 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  shared_examples 'Bank Account Token Mocking' do
4
4
 
5
+ it "generates a bank token with default values" do
6
+ bank_token = StripeMock.generate_bank_token
7
+ tokens = test_data_source(:bank_tokens)
8
+ expect(tokens[bank_token]).to_not be_nil
9
+ expect(tokens[bank_token][:bank_name]).to eq("STRIPEMOCK TEST BANK")
10
+ expect(tokens[bank_token][:last4]).to eq("6789")
11
+ end
12
+
5
13
  it "generates a bank token with an associated account in memory" do
6
14
  bank_token = StripeMock.generate_bank_token(
7
15
  :bank_name => "Memory Bank",
@@ -4,6 +4,16 @@ shared_examples 'Card Token Mocking' do
4
4
 
5
5
  describe 'Direct Token Creation' do
6
6
 
7
+ it "generates and reads a card token with default values" do
8
+ card_token = StripeMock.generate_card_token
9
+
10
+ charge = Stripe::Charge.create(amount: 500, currency: 'usd', source: card_token)
11
+ card = charge.source
12
+ expect(card.last4).to eq("4242")
13
+ expect(card.exp_month).to eq(4)
14
+ expect(card.exp_year).to eq(2016)
15
+ end
16
+
7
17
  it "generates and reads a card token for create charge" do
8
18
  card_token = StripeMock.generate_card_token(last4: "2244", exp_month: 33, exp_year: 2255)
9
19
 
@@ -65,6 +65,31 @@ shared_examples 'Charge API' do
65
65
  expect(charge.status).to eq('succeeded')
66
66
  end
67
67
 
68
+ it 'creates a stripe charge item with a customer', :live => true do
69
+ customer = Stripe::Customer.create({
70
+ email: 'johnny@appleseed.com',
71
+ source: stripe_helper.generate_card_token(number: '4012888888881881', address_city: 'LA'),
72
+ description: "a description"
73
+ })
74
+
75
+ expect(customer.sources.data.length).to eq(1)
76
+ expect(customer.sources.data[0].id).not_to be_nil
77
+ expect(customer.sources.data[0].last4).to eq('1881')
78
+
79
+ charge = Stripe::Charge.create(
80
+ amount: 999,
81
+ currency: 'USD',
82
+ customer: customer.id,
83
+ description: 'a charge with a specific customer'
84
+ )
85
+
86
+ expect(charge.id).to match(/^(test_)?ch/)
87
+ expect(charge.amount).to eq(999)
88
+ expect(charge.description).to eq('a charge with a specific customer')
89
+ expect(charge.captured).to eq(true)
90
+ expect(charge.source.last4).to eq('1881')
91
+ expect(charge.source.address_city).to eq('LA')
92
+ end
68
93
 
69
94
  it "creates a stripe charge item with a customer and card id" do
70
95
  customer = Stripe::Customer.create({
@@ -266,7 +291,8 @@ shared_examples 'Charge API' do
266
291
  object: 'card',
267
292
  number: '4242424242424242',
268
293
  exp_month: 12,
269
- exp_year: 2024
294
+ exp_year: 2024,
295
+ cvc: 123
270
296
  }
271
297
  )
272
298
  12.times do
@@ -43,7 +43,8 @@ shared_examples 'Customer API' do
43
43
  object: 'card',
44
44
  number: '4242424242424242',
45
45
  exp_month: 12,
46
- exp_year: 2024
46
+ exp_year: 2024,
47
+ cvc: 123
47
48
  },
48
49
  email: 'blah@blah.com')
49
50
 
@@ -122,7 +122,7 @@ shared_examples 'Invoice API' do
122
122
 
123
123
  it 'works when customer has a subscription', :live => true do
124
124
  plan = stripe_helper.create_plan(:id => 'has_sub')
125
- subscription = @customer.subscriptions.create(plan: plan.id)
125
+ subscription = Stripe::Subscription.create(plan: plan.id, customer: @customer.id)
126
126
  upcoming = Stripe::Invoice.upcoming(customer: @customer.id)
127
127
 
128
128
  expect(upcoming).to be_a Stripe::Invoice
@@ -137,7 +137,7 @@ shared_examples 'Invoice API' do
137
137
 
138
138
  it 'sets the start and end of billing periods correctly when plan has an interval_count' do
139
139
  @oddplan = stripe_helper.create_plan(interval: "week", interval_count: 11)
140
- @subscription = @customer.subscriptions.create(plan: @oddplan.id)
140
+ @subscription = Stripe::Subscription.create(plan: @oddplan.id, customer: @customer.id)
141
141
  @upcoming = Stripe::Invoice.upcoming(customer: @customer.id)
142
142
 
143
143
  expect(@upcoming.period_start + 6652800).to eq(@upcoming.period_end) # 6652800 = +11 weeks
@@ -151,9 +151,9 @@ shared_examples 'Invoice API' do
151
151
  @plainplan = stripe_helper.create_plan(id: 'b') # 1 month sub
152
152
  @longplan = stripe_helper.create_plan(id: 'c', interval: "year") # 1 year sub
153
153
 
154
- @plainsub = @customer.subscriptions.create(plan: @plainplan.id)
155
- @shortsub = @customer.subscriptions.create(plan: @shortplan.id)
156
- @longsub = @customer.subscriptions.create(plan: @longplan.id)
154
+ @plainsub = Stripe::Subscription.create(plan: @plainplan.id, customer: @customer.id)
155
+ @shortsub = Stripe::Subscription.create(plan: @shortplan.id, customer: @customer.id)
156
+ @longsub = Stripe::Subscription.create(plan: @longplan.id, customer: @customer.id)
157
157
 
158
158
  @upcoming = Stripe::Invoice.upcoming(customer: @customer.id)
159
159
 
@@ -176,7 +176,7 @@ shared_examples 'Invoice API' do
176
176
 
177
177
  it 'returns all line items for upcoming invoice' do
178
178
  plan = stripe_helper.create_plan()
179
- subscription = @customer.subscriptions.create(plan: plan.id)
179
+ subscription = Stripe::Subscription.create(plan: plan.id, customer: @customer.id)
180
180
  upcoming = Stripe::Invoice.upcoming(customer: @customer.id)
181
181
  line_items = upcoming.lines.all
182
182
 
@@ -192,7 +192,7 @@ shared_examples 'Invoice API' do
192
192
 
193
193
  it 'for one month plan on the 1st' do
194
194
  @plan = stripe_helper.create_plan()
195
- @sub = @customer.subscriptions.create(plan: @plan.id, current_period_start: Time.utc(2014,1,1,12).to_i)
195
+ @sub = Stripe::Subscription.create(plan: @plan.id, customer: @customer.id, current_period_start: Time.utc(2014,1,1,12).to_i)
196
196
  @upcoming = Stripe::Invoice.upcoming(customer: @customer.id)
197
197
 
198
198
  expect(Time.at(@upcoming.period_start)).to eq(Time.utc(2014,1,1,12))
@@ -203,7 +203,7 @@ shared_examples 'Invoice API' do
203
203
 
204
204
  it 'for one year plan on the 1st' do
205
205
  @plan = stripe_helper.create_plan(interval: "year")
206
- @sub = @customer.subscriptions.create(plan: @plan.id, current_period_start: Time.utc(2012,1,1,12).to_i)
206
+ @sub = Stripe::Subscription.create(plan: @plan.id, customer: @customer.id, current_period_start: Time.utc(2012,1,1,12).to_i)
207
207
  @upcoming = Stripe::Invoice.upcoming(customer: @customer.id)
208
208
 
209
209
  expect(Time.at(@upcoming.period_start)).to eq(Time.utc(2012,1,1,12))
@@ -214,7 +214,7 @@ shared_examples 'Invoice API' do
214
214
 
215
215
  it 'for one month plan on the 31st' do
216
216
  @plan = stripe_helper.create_plan()
217
- @sub = @customer.subscriptions.create(plan: @plan.id, current_period_start: Time.utc(2014,1,31,12).to_i)
217
+ @sub = Stripe::Subscription.create(plan: @plan.id, customer: @customer.id, current_period_start: Time.utc(2014,1,31,12).to_i)
218
218
  @upcoming = Stripe::Invoice.upcoming(customer: @customer.id)
219
219
 
220
220
  expect(Time.at(@upcoming.period_start)).to eq(Time.utc(2014,1,31,12))
@@ -225,7 +225,7 @@ shared_examples 'Invoice API' do
225
225
 
226
226
  it 'for one year plan on feb. 29th' do
227
227
  @plan = stripe_helper.create_plan(interval: "year")
228
- @sub = @customer.subscriptions.create(plan: @plan.id, current_period_start: Time.utc(2012,2,29,12).to_i)
228
+ @sub = Stripe::Subscription.create(plan: @plan.id, customer: @customer.id, current_period_start: Time.utc(2012,2,29,12).to_i)
229
229
  @upcoming = Stripe::Invoice.upcoming(customer: @customer.id)
230
230
 
231
231
  expect(Time.at(@upcoming.period_start)).to eq(Time.utc(2012,2,29,12))
@@ -236,7 +236,7 @@ shared_examples 'Invoice API' do
236
236
 
237
237
  it 'for two month plan on dec. 31st' do
238
238
  @plan = stripe_helper.create_plan(interval_count: 2)
239
- @sub = @customer.subscriptions.create(plan: @plan.id, current_period_start: Time.utc(2013,12,31,12).to_i)
239
+ @sub = Stripe::Subscription.create(plan: @plan.id, customer: @customer.id, current_period_start: Time.utc(2013,12,31,12).to_i)
240
240
  @upcoming = Stripe::Invoice.upcoming(customer: @customer.id)
241
241
 
242
242
  expect(Time.at(@upcoming.period_start)).to eq(Time.utc(2013,12,31,12))
@@ -247,7 +247,7 @@ shared_examples 'Invoice API' do
247
247
 
248
248
  it 'for three month plan on nov. 30th' do
249
249
  @plan = stripe_helper.create_plan(interval_count: 3)
250
- @sub = @customer.subscriptions.create(plan: @plan.id, current_period_start: Time.utc(2013,11,30,12).to_i)
250
+ @sub = Stripe::Subscription.create(plan: @plan.id, customer: @customer.id, current_period_start: Time.utc(2013,11,30,12).to_i)
251
251
  @upcoming = Stripe::Invoice.upcoming(customer: @customer.id)
252
252
 
253
253
  expect(Time.at(@upcoming.period_start)).to eq(Time.utc(2013,11,30,12))
@@ -43,6 +43,19 @@ shared_examples 'Refund API' do
43
43
  expect(refund.refunds.data.first.id).to match(/^test_re/)
44
44
  end
45
45
 
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
+
46
59
  it "creates a stripe refund with a different balance transaction than the charge" do
47
60
  charge = Stripe::Charge.create(
48
61
  amount: 999,