stripe-ruby-mock 2.4.1 → 2.5.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 +6 -4
- data/README.md +10 -4
- data/lib/stripe_mock/api/client.rb +3 -3
- data/lib/stripe_mock/api/errors.rb +25 -14
- data/lib/stripe_mock/api/instance.rb +4 -4
- data/lib/stripe_mock/api/webhooks.rb +1 -1
- data/lib/stripe_mock/client.rb +2 -2
- data/lib/stripe_mock/data.rb +51 -26
- data/lib/stripe_mock/instance.rb +7 -3
- data/lib/stripe_mock/request_handlers/charges.rb +6 -6
- data/lib/stripe_mock/request_handlers/coupons.rb +3 -2
- data/lib/stripe_mock/request_handlers/customers.rb +16 -7
- data/lib/stripe_mock/request_handlers/helpers/card_helpers.rb +2 -2
- data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +6 -1
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +5 -5
- data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +2 -2
- data/lib/stripe_mock/request_handlers/invoices.rb +63 -11
- data/lib/stripe_mock/request_handlers/orders.rb +4 -4
- data/lib/stripe_mock/request_handlers/refunds.rb +3 -3
- data/lib/stripe_mock/request_handlers/subscriptions.rb +8 -8
- data/lib/stripe_mock/request_handlers/tokens.rb +1 -1
- data/lib/stripe_mock/request_handlers/transfers.rb +1 -1
- data/lib/stripe_mock/server.rb +1 -1
- data/lib/stripe_mock/version.rb +1 -1
- data/spec/instance_spec.rb +4 -4
- data/spec/integration_examples/prepare_error_examples.rb +6 -6
- data/spec/readme_spec.rb +2 -0
- data/spec/server_spec.rb +2 -2
- data/spec/shared_stripe_examples/card_examples.rb +3 -3
- data/spec/shared_stripe_examples/coupon_examples.rb +6 -0
- data/spec/shared_stripe_examples/customer_examples.rb +31 -3
- data/spec/shared_stripe_examples/dispute_examples.rb +9 -8
- data/spec/shared_stripe_examples/error_mock_examples.rb +3 -3
- data/spec/shared_stripe_examples/extra_features_examples.rb +2 -0
- data/spec/shared_stripe_examples/invoice_examples.rb +232 -48
- data/spec/shared_stripe_examples/recipient_examples.rb +7 -7
- data/spec/shared_stripe_examples/subscription_examples.rb +52 -16
- data/spec/shared_stripe_examples/transfer_examples.rb +8 -6
- data/spec/shared_stripe_examples/webhook_event_examples.rb +3 -3
- data/spec/spec_helper.rb +6 -5
- data/spec/stripe_mock_spec.rb +3 -3
- data/stripe-ruby-mock.gemspec +1 -1
- metadata +4 -10
@@ -18,7 +18,7 @@ shared_examples 'Dispute API' do
|
|
18
18
|
dispute_id = 'dp_05RsQX2eZvKYlo2C0FRTGSSA'
|
19
19
|
dispute = Stripe::Dispute.retrieve(dispute_id)
|
20
20
|
|
21
|
-
expect(dispute).to be_a(Stripe::Dispute)
|
21
|
+
expect(dispute).to be_a(Stripe::Dispute)
|
22
22
|
expect(dispute.id).to eq(dispute_id)
|
23
23
|
end
|
24
24
|
|
@@ -36,7 +36,7 @@ shared_examples 'Dispute API' do
|
|
36
36
|
:customer_name => 'Rebel Idealist',
|
37
37
|
:product_description => 'Lorem ipsum dolor sit amet.',
|
38
38
|
:shipping_documentation => 'fil_15BZxW2eZvKYlo2CvQbrn9dc',
|
39
|
-
}
|
39
|
+
}
|
40
40
|
dispute.save
|
41
41
|
|
42
42
|
dispute = Stripe::Dispute.retrieve(dispute_id)
|
@@ -50,13 +50,13 @@ shared_examples 'Dispute API' do
|
|
50
50
|
|
51
51
|
it "closes a dispute" do
|
52
52
|
dispute_id = 'dp_75RsQX2eZvKYlo2C0EDCXSWQ'
|
53
|
-
|
53
|
+
|
54
54
|
dispute = Stripe::Dispute.retrieve(dispute_id)
|
55
|
-
|
55
|
+
|
56
56
|
expect(dispute).to be_a(Stripe::Dispute)
|
57
57
|
expect(dispute.id).to eq(dispute_id)
|
58
58
|
expect(dispute.status).to eq('under_review')
|
59
|
-
|
59
|
+
|
60
60
|
dispute.close
|
61
61
|
|
62
62
|
dispute = Stripe::Dispute.retrieve(dispute_id)
|
@@ -67,7 +67,7 @@ shared_examples 'Dispute API' do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
describe "listing disputes" do
|
70
|
-
|
70
|
+
|
71
71
|
it "retrieves all disputes" do
|
72
72
|
disputes = Stripe::Dispute.all
|
73
73
|
|
@@ -79,9 +79,10 @@ shared_examples 'Dispute API' do
|
|
79
79
|
disputes = Stripe::Dispute.all(limit: 3)
|
80
80
|
|
81
81
|
expect(disputes.count).to eq(3)
|
82
|
-
|
82
|
+
expected = ['dp_95RsQX2eZvKYlo2C0EDFRYUI','dp_85RsQX2eZvKYlo2C0UJMCDET', 'dp_75RsQX2eZvKYlo2C0EDCXSWQ']
|
83
|
+
expect(disputes.map &:id).to include(*expected)
|
83
84
|
end
|
84
85
|
|
85
86
|
end
|
86
|
-
|
87
|
+
|
87
88
|
end
|
@@ -12,7 +12,7 @@ end
|
|
12
12
|
shared_examples 'Stripe Error Mocking' do
|
13
13
|
|
14
14
|
it "mocks a manually given stripe card error" do
|
15
|
-
error = Stripe::CardError.new('Test Msg', 'param_name', 'bad_code', 444, 'body', 'json body')
|
15
|
+
error = Stripe::CardError.new('Test Msg', 'param_name', 'bad_code', http_status: 444, http_body: 'body', json_body: 'json body')
|
16
16
|
StripeMock.prepare_error(error)
|
17
17
|
|
18
18
|
expect { Stripe::Customer.create() }.to raise_error {|e|
|
@@ -30,7 +30,7 @@ shared_examples 'Stripe Error Mocking' do
|
|
30
30
|
|
31
31
|
it "mocks a manually gives stripe invalid request error" do
|
32
32
|
|
33
|
-
error = Stripe::InvalidRequestError.new('Test Invalid', 'param', 987, 'ibody', 'json ibody')
|
33
|
+
error = Stripe::InvalidRequestError.new('Test Invalid', 'param', http_status: 987, http_body: 'ibody', json_body: 'json ibody')
|
34
34
|
StripeMock.prepare_error(error)
|
35
35
|
|
36
36
|
expect { Stripe::Charge.create(amount: 1, currency: 'usd') }.to raise_error {|e|
|
@@ -46,7 +46,7 @@ shared_examples 'Stripe Error Mocking' do
|
|
46
46
|
|
47
47
|
|
48
48
|
it "mocks a manually gives stripe invalid auth error" do
|
49
|
-
error = Stripe::AuthenticationError.new('Bad Auth', 499, 'abody', 'json abody')
|
49
|
+
error = Stripe::AuthenticationError.new('Bad Auth', http_status: 499, http_body: 'abody', json_body: 'json abody')
|
50
50
|
StripeMock.prepare_error(error)
|
51
51
|
|
52
52
|
expect { stripe_helper.create_plan() }.to raise_error {|e|
|
@@ -8,6 +8,7 @@ shared_examples 'Extra Features' do
|
|
8
8
|
|
9
9
|
customer = Stripe::Customer.create
|
10
10
|
expect(customer.id).to match /^custom_prefix_cus/
|
11
|
+
StripeMock.global_id_prefix = nil
|
11
12
|
end
|
12
13
|
|
13
14
|
it "can set the global id prefix to nothing" do
|
@@ -23,6 +24,7 @@ shared_examples 'Extra Features' do
|
|
23
24
|
|
24
25
|
customer = Stripe::Customer.create
|
25
26
|
expect(customer.id).to match /^cus/
|
27
|
+
StripeMock.global_id_prefix = nil
|
26
28
|
end
|
27
29
|
|
28
30
|
it "has a default global id prefix" do
|
@@ -107,42 +107,80 @@ shared_examples 'Invoice API' do
|
|
107
107
|
end
|
108
108
|
|
109
109
|
context "retrieving upcoming invoice" do
|
110
|
-
|
111
|
-
|
112
|
-
|
110
|
+
let(:customer) { @teardown_customer = true; Stripe::Customer.create(source: stripe_helper.generate_card_token) }
|
111
|
+
let(:coupon_amtoff) { @teardown_coupon_amtoff = true; Stripe::Coupon.create(id: '100OFF', currency: 'usd', amount_off: 100_00, duration: 'repeating', duration_in_months: 6) }
|
112
|
+
let(:coupon_pctoff) { @teardown_coupon_pctoff = true; Stripe::Coupon.create(id: '50%OFF', currency: 'usd', percent_off: 50, duration: 'repeating', duration_in_months: 6) }
|
113
|
+
let(:plan) { @teardown_plan = true; Stripe::Plan.create(id: '50m', amount: 50_00, interval: 'month', name: '50m', currency: 'usd') }
|
114
|
+
let(:quantity) { 3 }
|
115
|
+
let(:subscription) { @teardown_subscription = true; Stripe::Subscription.create(plan: plan.id, customer: customer.id, quantity: quantity) }
|
116
|
+
|
117
|
+
before(with_customer: true) { customer }
|
118
|
+
before(with_coupon_amtoff: true) { coupon_amtoff }
|
119
|
+
before(with_coupon_pctoff: true) { coupon_pctoff }
|
120
|
+
before(with_discount_amtoff: true) { customer.coupon = coupon_amtoff.id; customer.save }
|
121
|
+
before(with_discount_pctoff: true) { customer.coupon = coupon_pctoff.id; customer.save }
|
122
|
+
before(with_plan: true) { plan }
|
123
|
+
before(with_subscription: true) { subscription }
|
124
|
+
|
125
|
+
after { subscription.delete rescue nil if @teardown_subscription }
|
126
|
+
after { plan.delete rescue nil if @teardown_plan }
|
127
|
+
after { coupon_pctoff.delete rescue nil if @teardown_coupon_pctoff }
|
128
|
+
after { coupon_amtoff.delete rescue nil if @teardown_coupon_amtoff }
|
129
|
+
after { customer.delete rescue nil if @teardown_customer }
|
130
|
+
|
131
|
+
describe 'parameter validation' do
|
132
|
+
it 'fails without parameters' do
|
133
|
+
expect { Stripe::Invoice.upcoming() }.to raise_error {|e|
|
134
|
+
expect(e).to be_a(ArgumentError) }
|
135
|
+
end
|
113
136
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
137
|
+
it 'fails without a valid customer' do
|
138
|
+
expect { Stripe::Invoice.upcoming(customer: 'whatever') }.to raise_error {|e|
|
139
|
+
expect(e).to be_a(Stripe::InvalidRequestError)
|
140
|
+
expect(e.message).to eq('No such customer: whatever') }
|
141
|
+
end
|
118
142
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
143
|
+
it 'fails without a customer parameter' do
|
144
|
+
expect { Stripe::Invoice.upcoming(gazebo: 'raindance') }.to raise_error {|e|
|
145
|
+
expect(e).to be_a(Stripe::InvalidRequestError)
|
146
|
+
expect(e.http_status).to eq(400)
|
147
|
+
expect(e.message).to eq('Missing required param: customer') }
|
148
|
+
end
|
124
149
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
150
|
+
it 'fails without a subscription' do
|
151
|
+
expect { Stripe::Invoice.upcoming(customer: customer.id) }.to raise_error {|e|
|
152
|
+
expect(e).to be_a(Stripe::InvalidRequestError)
|
153
|
+
expect(e.http_status).to eq(404)
|
154
|
+
expect(e.message).to eq("No upcoming invoices for customer: #{customer.id}") }
|
155
|
+
end
|
130
156
|
end
|
131
157
|
|
132
|
-
|
133
|
-
|
134
|
-
expect(
|
135
|
-
|
136
|
-
|
158
|
+
describe 'parameter validation' do
|
159
|
+
it 'fails without a subscription or subscription plan if subscription proration date is specified', live: true do
|
160
|
+
expect { Stripe::Invoice.upcoming(customer: customer.id, subscription_proration_date: Time.now.to_i) }.to raise_error do |e|
|
161
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
162
|
+
expect(e.http_status).to eq 400
|
163
|
+
expect(e.message).to eq 'When previewing changes to a subscription, you must specify either `subscription` or `subscription_items`'
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'fails without a subscription if proration date is specified', live: true, with_subscription: true do
|
168
|
+
expect { Stripe::Invoice.upcoming(customer: customer.id, subscription_plan: plan.id, subscription_proration_date: Time.now.to_i) }.to raise_error do |e|
|
169
|
+
expect(e).to be_a Stripe::InvalidRequestError
|
170
|
+
expect(e.http_status).to eq 400
|
171
|
+
expect(e.message).to eq 'Cannot specify proration date without specifying a subscription'
|
172
|
+
end
|
173
|
+
end
|
137
174
|
end
|
138
175
|
|
139
|
-
it '
|
140
|
-
|
141
|
-
|
142
|
-
upcoming = Stripe::Invoice.upcoming(customer: @customer.id)
|
176
|
+
it 'considers current subscription', live: true, with_subscription: true do
|
177
|
+
# When
|
178
|
+
upcoming = Stripe::Invoice.upcoming(customer: customer.id)
|
143
179
|
|
180
|
+
# Then
|
144
181
|
expect(upcoming).to be_a Stripe::Invoice
|
145
|
-
expect(upcoming.customer).to eq(
|
182
|
+
expect(upcoming.customer).to eq(customer.id)
|
183
|
+
expect(upcoming.amount_due).to eq plan.amount * quantity
|
146
184
|
expect(upcoming.total).to eq(upcoming.lines.data[0].amount)
|
147
185
|
expect(upcoming.period_end).to eq(upcoming.lines.data[0].period.start)
|
148
186
|
expect(Time.at(upcoming.period_start).to_datetime >> 1).to eq(Time.at(upcoming.period_end).to_datetime) # +1 month
|
@@ -151,10 +189,156 @@ shared_examples 'Invoice API' do
|
|
151
189
|
expect(upcoming.subscription).to eq(subscription.id)
|
152
190
|
end
|
153
191
|
|
192
|
+
describe 'discounts' do
|
193
|
+
it 'considers a $ off discount', live: true, with_discount_amtoff: true, with_subscription: true do
|
194
|
+
# When
|
195
|
+
upcoming = Stripe::Invoice.upcoming(customer: customer.id)
|
196
|
+
|
197
|
+
# Then
|
198
|
+
expect(upcoming.discount).not_to be_nil
|
199
|
+
expect(upcoming.discount.coupon.id).to eq '100OFF'
|
200
|
+
expect(upcoming.discount.customer).to eq customer.id
|
201
|
+
expect(upcoming.discount.start).to be_within(5).of Time.now.to_i
|
202
|
+
expect(upcoming.discount.end).to be_within(5).of (Time.now.to_datetime >> 6).to_time.to_i
|
203
|
+
expect(upcoming.amount_due).to eq plan.amount * quantity - 100_00
|
204
|
+
expect(upcoming.subtotal).to eq(upcoming.lines.data[0].amount)
|
205
|
+
expect(upcoming.total).to eq upcoming.subtotal - 100_00
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'considers a % off discount', live: true, with_discount_pctoff: true, with_subscription: true do
|
209
|
+
# When
|
210
|
+
upcoming = Stripe::Invoice.upcoming(customer: customer.id)
|
211
|
+
|
212
|
+
# Then
|
213
|
+
expect(upcoming.discount).not_to be_nil
|
214
|
+
expect(upcoming.discount.coupon.id).to eq '50%OFF'
|
215
|
+
expect(upcoming.discount.customer).to eq customer.id
|
216
|
+
expect(upcoming.discount.start).to be_within(5).of Time.now.to_i
|
217
|
+
expect(upcoming.discount.end).to be_within(5).of (Time.now.to_datetime >> 6).to_time.to_i
|
218
|
+
expect(upcoming.amount_due).to eq (plan.amount * quantity) * 0.5
|
219
|
+
expect(upcoming.subtotal).to eq(upcoming.lines.data[0].amount)
|
220
|
+
expect(upcoming.total).to eq upcoming.subtotal * 0.5
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
describe 'proration' do
|
225
|
+
shared_examples 'failing when proration date is outside of the subscription current period' do
|
226
|
+
it 'fails', live: true do
|
227
|
+
expect { Stripe::Invoice.upcoming(
|
228
|
+
customer: customer.id,
|
229
|
+
subscription: subscription.id,
|
230
|
+
subscription_plan: plan.id,
|
231
|
+
subscription_quantity: quantity,
|
232
|
+
subscription_proration_date: proration_date.to_i,
|
233
|
+
subscription_trial_end: nil
|
234
|
+
) }.to raise_error {|e|
|
235
|
+
expect(e).to be_a(Stripe::InvalidRequestError)
|
236
|
+
expect(e.http_status).to eq(400)
|
237
|
+
expect(e.message).to eq('Cannot specify proration date outside of current subscription period') }
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
it_behaves_like 'failing when proration date is outside of the subscription current period' do
|
242
|
+
let(:proration_date) { subscription.current_period_start - 1 }
|
243
|
+
end
|
244
|
+
|
245
|
+
it_behaves_like 'failing when proration date is outside of the subscription current period' do
|
246
|
+
let(:proration_date) { subscription.current_period_end + 1 }
|
247
|
+
end
|
248
|
+
|
249
|
+
[false, true].each do |with_trial|
|
250
|
+
describe "prorating a subscription with a new plan, with_trial: #{with_trial}" do
|
251
|
+
let!(:new_plan) { Stripe::Plan.create(id: '100y', amount: 10000, interval: 'year', name: '100y', currency: 'usd') }
|
252
|
+
|
253
|
+
it 'prorates', live: true do
|
254
|
+
# Given
|
255
|
+
proration_date = Time.now + 5 * 24 * 3600 # 5 days later
|
256
|
+
new_quantity = 2
|
257
|
+
unused_amount = plan.amount * quantity * (subscription.current_period_end - proration_date.to_i) / (subscription.current_period_end - subscription.current_period_start)
|
258
|
+
prorated_amount_due = new_plan.amount * new_quantity - unused_amount
|
259
|
+
credit_balance = 1000
|
260
|
+
customer.account_balance = -credit_balance
|
261
|
+
customer.save
|
262
|
+
query = { customer: customer.id, subscription: subscription.id, subscription_plan: new_plan.id, subscription_proration_date: proration_date.to_i, subscription_quantity: new_quantity }
|
263
|
+
query[:subscription_trial_end] = (DateTime.now >> 1).to_time.to_i if with_trial
|
264
|
+
|
265
|
+
# When
|
266
|
+
upcoming = Stripe::Invoice.upcoming(query)
|
267
|
+
|
268
|
+
# Then
|
269
|
+
expect(upcoming).to be_a Stripe::Invoice
|
270
|
+
expect(upcoming.customer).to eq(customer.id)
|
271
|
+
if with_trial
|
272
|
+
expect(upcoming.amount_due).to eq 0
|
273
|
+
else
|
274
|
+
expect(upcoming.amount_due).to be_within(1).of prorated_amount_due - credit_balance
|
275
|
+
end
|
276
|
+
expect(upcoming.starting_balance).to eq -credit_balance
|
277
|
+
expect(upcoming.ending_balance).to be_nil
|
278
|
+
expect(upcoming.subscription).to eq(subscription.id)
|
279
|
+
expect(upcoming.lines.data[0].proration).to be_truthy
|
280
|
+
expect(upcoming.lines.data[0].plan.id).to eq '50m'
|
281
|
+
expect(upcoming.lines.data[0].amount).to be_within(1).of -unused_amount
|
282
|
+
expect(upcoming.lines.data[0].quantity).to eq quantity
|
283
|
+
expect(upcoming.lines.data[1].proration).to be_falsey
|
284
|
+
expect(upcoming.lines.data[1].plan.id).to eq '100y'
|
285
|
+
expect(upcoming.lines.data[1].amount).to eq with_trial ? 0 : 20000
|
286
|
+
expect(upcoming.lines.data[1].quantity).to eq new_quantity
|
287
|
+
end
|
288
|
+
|
289
|
+
after { new_plan.delete }
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
shared_examples 'no proration is done' do
|
294
|
+
it 'generates a preview without performing an actual proration', live: true do
|
295
|
+
expect(preview.subtotal).to eq 150_00
|
296
|
+
# this is a future invoice (generted at the end of the current subscription cycle), rather than a proration invoice
|
297
|
+
expect(preview.date).to be_within(1).of subscription.current_period_end
|
298
|
+
expect(preview.period_start).to eq subscription.current_period_start
|
299
|
+
expect(preview.period_end).to eq subscription.current_period_end
|
300
|
+
expect(preview.lines.count).to eq 1
|
301
|
+
line = preview.lines.first
|
302
|
+
expect(line.type).to eq 'subscription'
|
303
|
+
expect(line.amount).to eq 150_00
|
304
|
+
# line period is for the NEXT subscription cycle
|
305
|
+
expect(line.period.start).to be_within(1).of subscription.current_period_end
|
306
|
+
expect(line.period.end).to be_within(1).of (Time.at(subscription.current_period_end).to_datetime >> 1).to_time.to_i # +1 month
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
describe 'upcoming invoice with no proration parameters specified' do
|
311
|
+
let(:preview) do
|
312
|
+
Stripe::Invoice.upcoming(
|
313
|
+
customer: customer.id,
|
314
|
+
subscription: subscription.id
|
315
|
+
)
|
316
|
+
end
|
317
|
+
|
318
|
+
it_behaves_like 'no proration is done'
|
319
|
+
end
|
320
|
+
|
321
|
+
describe 'upcoming invoice with same subscription plan and quantity specified' do
|
322
|
+
let(:preview) do
|
323
|
+
proration_date = Time.now + 60
|
324
|
+
Stripe::Invoice.upcoming(
|
325
|
+
customer: customer.id,
|
326
|
+
subscription: subscription.id,
|
327
|
+
subscription_plan: plan.id,
|
328
|
+
subscription_quantity: quantity,
|
329
|
+
subscription_proration_date: proration_date.to_i,
|
330
|
+
subscription_trial_end: nil
|
331
|
+
)
|
332
|
+
end
|
333
|
+
|
334
|
+
it_behaves_like 'no proration is done'
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
154
338
|
it 'sets the start and end of billing periods correctly when plan has an interval_count' do
|
155
339
|
@oddplan = stripe_helper.create_plan(interval: "week", interval_count: 11)
|
156
|
-
@subscription = Stripe::Subscription.create(plan: @oddplan.id, customer:
|
157
|
-
@upcoming = Stripe::Invoice.upcoming(customer:
|
340
|
+
@subscription = Stripe::Subscription.create(plan: @oddplan.id, customer: customer.id)
|
341
|
+
@upcoming = Stripe::Invoice.upcoming(customer: customer.id)
|
158
342
|
|
159
343
|
expect(@upcoming.period_start + 6652800).to eq(@upcoming.period_end) # 6652800 = +11 weeks
|
160
344
|
expect(@upcoming.period_end).to eq(@upcoming.lines.data[0].period.start)
|
@@ -167,11 +351,11 @@ shared_examples 'Invoice API' do
|
|
167
351
|
@plainplan = stripe_helper.create_plan(id: 'b') # 1 month sub
|
168
352
|
@longplan = stripe_helper.create_plan(id: 'c', interval: "year") # 1 year sub
|
169
353
|
|
170
|
-
@plainsub = Stripe::Subscription.create(plan: @plainplan.id, customer:
|
171
|
-
@shortsub = Stripe::Subscription.create(plan: @shortplan.id, customer:
|
172
|
-
@longsub = Stripe::Subscription.create(plan: @longplan.id, customer:
|
354
|
+
@plainsub = Stripe::Subscription.create(plan: @plainplan.id, customer: customer.id)
|
355
|
+
@shortsub = Stripe::Subscription.create(plan: @shortplan.id, customer: customer.id)
|
356
|
+
@longsub = Stripe::Subscription.create(plan: @longplan.id, customer: customer.id)
|
173
357
|
|
174
|
-
@upcoming = Stripe::Invoice.upcoming(customer:
|
358
|
+
@upcoming = Stripe::Invoice.upcoming(customer: customer.id)
|
175
359
|
|
176
360
|
expect(@upcoming.period_start + 604800).to eq(@upcoming.period_end) # 604800 = 1 week
|
177
361
|
expect(@upcoming.period_end + 604800).to eq(@upcoming.lines.data[0].period.end) # 604800 = 1 week
|
@@ -180,7 +364,7 @@ shared_examples 'Invoice API' do
|
|
180
364
|
|
181
365
|
context 'retrieving invoice line items' do
|
182
366
|
it 'returns all line items for created invoice' do
|
183
|
-
invoice = Stripe::Invoice.create(customer:
|
367
|
+
invoice = Stripe::Invoice.create(customer: customer.id)
|
184
368
|
line_items = invoice.lines.all
|
185
369
|
|
186
370
|
expect(invoice).to be_a Stripe::Invoice
|
@@ -192,8 +376,8 @@ shared_examples 'Invoice API' do
|
|
192
376
|
|
193
377
|
it 'returns all line items for upcoming invoice' do
|
194
378
|
plan = stripe_helper.create_plan()
|
195
|
-
subscription = Stripe::Subscription.create(plan: plan.id, customer:
|
196
|
-
upcoming = Stripe::Invoice.upcoming(customer:
|
379
|
+
subscription = Stripe::Subscription.create(plan: plan.id, customer: customer.id)
|
380
|
+
upcoming = Stripe::Invoice.upcoming(customer: customer.id)
|
197
381
|
line_items = upcoming.lines.all
|
198
382
|
|
199
383
|
expect(upcoming).to be_a Stripe::Invoice
|
@@ -208,8 +392,8 @@ shared_examples 'Invoice API' do
|
|
208
392
|
|
209
393
|
it 'for one month plan on the 1st' do
|
210
394
|
@plan = stripe_helper.create_plan()
|
211
|
-
@sub = Stripe::Subscription.create(plan: @plan.id, customer:
|
212
|
-
@upcoming = Stripe::Invoice.upcoming(customer:
|
395
|
+
@sub = Stripe::Subscription.create(plan: @plan.id, customer: customer.id, current_period_start: Time.utc(2014,1,1,12).to_i)
|
396
|
+
@upcoming = Stripe::Invoice.upcoming(customer: customer.id)
|
213
397
|
|
214
398
|
expect(Time.at(@upcoming.period_start)).to eq(Time.utc(2014,1,1,12))
|
215
399
|
expect(Time.at(@upcoming.period_end)).to eq(Time.utc(2014,2,1,12))
|
@@ -219,8 +403,8 @@ shared_examples 'Invoice API' do
|
|
219
403
|
|
220
404
|
it 'for one year plan on the 1st' do
|
221
405
|
@plan = stripe_helper.create_plan(interval: "year")
|
222
|
-
@sub = Stripe::Subscription.create(plan: @plan.id, customer:
|
223
|
-
@upcoming = Stripe::Invoice.upcoming(customer:
|
406
|
+
@sub = Stripe::Subscription.create(plan: @plan.id, customer: customer.id, current_period_start: Time.utc(2012,1,1,12).to_i)
|
407
|
+
@upcoming = Stripe::Invoice.upcoming(customer: customer.id)
|
224
408
|
|
225
409
|
expect(Time.at(@upcoming.period_start)).to eq(Time.utc(2012,1,1,12))
|
226
410
|
expect(Time.at(@upcoming.period_end)).to eq(Time.utc(2013,1,1,12))
|
@@ -230,8 +414,8 @@ shared_examples 'Invoice API' do
|
|
230
414
|
|
231
415
|
it 'for one month plan on the 31st' do
|
232
416
|
@plan = stripe_helper.create_plan()
|
233
|
-
@sub = Stripe::Subscription.create(plan: @plan.id, customer:
|
234
|
-
@upcoming = Stripe::Invoice.upcoming(customer:
|
417
|
+
@sub = Stripe::Subscription.create(plan: @plan.id, customer: customer.id, current_period_start: Time.utc(2014,1,31,12).to_i)
|
418
|
+
@upcoming = Stripe::Invoice.upcoming(customer: customer.id)
|
235
419
|
|
236
420
|
expect(Time.at(@upcoming.period_start)).to eq(Time.utc(2014,1,31,12))
|
237
421
|
expect(Time.at(@upcoming.period_end)).to eq(Time.utc(2014,2,28,12))
|
@@ -241,8 +425,8 @@ shared_examples 'Invoice API' do
|
|
241
425
|
|
242
426
|
it 'for one year plan on feb. 29th' do
|
243
427
|
@plan = stripe_helper.create_plan(interval: "year")
|
244
|
-
@sub = Stripe::Subscription.create(plan: @plan.id, customer:
|
245
|
-
@upcoming = Stripe::Invoice.upcoming(customer:
|
428
|
+
@sub = Stripe::Subscription.create(plan: @plan.id, customer: customer.id, current_period_start: Time.utc(2012,2,29,12).to_i)
|
429
|
+
@upcoming = Stripe::Invoice.upcoming(customer: customer.id)
|
246
430
|
|
247
431
|
expect(Time.at(@upcoming.period_start)).to eq(Time.utc(2012,2,29,12))
|
248
432
|
expect(Time.at(@upcoming.period_end)).to eq(Time.utc(2013,2,28,12))
|
@@ -252,8 +436,8 @@ shared_examples 'Invoice API' do
|
|
252
436
|
|
253
437
|
it 'for two month plan on dec. 31st' do
|
254
438
|
@plan = stripe_helper.create_plan(interval_count: 2)
|
255
|
-
@sub = Stripe::Subscription.create(plan: @plan.id, customer:
|
256
|
-
@upcoming = Stripe::Invoice.upcoming(customer:
|
439
|
+
@sub = Stripe::Subscription.create(plan: @plan.id, customer: customer.id, current_period_start: Time.utc(2013,12,31,12).to_i)
|
440
|
+
@upcoming = Stripe::Invoice.upcoming(customer: customer.id)
|
257
441
|
|
258
442
|
expect(Time.at(@upcoming.period_start)).to eq(Time.utc(2013,12,31,12))
|
259
443
|
expect(Time.at(@upcoming.period_end)).to eq(Time.utc(2014, 2,28,12))
|
@@ -263,8 +447,8 @@ shared_examples 'Invoice API' do
|
|
263
447
|
|
264
448
|
it 'for three month plan on nov. 30th' do
|
265
449
|
@plan = stripe_helper.create_plan(interval_count: 3)
|
266
|
-
@sub = Stripe::Subscription.create(plan: @plan.id, customer:
|
267
|
-
@upcoming = Stripe::Invoice.upcoming(customer:
|
450
|
+
@sub = Stripe::Subscription.create(plan: @plan.id, customer: customer.id, current_period_start: Time.utc(2013,11,30,12).to_i)
|
451
|
+
@upcoming = Stripe::Invoice.upcoming(customer: customer.id)
|
268
452
|
|
269
453
|
expect(Time.at(@upcoming.period_start)).to eq(Time.utc(2013,11,30,12))
|
270
454
|
expect(Time.at(@upcoming.period_end)).to eq(Time.utc(2014, 2,28,12))
|