reji 1.0.0 → 1.1.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/.gitignore +1 -0
- data/.rubocop.yml +73 -0
- data/.rubocop_todo.yml +31 -0
- data/Appraisals +2 -0
- data/Gemfile +1 -1
- data/README.md +41 -17
- data/Rakefile +8 -2
- data/app/controllers/reji/payment_controller.rb +4 -4
- data/app/controllers/reji/webhook_controller.rb +51 -62
- data/app/views/payment.html.erb +4 -4
- data/app/views/receipt.html.erb +16 -16
- data/config/routes.rb +2 -0
- data/gemfiles/rails_5.0.gemfile +9 -9
- data/gemfiles/rails_5.1.gemfile +7 -9
- data/gemfiles/rails_5.2.gemfile +7 -9
- data/gemfiles/rails_6.0.gemfile +7 -9
- data/lib/generators/reji/install/install_generator.rb +20 -24
- data/lib/generators/reji/install/templates/reji.rb +2 -2
- data/lib/reji.rb +12 -8
- data/lib/reji/concerns/manages_customer.rb +25 -29
- data/lib/reji/concerns/manages_invoices.rb +37 -44
- data/lib/reji/concerns/manages_payment_methods.rb +45 -62
- data/lib/reji/concerns/manages_subscriptions.rb +13 -13
- data/lib/reji/concerns/performs_charges.rb +7 -7
- data/lib/reji/concerns/prorates.rb +1 -1
- data/lib/reji/configuration.rb +2 -2
- data/lib/reji/engine.rb +2 -0
- data/lib/reji/errors.rb +9 -9
- data/lib/reji/invoice.rb +57 -56
- data/lib/reji/invoice_line_item.rb +21 -23
- data/lib/reji/payment.rb +9 -5
- data/lib/reji/payment_method.rb +8 -4
- data/lib/reji/subscription.rb +165 -183
- data/lib/reji/subscription_builder.rb +41 -49
- data/lib/reji/subscription_item.rb +26 -26
- data/lib/reji/tax.rb +8 -10
- data/lib/reji/version.rb +1 -1
- data/reji.gemspec +5 -4
- data/spec/dummy/app/models/user.rb +3 -7
- data/spec/dummy/application.rb +3 -7
- data/spec/dummy/db/schema.rb +3 -4
- data/spec/feature/charges_spec.rb +1 -1
- data/spec/feature/customer_spec.rb +1 -1
- data/spec/feature/invoices_spec.rb +6 -6
- data/spec/feature/multiplan_subscriptions_spec.rb +51 -53
- data/spec/feature/payment_methods_spec.rb +25 -25
- data/spec/feature/pending_updates_spec.rb +26 -26
- data/spec/feature/subscriptions_spec.rb +78 -78
- data/spec/feature/webhooks_spec.rb +72 -72
- data/spec/spec_helper.rb +2 -2
- data/spec/support/feature_helpers.rb +6 -12
- data/spec/unit/customer_spec.rb +13 -13
- data/spec/unit/invoice_line_item_spec.rb +12 -14
- data/spec/unit/invoice_spec.rb +7 -9
- data/spec/unit/payment_spec.rb +3 -3
- data/spec/unit/subscription_spec.rb +29 -30
- metadata +26 -11
- data/Gemfile.lock +0 -133
@@ -11,55 +11,55 @@ describe 'subscriptions', type: :request do
|
|
11
11
|
@coupon_id = "#{stripe_prefix}coupon-#{SecureRandom.hex(5)}"
|
12
12
|
|
13
13
|
Stripe::Product.create({
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
14
|
+
id: @product_id,
|
15
|
+
name: 'Rails Reji Test Product',
|
16
|
+
type: 'service',
|
17
17
|
})
|
18
18
|
|
19
19
|
Stripe::Plan.create({
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
20
|
+
id: @plan_id,
|
21
|
+
nickname: 'Monthly $10',
|
22
|
+
currency: 'USD',
|
23
|
+
interval: 'month',
|
24
|
+
billing_scheme: 'per_unit',
|
25
|
+
amount: 1000,
|
26
|
+
product: @product_id,
|
27
27
|
})
|
28
28
|
|
29
29
|
Stripe::Plan.create({
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:
|
30
|
+
id: @other_plan_id,
|
31
|
+
nickname: 'Monthly $10 Other',
|
32
|
+
currency: 'USD',
|
33
|
+
interval: 'month',
|
34
|
+
billing_scheme: 'per_unit',
|
35
|
+
amount: 1000,
|
36
|
+
product: @product_id,
|
37
37
|
})
|
38
38
|
|
39
39
|
Stripe::Plan.create({
|
40
|
-
:
|
41
|
-
:
|
42
|
-
:
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
40
|
+
id: @premium_plan_id,
|
41
|
+
nickname: 'Monthly $20 Premium',
|
42
|
+
currency: 'USD',
|
43
|
+
interval: 'month',
|
44
|
+
billing_scheme: 'per_unit',
|
45
|
+
amount: 2000,
|
46
|
+
product: @product_id,
|
47
47
|
})
|
48
48
|
|
49
49
|
Stripe::Coupon.create({
|
50
|
-
:
|
51
|
-
:
|
52
|
-
:
|
53
|
-
:
|
54
|
-
:
|
50
|
+
id: @coupon_id,
|
51
|
+
duration: 'repeating',
|
52
|
+
amount_off: 500,
|
53
|
+
duration_in_months: 3,
|
54
|
+
currency: 'USD',
|
55
55
|
})
|
56
56
|
|
57
57
|
@tax_rate_id = Stripe::TaxRate.create({
|
58
|
-
:
|
59
|
-
:
|
60
|
-
:
|
61
|
-
:
|
62
|
-
:
|
58
|
+
display_name: 'VAT',
|
59
|
+
description: 'VAT Belgium',
|
60
|
+
jurisdiction: 'BE',
|
61
|
+
percentage: 21,
|
62
|
+
inclusive: false,
|
63
63
|
}).id
|
64
64
|
end
|
65
65
|
|
@@ -104,7 +104,7 @@ describe 'subscriptions', type: :request do
|
|
104
104
|
|
105
105
|
# Modify Ends Date To Past
|
106
106
|
old_grace_period = subscription.ends_at
|
107
|
-
subscription.update({:
|
107
|
+
subscription.update({ ends_at: Time.current - 5.days })
|
108
108
|
|
109
109
|
expect(subscription.active).to be false
|
110
110
|
expect(subscription.cancelled).to be true
|
@@ -112,7 +112,7 @@ describe 'subscriptions', type: :request do
|
|
112
112
|
expect(subscription.recurring).to be false
|
113
113
|
expect(subscription.ended).to be true
|
114
114
|
|
115
|
-
subscription.update({:
|
115
|
+
subscription.update({ ends_at: old_grace_period })
|
116
116
|
|
117
117
|
# Resume Subscription
|
118
118
|
subscription.resume
|
@@ -141,8 +141,8 @@ describe 'subscriptions', type: :request do
|
|
141
141
|
invoice = user.invoices.last
|
142
142
|
|
143
143
|
expect(invoice.total).to eq('$10.00')
|
144
|
-
expect(invoice.
|
145
|
-
expect(invoice.
|
144
|
+
expect(invoice.discount?).to be false
|
145
|
+
expect(invoice.starting_balance?).to be false
|
146
146
|
expect(invoice.coupon).to be_nil
|
147
147
|
end
|
148
148
|
|
@@ -151,7 +151,7 @@ describe 'subscriptions', type: :request do
|
|
151
151
|
user.new_subscription('main', @plan_id).create('pm_card_visa')
|
152
152
|
subscription = user.subscription('main')
|
153
153
|
|
154
|
-
subscription.swap(@other_plan_id, {:
|
154
|
+
subscription.swap(@other_plan_id, { coupon: @coupon_id })
|
155
155
|
|
156
156
|
expect(subscription.as_stripe_subscription.discount.coupon.id).to eq(@coupon_id)
|
157
157
|
end
|
@@ -162,7 +162,7 @@ describe 'subscriptions', type: :request do
|
|
162
162
|
begin
|
163
163
|
user.new_subscription('main', @plan_id).create('pm_card_chargeCustomerFail')
|
164
164
|
|
165
|
-
raise RSpec::Expectations::ExpectationNotMetError
|
165
|
+
raise RSpec::Expectations::ExpectationNotMetError, 'Expected exception PaymentFailureError was not thrown.'
|
166
166
|
rescue Reji::PaymentFailureError => e
|
167
167
|
# Assert that the payment needs a valid payment method.
|
168
168
|
expect(e.payment.requires_payment_method).to be true
|
@@ -182,7 +182,7 @@ describe 'subscriptions', type: :request do
|
|
182
182
|
begin
|
183
183
|
user.new_subscription('main', @plan_id).create('pm_card_threeDSecure2Required')
|
184
184
|
|
185
|
-
raise RSpec::Expectations::ExpectationNotMetError
|
185
|
+
raise RSpec::Expectations::ExpectationNotMetError, 'Expected exception PaymentActionRequiredError was not thrown.'
|
186
186
|
rescue Reji::PaymentActionRequiredError => e
|
187
187
|
# Assert that the payment needs an extra action.
|
188
188
|
expect(e.payment.requires_action).to be true
|
@@ -208,7 +208,7 @@ describe 'subscriptions', type: :request do
|
|
208
208
|
# Attempt to swap and pay with a faulty card.
|
209
209
|
subscription = subscription.swap_and_invoice(@premium_plan_id)
|
210
210
|
|
211
|
-
raise RSpec::Expectations::ExpectationNotMetError
|
211
|
+
raise RSpec::Expectations::ExpectationNotMetError, 'Expected exception PaymentFailureError was not thrown.'
|
212
212
|
rescue Reji::PaymentFailureError => e
|
213
213
|
# Assert that the payment needs a valid payment method.
|
214
214
|
expect(e.payment.requires_payment_method).to be true
|
@@ -233,7 +233,7 @@ describe 'subscriptions', type: :request do
|
|
233
233
|
# Attempt to swap and pay with a faulty card.
|
234
234
|
subscription = subscription.swap_and_invoice(@premium_plan_id)
|
235
235
|
|
236
|
-
raise RSpec::Expectations::ExpectationNotMetError
|
236
|
+
raise RSpec::Expectations::ExpectationNotMetError, 'Expected exception PaymentActionRequiredError was not thrown.'
|
237
237
|
rescue Reji::PaymentActionRequiredError => e
|
238
238
|
# Assert that the payment needs an extra action.
|
239
239
|
expect(e.payment.requires_action).to be true
|
@@ -304,7 +304,7 @@ describe 'subscriptions', type: :request do
|
|
304
304
|
# Invoice Tests
|
305
305
|
invoice = user.invoices.first
|
306
306
|
|
307
|
-
expect(invoice.
|
307
|
+
expect(invoice.discount?).to be true
|
308
308
|
expect(invoice.total).to eq('$5.00')
|
309
309
|
expect(invoice.amount_off).to eq('$5.00')
|
310
310
|
expect(invoice.discount_is_percentage).to be false
|
@@ -315,7 +315,7 @@ describe 'subscriptions', type: :request do
|
|
315
315
|
|
316
316
|
# Create Subscription
|
317
317
|
user.new_subscription('main', @plan_id)
|
318
|
-
.anchor_billing_cycle_on(Time.
|
318
|
+
.anchor_billing_cycle_on(Time.current.next_month.at_beginning_of_month.to_i)
|
319
319
|
.create('pm_card_visa')
|
320
320
|
|
321
321
|
subscription = user.subscription('main')
|
@@ -333,8 +333,8 @@ describe 'subscriptions', type: :request do
|
|
333
333
|
invoice = user.invoices.first
|
334
334
|
invoice_period = invoice.invoice_items.first.period
|
335
335
|
|
336
|
-
expect(Time.at(invoice_period.start).strftime('%Y-%m-%d')).to eq(Time.
|
337
|
-
expect(Time.at(invoice_period.end).strftime('%Y-%m-%d')).to eq(Time.
|
336
|
+
expect(Time.zone.at(invoice_period.start).strftime('%Y-%m-%d')).to eq(Time.current.strftime('%Y-%m-%d'))
|
337
|
+
expect(Time.zone.at(invoice_period.end).strftime('%Y-%m-%d')).to eq(Time.current.next_month.at_beginning_of_month.strftime('%Y-%m-%d'))
|
338
338
|
end
|
339
339
|
|
340
340
|
it 'test_creating_subscription_with_trial' do
|
@@ -351,7 +351,7 @@ describe 'subscriptions', type: :request do
|
|
351
351
|
expect(subscription.on_trial).to be true
|
352
352
|
expect(subscription.recurring).to be false
|
353
353
|
expect(subscription.ended).to be false
|
354
|
-
expect(Time.at(subscription.trial_ends_at).strftime('%Y-%m-%d')).to eq((Time.
|
354
|
+
expect(Time.zone.at(subscription.trial_ends_at).strftime('%Y-%m-%d')).to eq((Time.current + 7.days).strftime('%Y-%m-%d'))
|
355
355
|
|
356
356
|
# Cancel Subscription
|
357
357
|
subscription.cancel
|
@@ -369,7 +369,7 @@ describe 'subscriptions', type: :request do
|
|
369
369
|
expect(subscription.on_trial).to be true
|
370
370
|
expect(subscription.recurring).to be false
|
371
371
|
expect(subscription.ended).to be false
|
372
|
-
expect(Time.at(subscription.trial_ends_at).day).to eq((Time.
|
372
|
+
expect(Time.zone.at(subscription.trial_ends_at).day).to eq((Time.current + 7.days).day)
|
373
373
|
end
|
374
374
|
|
375
375
|
it 'test_creating_subscription_with_explicit_trial' do
|
@@ -377,7 +377,7 @@ describe 'subscriptions', type: :request do
|
|
377
377
|
|
378
378
|
# Create Subscription
|
379
379
|
user.new_subscription('main', @plan_id)
|
380
|
-
.trial_until(Time.
|
380
|
+
.trial_until(Time.current + 1.day + 3.hours + 15.minutes)
|
381
381
|
.create('pm_card_visa')
|
382
382
|
|
383
383
|
subscription = user.subscription('main')
|
@@ -386,7 +386,7 @@ describe 'subscriptions', type: :request do
|
|
386
386
|
expect(subscription.on_trial).to be true
|
387
387
|
expect(subscription.recurring).to be false
|
388
388
|
expect(subscription.ended).to be false
|
389
|
-
expect(Time.at(subscription.trial_ends_at).strftime('%Y-%m-%d')).to eq((Time.
|
389
|
+
expect(Time.zone.at(subscription.trial_ends_at).strftime('%Y-%m-%d')).to eq((Time.current + 1.day + 3.hours + 15.minutes).strftime('%Y-%m-%d'))
|
390
390
|
|
391
391
|
# Cancel Subscription
|
392
392
|
subscription.cancel
|
@@ -404,7 +404,7 @@ describe 'subscriptions', type: :request do
|
|
404
404
|
expect(subscription.on_trial).to be true
|
405
405
|
expect(subscription.recurring).to be false
|
406
406
|
expect(subscription.ended).to be false
|
407
|
-
expect(Time.at(subscription.trial_ends_at).day).to eq((Time.
|
407
|
+
expect(Time.zone.at(subscription.trial_ends_at).day).to eq((Time.current + 1.day + 3.hours + 15.minutes).day)
|
408
408
|
end
|
409
409
|
|
410
410
|
it 'test_subscription_changes_can_be_prorated' do
|
@@ -442,10 +442,10 @@ describe 'subscriptions', type: :request do
|
|
442
442
|
subscription = user.new_subscription('main', @plan_id)
|
443
443
|
.no_prorate
|
444
444
|
.create('pm_card_visa', {}, {
|
445
|
-
:
|
446
|
-
:
|
447
|
-
:
|
448
|
-
:
|
445
|
+
collection_method: 'send_invoice',
|
446
|
+
days_until_due: 30,
|
447
|
+
backdate_start_date: (Time.current + 5.days - 1.year).beginning_of_day.to_i,
|
448
|
+
billing_cycle_anchor: (Time.current + 5.days).beginning_of_day.to_i,
|
449
449
|
})
|
450
450
|
|
451
451
|
expect(subscription.stripe_plan).to eq(@plan_id)
|
@@ -463,10 +463,10 @@ describe 'subscriptions', type: :request do
|
|
463
463
|
subscription = user.new_subscription('main', @plan_id)
|
464
464
|
.no_prorate
|
465
465
|
.create('pm_card_visa', {}, {
|
466
|
-
:
|
467
|
-
:
|
468
|
-
:
|
469
|
-
:
|
466
|
+
collection_method: 'send_invoice',
|
467
|
+
days_until_due: 30,
|
468
|
+
backdate_start_date: (Time.current + 5.days - 1.year).beginning_of_day.to_i,
|
469
|
+
billing_cycle_anchor: (Time.current + 5.days).beginning_of_day.to_i,
|
470
470
|
})
|
471
471
|
|
472
472
|
expect(subscription.stripe_plan).to eq(@plan_id)
|
@@ -489,7 +489,7 @@ describe 'subscriptions', type: :request do
|
|
489
489
|
|
490
490
|
expect(subscription.trial_ends_at).to be_nil
|
491
491
|
|
492
|
-
trial_ends_at = Time.
|
492
|
+
trial_ends_at = Time.current + 1.day
|
493
493
|
|
494
494
|
subscription.extend_trial(trial_ends_at)
|
495
495
|
|
@@ -514,13 +514,13 @@ describe 'subscriptions', type: :request do
|
|
514
514
|
|
515
515
|
# Start with an incomplete subscription.
|
516
516
|
subscription = user.subscriptions.create({
|
517
|
-
:
|
518
|
-
:
|
519
|
-
:
|
520
|
-
:
|
521
|
-
:
|
522
|
-
:
|
523
|
-
:
|
517
|
+
name: 'yearly',
|
518
|
+
stripe_id: 'xxxx',
|
519
|
+
stripe_status: 'incomplete',
|
520
|
+
stripe_plan: 'stripe-yearly',
|
521
|
+
quantity: 1,
|
522
|
+
trial_ends_at: nil,
|
523
|
+
ends_at: nil,
|
524
524
|
})
|
525
525
|
|
526
526
|
# Subscription is incomplete
|
@@ -536,7 +536,7 @@ describe 'subscriptions', type: :request do
|
|
536
536
|
expect(user.subscriptions.ended.exists?).to be false
|
537
537
|
|
538
538
|
# Activate.
|
539
|
-
subscription.update({:
|
539
|
+
subscription.update({ stripe_status: 'active' })
|
540
540
|
|
541
541
|
expect(user.subscriptions.incomplete.exists?).to be false
|
542
542
|
expect(user.subscriptions.active.exists?).to be true
|
@@ -550,7 +550,7 @@ describe 'subscriptions', type: :request do
|
|
550
550
|
expect(user.subscriptions.ended.exists?).to be false
|
551
551
|
|
552
552
|
# Put on trial.
|
553
|
-
subscription.update({:
|
553
|
+
subscription.update({ trial_ends_at: Time.current + 1.day })
|
554
554
|
|
555
555
|
expect(user.subscriptions.incomplete.exists?).to be false
|
556
556
|
expect(user.subscriptions.active.exists?).to be true
|
@@ -564,7 +564,7 @@ describe 'subscriptions', type: :request do
|
|
564
564
|
expect(user.subscriptions.ended.exists?).to be false
|
565
565
|
|
566
566
|
# Put on grace period.
|
567
|
-
subscription.update({:
|
567
|
+
subscription.update({ ends_at: Time.current + 1.day })
|
568
568
|
|
569
569
|
expect(user.subscriptions.incomplete.exists?).to be false
|
570
570
|
expect(user.subscriptions.active.exists?).to be true
|
@@ -578,7 +578,7 @@ describe 'subscriptions', type: :request do
|
|
578
578
|
expect(user.subscriptions.ended.exists?).to be false
|
579
579
|
|
580
580
|
# End subscription.
|
581
|
-
subscription.update({:
|
581
|
+
subscription.update({ ends_at: Time.current - 1.day })
|
582
582
|
|
583
583
|
expect(user.subscriptions.incomplete.exists?).to be false
|
584
584
|
expect(user.subscriptions.active.exists?).to be false
|
@@ -598,8 +598,8 @@ describe 'subscriptions', type: :request do
|
|
598
598
|
Reji.keep_past_due_subscriptions_active
|
599
599
|
|
600
600
|
subscription.update({
|
601
|
-
:
|
602
|
-
:
|
601
|
+
ends_at: nil,
|
602
|
+
stripe_status: 'past_due',
|
603
603
|
})
|
604
604
|
|
605
605
|
expect(subscription.active).to be true
|
@@ -615,8 +615,8 @@ describe 'subscriptions', type: :request do
|
|
615
615
|
begin
|
616
616
|
user.new_subscription('main', @plan_id).create('pm_card_threeDSecure2Required')
|
617
617
|
|
618
|
-
raise RSpec::Expectations::ExpectationNotMetError
|
619
|
-
rescue Reji::PaymentActionRequiredError =>
|
618
|
+
raise RSpec::Expectations::ExpectationNotMetError, 'Expected exception PaymentActionRequiredError was not thrown.'
|
619
|
+
rescue Reji::PaymentActionRequiredError => _e
|
620
620
|
subscription = user.subscription('main')
|
621
621
|
|
622
622
|
payment = subscription.latest_payment
|
@@ -639,9 +639,9 @@ describe 'subscriptions', type: :request do
|
|
639
639
|
it 'test_subscriptions_with_options_can_be_created' do
|
640
640
|
user = create_customer('subscriptions_with_options_can_be_created')
|
641
641
|
|
642
|
-
backdate_start_date = (Time.
|
642
|
+
backdate_start_date = (Time.current - 1.month).to_i
|
643
643
|
subscription = user.new_subscription('main', @plan_id).create(
|
644
|
-
'pm_card_visa', {}, {:backdate_start_date
|
644
|
+
'pm_card_visa', {}, { backdate_start_date: backdate_start_date }
|
645
645
|
)
|
646
646
|
stripe_subscription = subscription.as_stripe_subscription
|
647
647
|
|
@@ -8,19 +8,19 @@ describe 'webhooks', type: :request do
|
|
8
8
|
@plan_id = "#{stripe_prefix}monthly-10-#{SecureRandom.hex(5)}"
|
9
9
|
|
10
10
|
Stripe::Product.create({
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
11
|
+
id: @product_id,
|
12
|
+
name: 'Rails Reji Test Product',
|
13
|
+
type: 'service',
|
14
14
|
})
|
15
15
|
|
16
16
|
Stripe::Plan.create({
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
17
|
+
id: @plan_id,
|
18
|
+
nickname: 'Monthly $10',
|
19
|
+
currency: 'USD',
|
20
|
+
interval: 'month',
|
21
|
+
billing_scheme: 'per_unit',
|
22
|
+
amount: 1000,
|
23
|
+
product: @product_id,
|
24
24
|
})
|
25
25
|
end
|
26
26
|
|
@@ -30,61 +30,61 @@ describe 'webhooks', type: :request do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'test_subscriptions_are_updated' do
|
33
|
-
user = create_customer('subscriptions_are_updated', {:
|
33
|
+
user = create_customer('subscriptions_are_updated', { stripe_id: 'cus_foo' })
|
34
34
|
|
35
35
|
subscription = user.subscriptions.create({
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:
|
36
|
+
name: 'main',
|
37
|
+
stripe_id: 'sub_foo',
|
38
|
+
stripe_plan: 'plan_foo',
|
39
|
+
stripe_status: 'active',
|
40
40
|
})
|
41
41
|
|
42
42
|
item = subscription.items.create({
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
43
|
+
stripe_id: 'it_foo',
|
44
|
+
stripe_plan: 'plan_bar',
|
45
|
+
quantity: 1,
|
46
46
|
})
|
47
47
|
|
48
|
-
post '/stripe/webhook', :
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
52
|
-
:
|
53
|
-
:
|
54
|
-
:
|
55
|
-
:
|
56
|
-
:
|
57
|
-
:
|
58
|
-
:
|
48
|
+
post '/stripe/webhook', params: {
|
49
|
+
id: 'foo',
|
50
|
+
type: 'customer.subscription.updated',
|
51
|
+
data: {
|
52
|
+
object: {
|
53
|
+
id: subscription.stripe_id,
|
54
|
+
customer: 'cus_foo',
|
55
|
+
cancel_at_period_end: false,
|
56
|
+
quantity: 5,
|
57
|
+
items: {
|
58
|
+
data: [
|
59
59
|
{
|
60
|
-
:
|
61
|
-
:
|
62
|
-
:
|
63
|
-
}
|
60
|
+
id: 'bar',
|
61
|
+
plan: { id: 'plan_foo' },
|
62
|
+
quantity: 10,
|
63
|
+
},
|
64
64
|
],
|
65
65
|
},
|
66
66
|
},
|
67
67
|
},
|
68
|
-
}.to_json, :
|
68
|
+
}.to_json, headers: { 'CONTENT_TYPE' => 'application/json' }
|
69
69
|
|
70
70
|
expect(response.status).to eq(200)
|
71
71
|
|
72
72
|
expect(Reji::Subscription.where({
|
73
|
-
:
|
74
|
-
:
|
75
|
-
:
|
76
|
-
:
|
73
|
+
id: subscription.id,
|
74
|
+
user_id: user.id,
|
75
|
+
stripe_id: 'sub_foo',
|
76
|
+
quantity: 5,
|
77
77
|
}).exists?).to be true
|
78
78
|
|
79
79
|
expect(Reji::SubscriptionItem.where({
|
80
|
-
:
|
81
|
-
:
|
82
|
-
:
|
83
|
-
:
|
80
|
+
subscription_id: subscription.id,
|
81
|
+
stripe_id: 'bar',
|
82
|
+
stripe_plan: 'plan_foo',
|
83
|
+
quantity: 10,
|
84
84
|
}).exists?).to be true
|
85
85
|
|
86
86
|
expect(Reji::SubscriptionItem.where({
|
87
|
-
:
|
87
|
+
id: item.id,
|
88
88
|
}).exists?).to be false
|
89
89
|
end
|
90
90
|
|
@@ -95,18 +95,18 @@ describe 'webhooks', type: :request do
|
|
95
95
|
|
96
96
|
expect(subscription.cancelled).to be true
|
97
97
|
|
98
|
-
post '/stripe/webhook', :
|
99
|
-
:
|
100
|
-
:
|
101
|
-
:
|
102
|
-
:
|
103
|
-
:
|
104
|
-
:
|
105
|
-
:
|
106
|
-
:
|
98
|
+
post '/stripe/webhook', params: {
|
99
|
+
id: 'foo',
|
100
|
+
type: 'customer.subscription.updated',
|
101
|
+
data: {
|
102
|
+
object: {
|
103
|
+
id: subscription.stripe_id,
|
104
|
+
customer: user.stripe_id,
|
105
|
+
cancel_at_period_end: false,
|
106
|
+
quantity: 1,
|
107
107
|
},
|
108
108
|
},
|
109
|
-
}.to_json, :
|
109
|
+
}.to_json, headers: { 'CONTENT_TYPE' => 'application/json' }
|
110
110
|
|
111
111
|
expect(response.status).to eq(200)
|
112
112
|
|
@@ -119,17 +119,17 @@ describe 'webhooks', type: :request do
|
|
119
119
|
|
120
120
|
expect(subscription.cancelled).to be false
|
121
121
|
|
122
|
-
post '/stripe/webhook', :
|
123
|
-
:
|
124
|
-
:
|
125
|
-
:
|
126
|
-
:
|
127
|
-
:
|
128
|
-
:
|
129
|
-
:
|
122
|
+
post '/stripe/webhook', params: {
|
123
|
+
id: 'foo',
|
124
|
+
type: 'customer.subscription.deleted',
|
125
|
+
data: {
|
126
|
+
object: {
|
127
|
+
id: subscription.stripe_id,
|
128
|
+
customer: user.stripe_id,
|
129
|
+
quantity: 1,
|
130
130
|
},
|
131
131
|
},
|
132
|
-
}.to_json, :
|
132
|
+
}.to_json, headers: { 'CONTENT_TYPE' => 'application/json' }
|
133
133
|
|
134
134
|
expect(response.status).to eq(200)
|
135
135
|
|
@@ -142,18 +142,18 @@ describe 'webhooks', type: :request do
|
|
142
142
|
|
143
143
|
expect(user.subscriptions.count).to eq(1)
|
144
144
|
|
145
|
-
post '/stripe/webhook', :
|
146
|
-
:
|
147
|
-
:
|
148
|
-
:
|
149
|
-
:
|
150
|
-
:
|
151
|
-
:
|
152
|
-
:
|
153
|
-
:
|
145
|
+
post '/stripe/webhook', params: {
|
146
|
+
id: 'foo',
|
147
|
+
type: 'customer.subscription.updated',
|
148
|
+
data: {
|
149
|
+
object: {
|
150
|
+
id: subscription.stripe_id,
|
151
|
+
customer: user.stripe_id,
|
152
|
+
status: 'incomplete_expired',
|
153
|
+
quantity: 1,
|
154
154
|
},
|
155
155
|
},
|
156
|
-
}.to_json, :
|
156
|
+
}.to_json, headers: { 'CONTENT_TYPE' => 'application/json' }
|
157
157
|
|
158
158
|
expect(response.status).to eq(200)
|
159
159
|
|