payola-payments 1.2.2 → 1.2.3

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 +8 -1
  3. data/app/assets/javascripts/payola/subscription_form_onestep.js +13 -2
  4. data/app/assets/javascripts/payola/subscription_form_twostep.js +10 -1
  5. data/app/controllers/concerns/payola/async_behavior.rb +14 -5
  6. data/app/controllers/payola/subscriptions_controller.rb +16 -3
  7. data/app/controllers/payola/transactions_controller.rb +1 -1
  8. data/app/models/concerns/payola/plan.rb +1 -1
  9. data/app/models/payola/subscription.rb +7 -1
  10. data/app/services/payola/change_subscription_quantity.rb +25 -0
  11. data/app/services/payola/charge_card.rb +8 -4
  12. data/app/services/payola/create_subscription.rb +1 -0
  13. data/app/services/payola/start_subscription.rb +48 -12
  14. data/app/views/payola/subscriptions/_change_plan.html.erb +1 -1
  15. data/config/database.yml.ci +6 -0
  16. data/config/routes.rb +1 -0
  17. data/db/migrate/20141213205847_add_active_to_payola_coupon.rb +5 -0
  18. data/lib/payola.rb +4 -4
  19. data/lib/payola/engine.rb +1 -1
  20. data/lib/payola/version.rb +1 -1
  21. data/lib/payola/worker.rb +1 -1
  22. data/spec/concerns/plan_spec.rb +9 -0
  23. data/spec/concerns/sellable_spec.rb +1 -1
  24. data/spec/controllers/payola/subscriptions_controller_spec.rb +41 -13
  25. data/spec/controllers/payola/transactions_controller_spec.rb +7 -5
  26. data/spec/dummy/app/models/user.rb +2 -0
  27. data/spec/dummy/app/views/subscribe/index.html.erb +2 -0
  28. data/spec/dummy/config/environments/test.rb +5 -1
  29. data/spec/dummy/db/development.sqlite3 +0 -0
  30. data/spec/dummy/db/migrate/20141204170622_create_users.rb +8 -0
  31. data/spec/dummy/db/schema.rb +16 -10
  32. data/spec/dummy/db/test.sqlite3 +0 -0
  33. data/spec/dummy/log/development.log +131 -0
  34. data/spec/dummy/log/test.log +75119 -0
  35. data/spec/factories/subscription_plan.rb +2 -2
  36. data/spec/mailers/payola/receipt_mailer_spec.rb +6 -1
  37. data/spec/models/payola/coupon_spec.rb +27 -0
  38. data/spec/payola_spec.rb +2 -2
  39. data/spec/services/payola/change_subscription_plan_spec.rb +0 -1
  40. data/spec/services/payola/change_subscription_quantity_spec.rb +29 -0
  41. data/spec/services/payola/charge_card_spec.rb +9 -0
  42. data/spec/services/payola/start_subscription_spec.rb +37 -0
  43. data/spec/worker_spec.rb +1 -1
  44. metadata +15 -4
@@ -8,8 +8,8 @@ FactoryGirl.define do
8
8
  end
9
9
 
10
10
  factory :subscription_plan_without_interval_count do
11
- sequence(:name) { |n| "Foo #{n}" }
12
- sequence(:stripe_id) { |n| "foo-#{n}" }
11
+ sequence(:name) { |n| "Foo Without Interval #{n}" }
12
+ sequence(:stripe_id) { |n| "foo-without-interval-#{n}" }
13
13
  amount 100
14
14
  interval "month"
15
15
  end
@@ -1,18 +1,23 @@
1
1
  require 'spec_helper'
2
+ require 'docverter'
2
3
 
3
4
  module Payola
4
5
  describe ReceiptMailer do
5
6
  let(:sale) { create(:sale) }
6
7
 
8
+ before do
9
+ Payola.pdf_receipt = false
10
+ end
11
+
7
12
  describe '#receipt' do
8
13
  it 'should send a receipt' do
9
- Payola.pdf_receipt = false
10
14
  mail = Payola::ReceiptMailer.receipt(sale.guid)
11
15
  expect(mail.subject).to eq 'Purchase Receipt'
12
16
  end
13
17
 
14
18
  it 'should send a receipt with a pdf' do
15
19
  Payola.pdf_receipt = true
20
+ expect(Docverter::Conversion).to receive(:run).and_return('pdf')
16
21
  mail = Payola::ReceiptMailer.receipt(sale.guid)
17
22
  expect(mail.attachments["receipt-#{sale.guid}.pdf"]).to_not be nil
18
23
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ module Payola
4
+ describe Coupon do
5
+ describe "validations" do
6
+ it "should validate uniqueness of coupon code" do
7
+ c1 = Coupon.create(code: 'abc')
8
+ expect(c1.valid?).to be_truthy
9
+
10
+ c2 = Coupon.new(code: 'abc')
11
+ expect(c2.valid?).to be_falsey
12
+ end
13
+ end
14
+
15
+ describe "active" do
16
+ it "should allow active flag" do
17
+ c1 = Coupon.create(code: 'abc', active: false)
18
+ expect(c1.active?).to be_falsey
19
+ end
20
+
21
+ it "should be true by default" do
22
+ c1 = Coupon.create(code: 'abc')
23
+ expect(c1.active?).to be_truthy
24
+ end
25
+ end
26
+ end
27
+ end
data/spec/payola_spec.rb CHANGED
@@ -13,13 +13,13 @@ module Payola
13
13
  it "should set publishable key from env" do
14
14
  ENV['STRIPE_PUBLISHABLE_KEY'] = 'some_key'
15
15
  Payola.reset!
16
- expect(Payola.publishable_key).to eq 'some_key'
16
+ expect(Payola.publishable_key.call).to eq 'some_key'
17
17
  end
18
18
 
19
19
  it "should set secret key from env" do
20
20
  ENV['STRIPE_SECRET_KEY'] = 'some_secret'
21
21
  Payola.reset!
22
- expect(Payola.secret_key).to eq 'some_secret'
22
+ expect(Payola.secret_key.call).to eq 'some_secret'
23
23
  end
24
24
  end
25
25
 
@@ -23,7 +23,6 @@ module Payola
23
23
  end
24
24
 
25
25
  it "should change the plan on the payola subscription" do
26
- Payola::ChangeSubscriptionPlan.call(@subscription, @plan2)
27
26
  expect(@subscription.reload.plan).to eq @plan2
28
27
  end
29
28
  end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ module Payola
4
+ describe ChangeSubscriptionQuantity do
5
+ let(:stripe_helper) { StripeMock.create_test_helper }
6
+
7
+ describe "#call" do
8
+ before do
9
+ @plan = create(:subscription_plan)
10
+
11
+ token = StripeMock.generate_card_token({})
12
+ @subscription = create(:subscription, quantity: 1, stripe_token: token)
13
+ StartSubscription.call(@subscription)
14
+ Payola::ChangeSubscriptionQuantity.call(@subscription, 2)
15
+ end
16
+
17
+ it "should change the quantity on the stripe subscription" do
18
+ customer = Stripe::Customer.retrieve(@subscription.stripe_customer_id)
19
+ sub = customer.subscriptions.retrieve(@subscription.stripe_id)
20
+
21
+ expect(sub.quantity).to eq 2
22
+ end
23
+
24
+ it "should change the quantity on the payola subscription" do
25
+ expect(@subscription.reload.quantity).to eq 2
26
+ end
27
+ end
28
+ end
29
+ end
@@ -10,6 +10,15 @@ module Payola
10
10
  expect(sale.reload.stripe_customer_id).to_not be_nil
11
11
  end
12
12
 
13
+ it "should not create a customer if one already exists" do
14
+ customer = Stripe::Customer.create
15
+ sale = create(:sale, state: 'processing', stripe_customer_id: customer.id)
16
+ expect(Stripe::Customer).to receive(:retrieve).and_return(customer)
17
+ ChargeCard.call(sale)
18
+ expect(sale.reload.stripe_customer_id).to eq customer.id
19
+ expect(sale.state).to eq 'finished'
20
+ end
21
+
13
22
  it "should create a charge" do
14
23
  sale = create(:sale, state: 'processing', stripe_token: stripe_helper.generate_card_token)
15
24
  ChargeCard.call(sale)
@@ -4,6 +4,8 @@ module Payola
4
4
  describe StartSubscription do
5
5
  let(:stripe_helper) { StripeMock.create_test_helper }
6
6
  let(:token){ StripeMock.generate_card_token({}) }
7
+ let(:user){ User.create }
8
+
7
9
  describe "#call" do
8
10
  it "should create a customer" do
9
11
  plan = create(:subscription_plan)
@@ -31,6 +33,41 @@ module Payola
31
33
  end
32
34
  end
33
35
 
36
+ it "should re-use an existing customer" do
37
+ plan = create(:subscription_plan)
38
+ subscription = create(:subscription, state: 'processing', plan: plan, stripe_token: token, owner: user)
39
+ StartSubscription.call(subscription)
40
+ CancelSubscription.call(subscription)
41
+
42
+ subscription2 = create(:subscription, state: 'processing', plan: plan, owner: user)
43
+ StartSubscription.call(subscription2)
44
+ expect(subscription2.reload.stripe_customer_id).to_not be_nil
45
+ expect(subscription2.reload.stripe_customer_id).to eq subscription.reload.stripe_customer_id
46
+ end
47
+
48
+ it "should create an invoice item with a setup fee" do
49
+ plan = create(:subscription_plan)
50
+ subscription = create(:subscription, state: 'processing', plan: plan, stripe_token: token, owner: user, setup_fee: 100)
51
+ StartSubscription.call(subscription)
52
+
53
+ ii = Stripe::InvoiceItem.all(customer: subscription.stripe_customer_id).first
54
+ expect(ii).to_not be_nil
55
+ expect(ii.amount).to eq 100
56
+ expect(ii.description).to eq "Setup Fee"
57
+ end
58
+
59
+ it "should allow the plan to override the setup fee description" do
60
+ plan = create(:subscription_plan)
61
+ subscription = create(:subscription, state: 'processing', plan: plan, stripe_token: token, owner: user, setup_fee: 100)
62
+
63
+ expect(plan).to receive(:setup_fee_description).with(subscription).and_return('Random Mystery Fee')
64
+ StartSubscription.call(subscription)
65
+
66
+ ii = Stripe::InvoiceItem.all(customer: subscription.stripe_customer_id).first
67
+ expect(ii).to_not be_nil
68
+ expect(ii.amount).to eq 100
69
+ expect(ii.description).to eq 'Random Mystery Fee'
70
+ end
34
71
  end
35
72
  end
36
73
  end
data/spec/worker_spec.rb CHANGED
@@ -26,7 +26,7 @@ module Payola
26
26
  expect(Payola::Worker::Sidekiq).to receive(:can_run?).and_return(false)
27
27
  expect(Payola::Worker::SuckerPunch).to receive(:can_run?).and_return(false)
28
28
 
29
- expect { Payola::Worker.autofind }.to raise_error("No eligable background worker systems found.")
29
+ expect { Payola::Worker.autofind }.to raise_error("No eligible background worker systems found.")
30
30
  end
31
31
  end
32
32
  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.2
4
+ version: 1.2.3
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-29 00:00:00.000000000 Z
11
+ date: 2015-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '4.0'
61
+ version: 4.0.7
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: '4.0'
68
+ version: 4.0.7
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: stripe_event
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -199,6 +199,7 @@ files:
199
199
  - app/models/payola/subscription.rb
200
200
  - app/services/payola/cancel_subscription.rb
201
201
  - app/services/payola/change_subscription_plan.rb
202
+ - app/services/payola/change_subscription_quantity.rb
202
203
  - app/services/payola/charge_card.rb
203
204
  - app/services/payola/create_plan.rb
204
205
  - app/services/payola/create_sale.rb
@@ -231,6 +232,7 @@ files:
231
232
  - app/views/payola/transactions/new.html.erb
232
233
  - app/views/payola/transactions/show.html.erb
233
234
  - app/views/payola/transactions/wait.html.erb
235
+ - config/database.yml.ci
234
236
  - config/routes.rb
235
237
  - db/migrate/20141001170138_create_payola_sales.rb
236
238
  - db/migrate/20141001203541_create_payola_stripe_webhooks.rb
@@ -250,6 +252,7 @@ files:
250
252
  - db/migrate/20141114154223_add_signed_custom_fields_to_payola_subscription.rb
251
253
  - db/migrate/20141114163841_add_addresses_to_payola_subscription.rb
252
254
  - db/migrate/20141122020755_add_setup_fee_to_payola_subscriptions.rb
255
+ - db/migrate/20141213205847_add_active_to_payola_coupon.rb
253
256
  - lib/generators/payola/install_generator.rb
254
257
  - lib/generators/payola/templates/initializer.rb
255
258
  - lib/payola-payments.rb
@@ -282,6 +285,7 @@ files:
282
285
  - spec/dummy/app/models/product.rb
283
286
  - spec/dummy/app/models/subscription_plan.rb
284
287
  - spec/dummy/app/models/subscription_plan_without_interval_count.rb
288
+ - spec/dummy/app/models/user.rb
285
289
  - spec/dummy/app/views/buy/index.html.erb
286
290
  - spec/dummy/app/views/home/index.html.erb
287
291
  - spec/dummy/app/views/layouts/application.html.erb
@@ -316,6 +320,7 @@ files:
316
320
  - spec/dummy/db/migrate/20141029140518_create_owners.rb
317
321
  - spec/dummy/db/migrate/20141105010234_create_subscription_plans.rb
318
322
  - spec/dummy/db/migrate/20141120170744_create_subscription_plan_without_interval_counts.rb
323
+ - spec/dummy/db/migrate/20141204170622_create_users.rb
319
324
  - spec/dummy/db/schema.rb
320
325
  - spec/dummy/db/test.sqlite3
321
326
  - spec/dummy/log/development.log
@@ -362,12 +367,14 @@ files:
362
367
  - spec/helpers/payola/price_helper_spec.rb
363
368
  - spec/mailers/payola/admin_mailer_spec.rb
364
369
  - spec/mailers/payola/receipt_mailer_spec.rb
370
+ - spec/models/payola/coupon_spec.rb
365
371
  - spec/models/payola/sale_spec.rb
366
372
  - spec/models/payola/stripe_webhook_spec.rb
367
373
  - spec/models/payola/subscription_spec.rb
368
374
  - spec/payola_spec.rb
369
375
  - spec/services/payola/cancel_subscription_spec.rb
370
376
  - spec/services/payola/change_subscription_plan_spec.rb
377
+ - spec/services/payola/change_subscription_quantity_spec.rb
371
378
  - spec/services/payola/charge_card_spec.rb
372
379
  - spec/services/payola/create_plan_spec.rb
373
380
  - spec/services/payola/create_sale_spec.rb
@@ -426,6 +433,7 @@ test_files:
426
433
  - spec/dummy/app/models/product.rb
427
434
  - spec/dummy/app/models/subscription_plan.rb
428
435
  - spec/dummy/app/models/subscription_plan_without_interval_count.rb
436
+ - spec/dummy/app/models/user.rb
429
437
  - spec/dummy/app/views/buy/index.html.erb
430
438
  - spec/dummy/app/views/home/index.html.erb
431
439
  - spec/dummy/app/views/layouts/application.html.erb
@@ -460,6 +468,7 @@ test_files:
460
468
  - spec/dummy/db/migrate/20141029140518_create_owners.rb
461
469
  - spec/dummy/db/migrate/20141105010234_create_subscription_plans.rb
462
470
  - spec/dummy/db/migrate/20141120170744_create_subscription_plan_without_interval_counts.rb
471
+ - spec/dummy/db/migrate/20141204170622_create_users.rb
463
472
  - spec/dummy/db/schema.rb
464
473
  - spec/dummy/db/test.sqlite3
465
474
  - spec/dummy/log/development.log
@@ -508,12 +517,14 @@ test_files:
508
517
  - spec/helpers/payola/price_helper_spec.rb
509
518
  - spec/mailers/payola/admin_mailer_spec.rb
510
519
  - spec/mailers/payola/receipt_mailer_spec.rb
520
+ - spec/models/payola/coupon_spec.rb
511
521
  - spec/models/payola/sale_spec.rb
512
522
  - spec/models/payola/stripe_webhook_spec.rb
513
523
  - spec/models/payola/subscription_spec.rb
514
524
  - spec/payola_spec.rb
515
525
  - spec/services/payola/cancel_subscription_spec.rb
516
526
  - spec/services/payola/change_subscription_plan_spec.rb
527
+ - spec/services/payola/change_subscription_quantity_spec.rb
517
528
  - spec/services/payola/charge_card_spec.rb
518
529
  - spec/services/payola/create_plan_spec.rb
519
530
  - spec/services/payola/create_sale_spec.rb