payola-payments 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/payola/checkout_button.js +9 -9
  3. data/app/assets/javascripts/payola/form.js +6 -6
  4. data/app/assets/javascripts/payola/subscription_form.js +6 -6
  5. data/app/controllers/concerns/payola/affiliate_behavior.rb +17 -0
  6. data/app/controllers/concerns/payola/async_behavior.rb +36 -0
  7. data/app/controllers/payola/subscriptions_controller.rb +31 -46
  8. data/app/controllers/payola/transactions_controller.rb +16 -32
  9. data/app/mailers/payola/admin_mailer.rb +7 -15
  10. data/app/mailers/payola/receipt_mailer.rb +2 -0
  11. data/app/models/concerns/payola/guid_behavior.rb +20 -0
  12. data/app/models/concerns/payola/plan.rb +0 -1
  13. data/app/models/payola/sale.rb +6 -12
  14. data/app/models/payola/subscription.rb +9 -12
  15. data/app/services/payola/charge_card.rb +42 -33
  16. data/app/services/payola/create_plan.rb +2 -2
  17. data/app/services/payola/invoice_behavior.rb +55 -0
  18. data/app/services/payola/invoice_failed.rb +4 -29
  19. data/app/services/payola/invoice_paid.rb +4 -31
  20. data/lib/payola.rb +13 -11
  21. data/lib/payola/version.rb +1 -1
  22. data/spec/concerns/plan_spec.rb +0 -5
  23. data/spec/controllers/payola/subscriptions_controller_spec.rb +10 -1
  24. data/spec/controllers/payola/transactions_controller_spec.rb +10 -1
  25. data/spec/dummy/app/models/subscription_plan_without_interval_count.rb +3 -0
  26. data/spec/dummy/config/environments/test.rb +2 -0
  27. data/spec/dummy/db/development.sqlite3 +0 -0
  28. data/spec/dummy/db/migrate/20141120170744_create_subscription_plan_without_interval_counts.rb +12 -0
  29. data/spec/dummy/db/schema.rb +10 -1
  30. data/spec/dummy/db/test.sqlite3 +0 -0
  31. data/spec/dummy/log/development.log +222 -0
  32. data/spec/dummy/log/test.log +15830 -141203
  33. data/spec/factories/subscription_plan.rb +7 -0
  34. data/spec/mailers/payola/admin_mailer_spec.rb +35 -0
  35. data/spec/mailers/payola/receipt_mailer_spec.rb +52 -0
  36. data/spec/models/payola/subscription_spec.rb +21 -0
  37. data/spec/payola_spec.rb +6 -2
  38. data/spec/services/payola/create_plan_spec.rb +9 -0
  39. data/spec/services/payola/process_sale_spec.rb +15 -0
  40. data/spec/services/payola/process_subscription_spec.rb +15 -0
  41. data/spec/services/payola/send_mail_spec.rb +25 -0
  42. data/spec/spec_helper.rb +13 -0
  43. data/spec/worker_spec.rb +55 -0
  44. metadata +40 -8
@@ -6,4 +6,11 @@ FactoryGirl.define do
6
6
  interval "month"
7
7
  interval_count 1
8
8
  end
9
+
10
+ factory :subscription_plan_without_interval_count do
11
+ sequence(:name) { |n| "Foo #{n}" }
12
+ sequence(:stripe_id) { |n| "foo-#{n}" }
13
+ amount 100
14
+ interval "month"
15
+ end
9
16
  end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ module Payola
4
+ describe AdminMailer do
5
+ let(:sale) { create(:sale) }
6
+
7
+ describe '#receipt' do
8
+ it "should send a receipt notification" do
9
+ mail = AdminMailer.receipt(sale.guid)
10
+ expect(mail.subject).to eq 'Receipt'
11
+ end
12
+ end
13
+
14
+ describe '#refund' do
15
+ it "should send a refund notification" do
16
+ mail = AdminMailer.refund(sale.guid)
17
+ expect(mail.subject).to eq 'Refund'
18
+ end
19
+ end
20
+
21
+ describe '#dispute' do
22
+ it "should send a dispute notification" do
23
+ mail = AdminMailer.dispute(sale.guid)
24
+ expect(mail.subject).to eq 'Dispute'
25
+ end
26
+ end
27
+
28
+ describe '#failure' do
29
+ it "should send a failure notification" do
30
+ mail = AdminMailer.failure(sale.guid)
31
+ expect(mail.subject).to eq 'Failure'
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ module Payola
4
+ describe ReceiptMailer do
5
+ let(:sale) { create(:sale) }
6
+
7
+ describe '#receipt' do
8
+ it 'should send a receipt' do
9
+ Payola.pdf_receipt = false
10
+ mail = Payola::ReceiptMailer.receipt(sale.guid)
11
+ expect(mail.subject).to eq 'Purchase Receipt'
12
+ end
13
+
14
+ it 'should send a receipt with a pdf' do
15
+ Payola.pdf_receipt = true
16
+ mail = Payola::ReceiptMailer.receipt(sale.guid)
17
+ expect(mail.attachments["receipt-#{sale.guid}.pdf"]).to_not be nil
18
+ end
19
+
20
+ it "should allow product to override subject" do
21
+ expect_any_instance_of(Product).to receive(:receipt_subject).and_return("Override Subject")
22
+ mail = Payola::ReceiptMailer.receipt(sale.guid)
23
+ expect(mail.subject).to eq 'Override Subject'
24
+ end
25
+
26
+ it "should allow product to override from address" do
27
+ expect_any_instance_of(Product).to receive(:receipt_from_address).and_return("Override <override@example.com>")
28
+ mail = Payola::ReceiptMailer.receipt(sale.guid)
29
+ expect(mail.from.first).to eq 'override@example.com'
30
+ end
31
+ end
32
+
33
+ describe '#refund' do
34
+ it "should send refund email" do
35
+ mail = Payola::ReceiptMailer.refund(sale.guid)
36
+ expect(mail.subject).to eq 'Refund Confirmation'
37
+ end
38
+
39
+ it "should allow product to override subject" do
40
+ expect_any_instance_of(Product).to receive(:refund_subject).and_return("Override Subject")
41
+ mail = Payola::ReceiptMailer.refund(sale.guid)
42
+ expect(mail.subject).to eq 'Override Subject'
43
+ end
44
+
45
+ it "should allow product to override from address" do
46
+ expect_any_instance_of(Product).to receive(:refund_from_address).and_return("Override <override@example.com>")
47
+ mail = Payola::ReceiptMailer.refund(sale.guid)
48
+ expect(mail.from.first).to eq 'override@example.com'
49
+ end
50
+ end
51
+ end
52
+ end
@@ -36,6 +36,9 @@ module Payola
36
36
  trial_start = subscription.trial_start
37
37
  trial_end = subscription.trial_end
38
38
 
39
+ now = Time.now.to_i
40
+ expect(stripe_sub).to receive(:canceled_at).and_return(now).at_least(1)
41
+
39
42
  subscription.sync_with!(stripe_sub)
40
43
 
41
44
  subscription.reload
@@ -44,6 +47,24 @@ module Payola
44
47
  expect(subscription.current_period_start).to_not eq old_start
45
48
  expect(subscription.current_period_end).to eq Time.at(stripe_sub.current_period_end)
46
49
  expect(subscription.current_period_end).to_not eq old_end
50
+ expect(subscription.canceled_at).to eq Time.at(now)
51
+ end
52
+
53
+ it "should sync non-timestamp fields" do
54
+ plan = create(:subscription_plan)
55
+ subscription = build(:subscription, plan: plan)
56
+ stripe_sub = Stripe::Customer.create.subscriptions.create(plan: plan.stripe_id, card: StripeMock.generate_card_token(last4: '1234', exp_year: Time.now.year + 1))
57
+
58
+ expect(stripe_sub).to receive(:quantity).and_return(10).at_least(1)
59
+ expect(stripe_sub).to receive(:cancel_at_period_end).and_return(true).at_least(1)
60
+
61
+ subscription.sync_with!(stripe_sub)
62
+
63
+ subscription.reload
64
+
65
+ expect(subscription.quantity).to eq 10
66
+ expect(subscription.stripe_status).to eq 'active'
67
+ expect(subscription.cancel_at_period_end).to eq true
47
68
  end
48
69
  end
49
70
  end
data/spec/payola_spec.rb CHANGED
@@ -1,6 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Payola
4
+ class FakeWorker
5
+ def self.can_run?
6
+ false
7
+ end
8
+ end
9
+
4
10
  describe "#configure" do
5
11
  it "should pass the class back to the given block" do
6
12
  Payola.configure do |payola|
@@ -42,7 +48,6 @@ module Payola
42
48
  before do
43
49
  Payola.reset!
44
50
 
45
- class FakeWorker; end
46
51
  Payola::Worker.registry ||= {}
47
52
  Payola::Worker.registry[:fake] = FakeWorker
48
53
  end
@@ -88,7 +93,6 @@ module Payola
88
93
  before do
89
94
  Payola.reset!
90
95
 
91
- class FakeWorker; end
92
96
  Payola::Worker.registry ||= {}
93
97
  Payola::Worker.registry[:fake] = FakeWorker
94
98
  Payola.background_worker = :fake
@@ -18,6 +18,15 @@ module Payola
18
18
  expect(plan.currency).to eq 'usd'
19
19
  expect(plan.trial_period_days).to eq @subscription_plan.trial_period_days
20
20
  end
21
+
22
+ it "should default interval_count" do
23
+ our_plan = create(:subscription_plan_without_interval_count)
24
+
25
+ expect(our_plan.respond_to?(:interval_count)).to eq false
26
+
27
+ plan = Stripe::Plan.retrieve(our_plan.stripe_id)
28
+ expect(plan.interval_count).to be_nil
29
+ end
21
30
  end
22
31
 
23
32
  end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ module Payola
4
+ describe ProcessSale do
5
+ describe "#call" do
6
+ it "should call process!" do
7
+ sale = create(:sale)
8
+ expect(Payola::Sale).to receive(:find_by).with(guid: sale.guid).and_return(sale)
9
+ expect(sale).to receive(:process!)
10
+
11
+ Payola::ProcessSale.call(sale.guid)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ module Payola
4
+ describe ProcessSubscription do
5
+ describe "#call" do
6
+ it "should call process!" do
7
+ sale = create(:sale)
8
+ expect(Payola::Subscription).to receive(:find_by).with(guid: sale.guid).and_return(sale)
9
+ expect(sale).to receive(:process!)
10
+
11
+ Payola::ProcessSubscription.call(sale.guid)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ module Payola
4
+
5
+ class TestMailer < ActionMailer::Base
6
+ def test_mail(to, text)
7
+ mail(
8
+ to: to,
9
+ from: 'from@example.com',
10
+ body: text
11
+ )
12
+ end
13
+ end
14
+
15
+ describe SendMail do
16
+ describe "#call" do
17
+ it "should send a mail" do
18
+ mail = double
19
+ expect(TestMailer).to receive(:test_mail).with('to@example.com', 'Some Text').and_return(mail)
20
+ expect(mail).to receive(:deliver)
21
+ Payola::SendMail.call('Payola::TestMailer', 'test_mail', 'to@example.com', 'Some Text')
22
+ end
23
+ end
24
+ end
25
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,16 @@
1
+ require 'simplecov'
2
+ require "codeclimate-test-reporter"
3
+
4
+ if ENV['CIRCLE_ARTIFACTS']
5
+ dir = File.join("..", "..", "..", ENV['CIRCLE_ARTIFACTS'], "coverage")
6
+ SimpleCov.coverage_dir(dir)
7
+ CodeClimate::TestReporter.start
8
+ end
9
+ SimpleCov.start 'rails' do
10
+ add_filter 'app/secrets'
11
+ end
12
+
13
+
1
14
  # This file is copied to spec/ when you run 'rails generate rspec:install'
2
15
  ENV["RAILS_ENV"] ||= 'test'
3
16
  require File.expand_path("../dummy/config/environment", __FILE__)
data/spec/worker_spec.rb CHANGED
@@ -8,6 +8,29 @@ module Payola
8
8
  end
9
9
  end
10
10
 
11
+ describe Worker do
12
+ describe "#autofind" do
13
+ it "should return ActiveJob if available" do
14
+ expect(Payola::Worker::ActiveJob).to receive(:can_run?).and_return(true)
15
+ expect(Payola::Worker.autofind).to eq Payola::Worker::ActiveJob
16
+ end
17
+ it "should return something else if available" do
18
+ expect(Payola::Worker::ActiveJob).to receive(:can_run?).and_return(false)
19
+ expect(Payola::Worker::Sidekiq).to receive(:can_run?).and_return(false)
20
+ expect(Payola::Worker::SuckerPunch).to receive(:can_run?).and_return(true)
21
+ expect(Payola::Worker.autofind).to eq Payola::Worker::SuckerPunch
22
+ end
23
+
24
+ it "should raise if nothing available" do
25
+ expect(Payola::Worker::ActiveJob).to receive(:can_run?).and_return(false).at_least(1)
26
+ expect(Payola::Worker::Sidekiq).to receive(:can_run?).and_return(false)
27
+ expect(Payola::Worker::SuckerPunch).to receive(:can_run?).and_return(false)
28
+
29
+ expect { Payola::Worker.autofind }.to raise_error("No eligable background worker systems found.")
30
+ end
31
+ end
32
+ end
33
+
11
34
  describe Worker::Sidekiq do
12
35
  before do
13
36
  module ::Sidekiq
@@ -32,6 +55,24 @@ module Payola
32
55
  end
33
56
  end
34
57
 
58
+ describe Worker::SuckerPunch do
59
+ describe "#can_run?" do
60
+ it "should return true if SuckerPunch is defined" do
61
+ expect(Payola::Worker::SuckerPunch.can_run?).to be_truthy
62
+ end
63
+ end
64
+
65
+ describe "#call" do
66
+ it "should call async" do
67
+ worker = double
68
+ expect(Payola::Worker::SuckerPunch).to receive(:new).and_return(worker)
69
+ expect(worker).to receive(:async).and_return(worker)
70
+ expect(worker).to receive(:perform)
71
+ Payola::Worker::SuckerPunch.call(Payola::TestService, double)
72
+ end
73
+ end
74
+ end
75
+
35
76
  describe Worker::ActiveJob do
36
77
  before do
37
78
  module ::ActiveJob
@@ -52,4 +93,18 @@ module Payola
52
93
  end
53
94
  end
54
95
  end
96
+
97
+ describe Worker::BaseWorker do
98
+
99
+ class SomeTestService
100
+ def self.call; end
101
+ end
102
+
103
+ describe "#perform" do
104
+ it "should call the given service" do
105
+ expect(SomeTestService).to receive(:call)
106
+ Payola::Worker::BaseWorker.new.perform('Payola::SomeTestService')
107
+ end
108
+ end
109
+ end
55
110
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: payola-payments
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Keen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-17 00:00:00.000000000 Z
11
+ date: 2014-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -56,28 +56,28 @@ dependencies:
56
56
  name: aasm
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 3.4.0
61
+ version: '4.0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 3.4.0
68
+ version: '4.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: stripe_event
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: 1.3.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.3.0
83
83
  - !ruby/object:Gem::Dependency
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: 1.2.1
153
+ - !ruby/object:Gem::Dependency
154
+ name: docverter
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  description: One-off and subscription payments for your Rails application
154
168
  email:
155
169
  - pete@payola.io
@@ -164,6 +178,8 @@ files:
164
178
  - app/assets/javascripts/payola/form.js
165
179
  - app/assets/javascripts/payola/subscription_form.js
166
180
  - app/assets/stylesheets/payola/application.css
181
+ - app/controllers/concerns/payola/affiliate_behavior.rb
182
+ - app/controllers/concerns/payola/async_behavior.rb
167
183
  - app/controllers/payola/application_controller.rb
168
184
  - app/controllers/payola/subscriptions_controller.rb
169
185
  - app/controllers/payola/transactions_controller.rb
@@ -171,6 +187,7 @@ files:
171
187
  - app/helpers/payola/price_helper.rb
172
188
  - app/mailers/payola/admin_mailer.rb
173
189
  - app/mailers/payola/receipt_mailer.rb
190
+ - app/models/concerns/payola/guid_behavior.rb
174
191
  - app/models/concerns/payola/plan.rb
175
192
  - app/models/concerns/payola/sellable.rb
176
193
  - app/models/payola/affiliate.rb
@@ -184,6 +201,7 @@ files:
184
201
  - app/services/payola/create_plan.rb
185
202
  - app/services/payola/create_sale.rb
186
203
  - app/services/payola/create_subscription.rb
204
+ - app/services/payola/invoice_behavior.rb
187
205
  - app/services/payola/invoice_failed.rb
188
206
  - app/services/payola/invoice_paid.rb
189
207
  - app/services/payola/process_sale.rb
@@ -260,6 +278,7 @@ files:
260
278
  - spec/dummy/app/models/owner.rb
261
279
  - spec/dummy/app/models/product.rb
262
280
  - spec/dummy/app/models/subscription_plan.rb
281
+ - spec/dummy/app/models/subscription_plan_without_interval_count.rb
263
282
  - spec/dummy/app/views/buy/index.html.erb
264
283
  - spec/dummy/app/views/home/index.html.erb
265
284
  - spec/dummy/app/views/layouts/application.html.erb
@@ -293,6 +312,7 @@ files:
293
312
  - spec/dummy/db/migrate/20141001230848_create_products.rb
294
313
  - spec/dummy/db/migrate/20141029140518_create_owners.rb
295
314
  - spec/dummy/db/migrate/20141105010234_create_subscription_plans.rb
315
+ - spec/dummy/db/migrate/20141120170744_create_subscription_plan_without_interval_counts.rb
296
316
  - spec/dummy/db/schema.rb
297
317
  - spec/dummy/db/test.sqlite3
298
318
  - spec/dummy/log/development.log
@@ -334,6 +354,8 @@ files:
334
354
  - spec/factories/sales.rb
335
355
  - spec/factories/subscription_plan.rb
336
356
  - spec/helpers/payola/price_helper_spec.rb
357
+ - spec/mailers/payola/admin_mailer_spec.rb
358
+ - spec/mailers/payola/receipt_mailer_spec.rb
337
359
  - spec/models/payola/sale_spec.rb
338
360
  - spec/models/payola/stripe_webhook_spec.rb
339
361
  - spec/models/payola/subscription_spec.rb
@@ -346,6 +368,9 @@ files:
346
368
  - spec/services/payola/create_subscription_spec.rb
347
369
  - spec/services/payola/invoice_failed_spec.rb
348
370
  - spec/services/payola/invoice_paid_spec.rb
371
+ - spec/services/payola/process_sale_spec.rb
372
+ - spec/services/payola/process_subscription_spec.rb
373
+ - spec/services/payola/send_mail_spec.rb
349
374
  - spec/services/payola/start_subscription_spec.rb
350
375
  - spec/services/payola/sync_subscription_spec.rb
351
376
  - spec/services/payola/update_card_spec.rb
@@ -394,6 +419,7 @@ test_files:
394
419
  - spec/dummy/app/models/owner.rb
395
420
  - spec/dummy/app/models/product.rb
396
421
  - spec/dummy/app/models/subscription_plan.rb
422
+ - spec/dummy/app/models/subscription_plan_without_interval_count.rb
397
423
  - spec/dummy/app/views/buy/index.html.erb
398
424
  - spec/dummy/app/views/home/index.html.erb
399
425
  - spec/dummy/app/views/layouts/application.html.erb
@@ -427,6 +453,7 @@ test_files:
427
453
  - spec/dummy/db/migrate/20141001230848_create_products.rb
428
454
  - spec/dummy/db/migrate/20141029140518_create_owners.rb
429
455
  - spec/dummy/db/migrate/20141105010234_create_subscription_plans.rb
456
+ - spec/dummy/db/migrate/20141120170744_create_subscription_plan_without_interval_counts.rb
430
457
  - spec/dummy/db/schema.rb
431
458
  - spec/dummy/db/test.sqlite3
432
459
  - spec/dummy/log/development.log
@@ -470,6 +497,8 @@ test_files:
470
497
  - spec/factories/sales.rb
471
498
  - spec/factories/subscription_plan.rb
472
499
  - spec/helpers/payola/price_helper_spec.rb
500
+ - spec/mailers/payola/admin_mailer_spec.rb
501
+ - spec/mailers/payola/receipt_mailer_spec.rb
473
502
  - spec/models/payola/sale_spec.rb
474
503
  - spec/models/payola/stripe_webhook_spec.rb
475
504
  - spec/models/payola/subscription_spec.rb
@@ -482,6 +511,9 @@ test_files:
482
511
  - spec/services/payola/create_subscription_spec.rb
483
512
  - spec/services/payola/invoice_failed_spec.rb
484
513
  - spec/services/payola/invoice_paid_spec.rb
514
+ - spec/services/payola/process_sale_spec.rb
515
+ - spec/services/payola/process_subscription_spec.rb
516
+ - spec/services/payola/send_mail_spec.rb
485
517
  - spec/services/payola/start_subscription_spec.rb
486
518
  - spec/services/payola/sync_subscription_spec.rb
487
519
  - spec/services/payola/update_card_spec.rb