reji 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +73 -0
  4. data/.rubocop_todo.yml +31 -0
  5. data/Appraisals +2 -0
  6. data/Gemfile +1 -1
  7. data/README.md +41 -17
  8. data/Rakefile +8 -2
  9. data/app/controllers/reji/payment_controller.rb +4 -4
  10. data/app/controllers/reji/webhook_controller.rb +51 -62
  11. data/app/views/payment.html.erb +4 -4
  12. data/app/views/receipt.html.erb +16 -16
  13. data/config/routes.rb +2 -0
  14. data/gemfiles/rails_5.0.gemfile +9 -9
  15. data/gemfiles/rails_5.1.gemfile +7 -9
  16. data/gemfiles/rails_5.2.gemfile +7 -9
  17. data/gemfiles/rails_6.0.gemfile +7 -9
  18. data/lib/generators/reji/install/install_generator.rb +20 -24
  19. data/lib/generators/reji/install/templates/reji.rb +2 -2
  20. data/lib/reji.rb +12 -8
  21. data/lib/reji/concerns/manages_customer.rb +25 -29
  22. data/lib/reji/concerns/manages_invoices.rb +37 -44
  23. data/lib/reji/concerns/manages_payment_methods.rb +45 -62
  24. data/lib/reji/concerns/manages_subscriptions.rb +13 -13
  25. data/lib/reji/concerns/performs_charges.rb +7 -7
  26. data/lib/reji/concerns/prorates.rb +1 -1
  27. data/lib/reji/configuration.rb +2 -2
  28. data/lib/reji/engine.rb +2 -0
  29. data/lib/reji/errors.rb +9 -9
  30. data/lib/reji/invoice.rb +57 -56
  31. data/lib/reji/invoice_line_item.rb +21 -23
  32. data/lib/reji/payment.rb +9 -5
  33. data/lib/reji/payment_method.rb +8 -4
  34. data/lib/reji/subscription.rb +165 -183
  35. data/lib/reji/subscription_builder.rb +41 -49
  36. data/lib/reji/subscription_item.rb +26 -26
  37. data/lib/reji/tax.rb +8 -10
  38. data/lib/reji/version.rb +1 -1
  39. data/reji.gemspec +5 -4
  40. data/spec/dummy/app/models/user.rb +3 -7
  41. data/spec/dummy/application.rb +3 -7
  42. data/spec/dummy/db/schema.rb +3 -4
  43. data/spec/feature/charges_spec.rb +1 -1
  44. data/spec/feature/customer_spec.rb +1 -1
  45. data/spec/feature/invoices_spec.rb +6 -6
  46. data/spec/feature/multiplan_subscriptions_spec.rb +51 -53
  47. data/spec/feature/payment_methods_spec.rb +25 -25
  48. data/spec/feature/pending_updates_spec.rb +26 -26
  49. data/spec/feature/subscriptions_spec.rb +78 -78
  50. data/spec/feature/webhooks_spec.rb +72 -72
  51. data/spec/spec_helper.rb +2 -2
  52. data/spec/support/feature_helpers.rb +6 -12
  53. data/spec/unit/customer_spec.rb +13 -13
  54. data/spec/unit/invoice_line_item_spec.rb +12 -14
  55. data/spec/unit/invoice_spec.rb +7 -9
  56. data/spec/unit/payment_spec.rb +3 -3
  57. data/spec/unit/subscription_spec.rb +29 -30
  58. metadata +26 -11
  59. 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
- :id => @product_id,
15
- :name => 'Rails Reji Test Product',
16
- :type => 'service',
14
+ id: @product_id,
15
+ name: 'Rails Reji Test Product',
16
+ type: 'service',
17
17
  })
18
18
 
19
19
  Stripe::Plan.create({
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,
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
- :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,
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
- :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,
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
- :id => @coupon_id,
51
- :duration => 'repeating',
52
- :amount_off => 500,
53
- :duration_in_months => 3,
54
- :currency => 'USD',
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
- :display_name => 'VAT',
59
- :description => 'VAT Belgium',
60
- :jurisdiction => 'BE',
61
- :percentage => 21,
62
- :inclusive => false,
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({:ends_at => Time.now - 5.days})
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({:ends_at => old_grace_period})
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.has_discount).to be false
145
- expect(invoice.has_starting_balance).to be false
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, {:coupon => @coupon_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.new('Expected exception PaymentFailureError was not thrown.')
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.new('Expected exception PaymentActionRequiredError was not thrown.')
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.new('Expected exception PaymentFailureError was not thrown.')
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.new('Expected exception PaymentActionRequiredError was not thrown.')
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.has_discount).to be true
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.now.next_month.at_beginning_of_month.to_i)
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.now.strftime('%Y-%m-%d'))
337
- expect(Time.at(invoice_period.end).strftime('%Y-%m-%d')).to eq(Time.now.next_month.at_beginning_of_month.strftime('%Y-%m-%d'))
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.now + 7.days).strftime('%Y-%m-%d'))
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.now + 7.days).day)
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.now + 1.day + 3.hours + 15.minutes)
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.now + 1.day + 3.hours + 15.minutes).strftime('%Y-%m-%d'))
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.now + 1.day + 3.hours + 15.minutes).day)
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
- :collection_method => 'send_invoice',
446
- :days_until_due => 30,
447
- :backdate_start_date => (Time.now + 5.days - 1.year).beginning_of_day.to_i,
448
- :billing_cycle_anchor => (Time.now + 5.days).beginning_of_day.to_i,
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
- :collection_method => 'send_invoice',
467
- :days_until_due => 30,
468
- :backdate_start_date => (Time.now + 5.days - 1.year).beginning_of_day.to_i,
469
- :billing_cycle_anchor => (Time.now + 5.days).beginning_of_day.to_i,
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.now + 1.day
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
- :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,
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({:stripe_status => 'active'})
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({:trial_ends_at => Time.now + 1.day})
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({:ends_at => Time.now + 1.day})
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({:ends_at => Time.now - 1.day})
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
- :ends_at => nil,
602
- :stripe_status => 'past_due',
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.new('Expected exception PaymentActionRequiredError was not thrown.')
619
- rescue Reji::PaymentActionRequiredError => e
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.now - 1.month).to_i
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 => 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
- :id => @product_id,
12
- :name => 'Rails Reji Test Product',
13
- :type => 'service',
11
+ id: @product_id,
12
+ name: 'Rails Reji Test Product',
13
+ type: 'service',
14
14
  })
15
15
 
16
16
  Stripe::Plan.create({
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,
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', {:stripe_id => 'cus_foo'})
33
+ user = create_customer('subscriptions_are_updated', { stripe_id: 'cus_foo' })
34
34
 
35
35
  subscription = user.subscriptions.create({
36
- :name => 'main',
37
- :stripe_id => 'sub_foo',
38
- :stripe_plan => 'plan_foo',
39
- :stripe_status => 'active',
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
- :stripe_id => 'it_foo',
44
- :stripe_plan => 'plan_bar',
45
- :quantity => 1,
43
+ stripe_id: 'it_foo',
44
+ stripe_plan: 'plan_bar',
45
+ quantity: 1,
46
46
  })
47
47
 
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 => [
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
- :id => 'bar',
61
- :plan => {:id => 'plan_foo'},
62
- :quantity => 10,
63
- }
60
+ id: 'bar',
61
+ plan: { id: 'plan_foo' },
62
+ quantity: 10,
63
+ },
64
64
  ],
65
65
  },
66
66
  },
67
67
  },
68
- }.to_json, :headers => { 'CONTENT_TYPE' => 'application/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
- :id => subscription.id,
74
- :user_id => user.id,
75
- :stripe_id => 'sub_foo',
76
- :quantity => 5,
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
- :subscription_id => subscription.id,
81
- :stripe_id => 'bar',
82
- :stripe_plan => 'plan_foo',
83
- :quantity => 10,
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
- :id => item.id,
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', :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,
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, :headers => { 'CONTENT_TYPE' => 'application/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', :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,
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, :headers => { 'CONTENT_TYPE' => 'application/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', :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,
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, :headers => { 'CONTENT_TYPE' => 'application/json' }
156
+ }.to_json, headers: { 'CONTENT_TYPE' => 'application/json' }
157
157
 
158
158
  expect(response.status).to eq(200)
159
159