payola-payments 1.3.0 → 1.3.1
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/app/assets/javascripts/payola/subscription_checkout_button.js +1 -1
- data/app/services/payola/#update_card.rb# +27 -0
- data/app/services/payola/invoice_behavior.rb +2 -2
- data/app/services/payola/start_subscription.rb +13 -10
- data/app/views/payola/subscriptions/_cancel.html.erb +8 -4
- data/app/views/payola/subscriptions/_checkout.html.erb +3 -2
- data/db/migrate/20141001170138_create_payola_sales.rb +3 -3
- data/db/migrate/20141002203725_add_stripe_customer_id_to_sale.rb +1 -1
- data/db/migrate/20141029135848_add_owner_to_payola_sale.rb +1 -1
- data/db/migrate/20141107025420_add_guid_to_payola_subscriptions.rb +1 -1
- data/lib/payola.rb +1 -1
- data/lib/payola/version.rb +1 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +668 -0
- data/spec/dummy/log/test.log +58763 -0
- data/spec/services/payola/#start_subscription_spec.rb# +95 -0
- data/spec/services/payola/change_subscription_quantity_spec.rb +7 -3
- data/spec/services/payola/start_subscription_spec.rb +14 -1
- data/spec/services/payola/update_card_spec.rb +3 -1
- metadata +7 -4
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Payola
|
4
|
+
describe StartSubscription do
|
5
|
+
let(:stripe_helper) { StripeMock.create_test_helper }
|
6
|
+
let(:token){ StripeMock.generate_card_token({}) }
|
7
|
+
let(:user){ User.create }
|
8
|
+
|
9
|
+
describe "#call" do
|
10
|
+
it "should create a customer" do
|
11
|
+
plan = create(:subscription_plan)
|
12
|
+
subscription = create(:subscription, state: 'processing', plan: plan, stripe_token: token)
|
13
|
+
StartSubscription.call(subscription)
|
14
|
+
expect(subscription.reload.stripe_customer_id).to_not be_nil
|
15
|
+
end
|
16
|
+
it "should capture credit card info" do
|
17
|
+
plan = create(:subscription_plan)
|
18
|
+
subscription = create(:subscription, state: 'processing', plan: plan, stripe_token: token)
|
19
|
+
StartSubscription.call(subscription)
|
20
|
+
expect(subscription.reload.stripe_id).to_not be_nil
|
21
|
+
expect(subscription.reload.card_last4).to_not be_nil
|
22
|
+
expect(subscription.reload.card_expiration).to_not be_nil
|
23
|
+
expect(subscription.reload.card_type).to_not be_nil
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should pass through coupon code" do
|
27
|
+
plan = create(:subscription_plan)
|
28
|
+
subscription = create(:subscription, state: 'processing', plan: plan, stripe_token: token, coupon: 'test')
|
29
|
+
StartSubscription.call(subscription)
|
30
|
+
expect(subscription.reload.stripe_id).to_not be_nil
|
31
|
+
sub = Stripe::Customer.retrieve(subscription.stripe_customer_id).subscriptions.retrieve(subscription.stripe_id)
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "on error" do
|
35
|
+
it "should update the error attribute" do
|
36
|
+
StripeMock.prepare_card_error(:card_declined, :new_customer)
|
37
|
+
plan = create(:subscription_plan)
|
38
|
+
subscription = create(:subscription, state: 'processing', plan: plan, stripe_token: token)
|
39
|
+
StartSubscription.call(subscription)
|
40
|
+
expect(subscription.reload.error).to_not be_nil
|
41
|
+
expect(subscription.errored?).to be true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should re-use an existing customer" do
|
46
|
+
plan = create(:subscription_plan)
|
47
|
+
subscription = create(:subscription, state: 'processing', plan: plan, stripe_token: token, owner: user)
|
48
|
+
StartSubscription.call(subscription)
|
49
|
+
CancelSubscription.call(subscription)
|
50
|
+
|
51
|
+
subscription2 = create(:subscription, state: 'processing', plan: plan, owner: user)
|
52
|
+
StartSubscription.call(subscription2)
|
53
|
+
expect(subscription2.reload.stripe_customer_id).to_not be_nil
|
54
|
+
expect(subscription2.reload.stripe_customer_id).to eq subscription.reload.stripe_customer_id
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should not re-use an existing customer that has been deleted" do
|
58
|
+
plan = create(:subscription_plan)
|
59
|
+
subscription = create(:subscription, state: 'processing', plan: plan, stripe_token: token, owner: user)
|
60
|
+
StartSubscription.call(subscription)
|
61
|
+
deleted_customer_id = subscription.reload.stripe_customer_id
|
62
|
+
Stripe::Customer.retrieve(deleted_customer_id).delete
|
63
|
+
|
64
|
+
subscription2 = create(:subscription, state: 'processing', plan: plan, owner: user)
|
65
|
+
StartSubscription.call(subscription2)
|
66
|
+
expect(subscription2.reload.stripe_customer_id).to_not be_nil
|
67
|
+
expect(subscription2.reload.stripe_customer_id).to_not eq deleted_customer_id
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should create an invoice item with a setup fee" do
|
71
|
+
plan = create(:subscription_plan)
|
72
|
+
subscription = create(:subscription, state: 'processing', plan: plan, stripe_token: token, owner: user, setup_fee: 100)
|
73
|
+
StartSubscription.call(subscription)
|
74
|
+
|
75
|
+
ii = Stripe::InvoiceItem.all(customer: subscription.stripe_customer_id).first
|
76
|
+
expect(ii).to_not be_nil
|
77
|
+
expect(ii.amount).to eq 100
|
78
|
+
expect(ii.description).to eq "Setup Fee"
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should allow the plan to override the setup fee description" do
|
82
|
+
plan = create(:subscription_plan)
|
83
|
+
subscription = create(:subscription, state: 'processing', plan: plan, stripe_token: token, owner: user, setup_fee: 100)
|
84
|
+
|
85
|
+
expect(plan).to receive(:setup_fee_description).with(subscription).and_return('Random Mystery Fee')
|
86
|
+
StartSubscription.call(subscription)
|
87
|
+
|
88
|
+
ii = Stripe::InvoiceItem.all(customer: subscription.stripe_customer_id).first
|
89
|
+
expect(ii).to_not be_nil
|
90
|
+
expect(ii.amount).to eq 100
|
91
|
+
expect(ii.description).to eq 'Random Mystery Fee'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -5,13 +5,17 @@ module Payola
|
|
5
5
|
let(:stripe_helper) { StripeMock.create_test_helper }
|
6
6
|
|
7
7
|
describe "#call" do
|
8
|
-
before do
|
8
|
+
before(:each) do
|
9
9
|
@plan = create(:subscription_plan)
|
10
|
+
expect(@plan.errors).to be_blank
|
10
11
|
|
11
12
|
token = StripeMock.generate_card_token({})
|
12
|
-
@subscription = create(:subscription, quantity: 1, stripe_token: token)
|
13
|
+
@subscription = create(:subscription, quantity: 1, stripe_token: token, plan: @plan, state: 'processing')
|
13
14
|
StartSubscription.call(@subscription)
|
14
|
-
|
15
|
+
expect(@subscription.error).to be_nil
|
16
|
+
expect(@subscription.active?).to be_truthy
|
17
|
+
@subscription = Payola::ChangeSubscriptionQuantity.call(@subscription, 2)
|
18
|
+
expect(@subscription.errors).to be_blank
|
15
19
|
end
|
16
20
|
|
17
21
|
it "should change the quantity on the stripe subscription" do
|
@@ -45,6 +45,19 @@ module Payola
|
|
45
45
|
expect(subscription2.reload.stripe_customer_id).to eq subscription.reload.stripe_customer_id
|
46
46
|
end
|
47
47
|
|
48
|
+
it "should not re-use an existing customer that has been deleted" do
|
49
|
+
plan = create(:subscription_plan)
|
50
|
+
subscription = create(:subscription, state: 'processing', plan: plan, stripe_token: token, owner: user)
|
51
|
+
StartSubscription.call(subscription)
|
52
|
+
deleted_customer_id = subscription.reload.stripe_customer_id
|
53
|
+
Stripe::Customer.retrieve(deleted_customer_id).delete
|
54
|
+
|
55
|
+
subscription2 = create(:subscription, state: 'processing', plan: plan, owner: user)
|
56
|
+
StartSubscription.call(subscription2)
|
57
|
+
expect(subscription2.reload.stripe_customer_id).to_not be_nil
|
58
|
+
expect(subscription2.reload.stripe_customer_id).to_not eq deleted_customer_id
|
59
|
+
end
|
60
|
+
|
48
61
|
it "should create an invoice item with a setup fee" do
|
49
62
|
plan = create(:subscription_plan)
|
50
63
|
subscription = create(:subscription, state: 'processing', plan: plan, stripe_token: token, owner: user, setup_fee: 100)
|
@@ -66,7 +79,7 @@ module Payola
|
|
66
79
|
ii = Stripe::InvoiceItem.all(customer: subscription.stripe_customer_id).first
|
67
80
|
expect(ii).to_not be_nil
|
68
81
|
expect(ii.amount).to eq 100
|
69
|
-
expect(ii.description).to eq 'Random Mystery Fee'
|
82
|
+
expect(ii.description).to eq 'Random Mystery Fee'
|
70
83
|
end
|
71
84
|
end
|
72
85
|
end
|
@@ -9,8 +9,10 @@ module Payola
|
|
9
9
|
@plan = create(:subscription_plan)
|
10
10
|
|
11
11
|
token = StripeMock.generate_card_token({})
|
12
|
-
@subscription = create(:subscription, plan: @plan, stripe_token: token)
|
12
|
+
@subscription = create(:subscription, plan: @plan, stripe_token: token, state: 'processing')
|
13
13
|
StartSubscription.call(@subscription)
|
14
|
+
expect(@subscription.error).to be_nil
|
15
|
+
expect(@subscription.active?).to be_truthy
|
14
16
|
token2 = StripeMock.generate_card_token({last4: '2233', exp_year: '2021', exp_month: '11', brand: 'JCB'})
|
15
17
|
Payola::UpdateCard.call(@subscription, token2)
|
16
18
|
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.3.
|
4
|
+
version: 1.3.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: 2015-03-
|
11
|
+
date: 2015-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -42,14 +42,14 @@ dependencies:
|
|
42
42
|
name: stripe
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 1.20.1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 1.20.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
@@ -198,6 +198,7 @@ files:
|
|
198
198
|
- app/models/payola/sale.rb
|
199
199
|
- app/models/payola/stripe_webhook.rb
|
200
200
|
- app/models/payola/subscription.rb
|
201
|
+
- app/services/payola/#update_card.rb#
|
201
202
|
- app/services/payola/cancel_subscription.rb
|
202
203
|
- app/services/payola/change_subscription_plan.rb
|
203
204
|
- app/services/payola/change_subscription_quantity.rb
|
@@ -374,6 +375,7 @@ files:
|
|
374
375
|
- spec/models/payola/stripe_webhook_spec.rb
|
375
376
|
- spec/models/payola/subscription_spec.rb
|
376
377
|
- spec/payola_spec.rb
|
378
|
+
- spec/services/payola/#start_subscription_spec.rb#
|
377
379
|
- spec/services/payola/cancel_subscription_spec.rb
|
378
380
|
- spec/services/payola/change_subscription_plan_spec.rb
|
379
381
|
- spec/services/payola/change_subscription_quantity_spec.rb
|
@@ -524,6 +526,7 @@ test_files:
|
|
524
526
|
- spec/models/payola/stripe_webhook_spec.rb
|
525
527
|
- spec/models/payola/subscription_spec.rb
|
526
528
|
- spec/payola_spec.rb
|
529
|
+
- spec/services/payola/#start_subscription_spec.rb#
|
527
530
|
- spec/services/payola/cancel_subscription_spec.rb
|
528
531
|
- spec/services/payola/change_subscription_plan_spec.rb
|
529
532
|
- spec/services/payola/change_subscription_quantity_spec.rb
|