stripe-rails 1.8.2 → 2.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +40 -0
- data/Changelog.md +27 -0
- data/Gemfile +4 -4
- data/README.md +29 -9
- data/app/models/stripe/event_dispatch.rb +15 -3
- data/gemfiles/{rails4.gemfile → rails51.gemfile} +6 -5
- data/gemfiles/rails52.gemfile +20 -0
- data/lib/generators/templates/products.rb +2 -2
- data/lib/stripe/billing_tier.rb +34 -0
- data/lib/stripe/callbacks.rb +2 -4
- data/lib/stripe/engine.rb +10 -1
- data/lib/stripe/plans.rb +33 -5
- data/lib/stripe/products.rb +2 -0
- data/lib/stripe/rails.rb +1 -0
- data/lib/stripe/rails/tasks.rake +2 -2
- data/lib/stripe/rails/version.rb +1 -1
- data/stripe-rails.gemspec +2 -2
- data/test/callbacks_spec.rb +15 -15
- data/test/coupon_builder_spec.rb +4 -4
- data/test/dummy/config/stripe/plans.rb +21 -0
- data/test/dummy_apis_controller_spec.rb +1 -1
- data/test/events_controller_spec.rb +35 -3
- data/test/javascript_helper_spec.rb +12 -12
- data/test/plan_builder_spec.rb +112 -36
- data/test/product_builder_spec.rb +11 -11
- data/test/spec_helper.rb +2 -2
- data/test/stripe_initializers_spec.rb +33 -21
- data/test/support/application_system_test_case.rb +2 -7
- data/test/testing_spec.rb +8 -8
- metadata +13 -17
- data/.travis.yml +0 -28
- data/app/controllers/stripe/pings_controller.rb +0 -10
- data/app/models/stripe/ping.rb +0 -9
- data/test/pings_controller_spec.rb +0 -18
- data/test/support/null_system_test_case.rb +0 -11
data/lib/stripe/rails/version.rb
CHANGED
data/stripe-rails.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.name = "stripe-rails"
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = Stripe::Rails::VERSION
|
17
|
-
gem.add_dependency 'rails', '>=
|
18
|
-
gem.add_dependency 'stripe', '>=
|
17
|
+
gem.add_dependency 'rails', '>= 5.1'
|
18
|
+
gem.add_dependency 'stripe', '>= 3.15.0'
|
19
19
|
gem.add_dependency 'responders'
|
20
20
|
end
|
data/test/callbacks_spec.rb
CHANGED
@@ -31,9 +31,9 @@ describe Stripe::Callbacks do
|
|
31
31
|
describe 'when it is invoked for the invoice.payment_succeeded event' do
|
32
32
|
it 'is invoked for the invoice.payment_succeeded event' do
|
33
33
|
subject
|
34
|
-
@event.wont_be_nil
|
35
|
-
@event.type.must_equal 'invoice.payment_succeeded'
|
36
|
-
@target.total.must_equal 6999
|
34
|
+
_(@event).wont_be_nil
|
35
|
+
_(@event.type).must_equal 'invoice.payment_succeeded'
|
36
|
+
_(@target.total).must_equal 6999
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -42,7 +42,7 @@ describe Stripe::Callbacks do
|
|
42
42
|
|
43
43
|
it 'the invoice.payment_succeeded callback is not invoked' do
|
44
44
|
subject
|
45
|
-
@event.must_be_nil
|
45
|
+
_(@event).must_be_nil
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -50,7 +50,7 @@ describe Stripe::Callbacks do
|
|
50
50
|
before { run_callback_with(callback) { fail } }
|
51
51
|
|
52
52
|
it 'causes the whole webhook to fail' do
|
53
|
-
->{ subject }.must_raise RuntimeError
|
53
|
+
_(-> { subject }).must_raise RuntimeError
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -61,8 +61,8 @@ describe Stripe::Callbacks do
|
|
61
61
|
|
62
62
|
it 'does not cause the webhook to fail' do
|
63
63
|
subject
|
64
|
-
last_response.status.must_be :>=, 200
|
65
|
-
last_response.status.must_be :<, 300
|
64
|
+
_(last_response.status).must_be :>=, 200
|
65
|
+
_(last_response.status).must_be :<, 300
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -75,7 +75,7 @@ describe Stripe::Callbacks do
|
|
75
75
|
|
76
76
|
it 'it will be run' do
|
77
77
|
subject
|
78
|
-
events.first.type.must_equal 'invoice.payment_failed'
|
78
|
+
_(events.first.type).must_equal 'invoice.payment_failed'
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
@@ -84,7 +84,7 @@ describe Stripe::Callbacks do
|
|
84
84
|
|
85
85
|
it 'it will be run' do
|
86
86
|
subject
|
87
|
-
events.first.type.must_equal 'foo.bar.baz'
|
87
|
+
_(events.first.type).must_equal 'foo.bar.baz'
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
@@ -109,7 +109,7 @@ describe Stripe::Callbacks do
|
|
109
109
|
describe 'when a prior attribute was not specified' do
|
110
110
|
it 'does not fire events' do
|
111
111
|
subject
|
112
|
-
events.length.must_equal 0
|
112
|
+
_(events.length).must_equal 0
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
@@ -117,7 +117,7 @@ describe Stripe::Callbacks do
|
|
117
117
|
before { @stubbed_event.data.previous_attributes['closed'] = true }
|
118
118
|
it 'fires events' do
|
119
119
|
subject
|
120
|
-
events.length.must_equal 1
|
120
|
+
_(events.length).must_equal 1
|
121
121
|
end
|
122
122
|
end
|
123
123
|
end
|
@@ -134,7 +134,7 @@ describe Stripe::Callbacks do
|
|
134
134
|
describe 'when a prior attribute was not specified' do
|
135
135
|
it 'does not fire events' do
|
136
136
|
subject
|
137
|
-
events.length.must_equal 0
|
137
|
+
_(events.length).must_equal 0
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
@@ -142,7 +142,7 @@ describe Stripe::Callbacks do
|
|
142
142
|
before { @stubbed_event.data.previous_attributes['subtotal'] = 699 }
|
143
143
|
it 'fire events' do
|
144
144
|
subject
|
145
|
-
events.length.must_equal 1
|
145
|
+
_(events.length).must_equal 1
|
146
146
|
end
|
147
147
|
end
|
148
148
|
end
|
@@ -159,7 +159,7 @@ describe Stripe::Callbacks do
|
|
159
159
|
describe 'when the lambda is not true' do
|
160
160
|
it 'does not fire events' do
|
161
161
|
subject
|
162
|
-
events.length.must_equal 0
|
162
|
+
_(events.length).must_equal 0
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
@@ -167,7 +167,7 @@ describe Stripe::Callbacks do
|
|
167
167
|
before { @stubbed_event.data.previous_attributes['closed'] = 'false' }
|
168
168
|
it 'fires events' do
|
169
169
|
subject
|
170
|
-
events.length.must_equal 1
|
170
|
+
_(events.length).must_equal 1
|
171
171
|
end
|
172
172
|
end
|
173
173
|
end
|
data/test/coupon_builder_spec.rb
CHANGED
@@ -13,7 +13,7 @@ describe 'building coupons' do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
it "allows a single redemption by default" do
|
16
|
-
@coupon.max_redemptions.must_equal 1
|
16
|
+
_(@coupon.max_redemptions).must_equal 1
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -33,8 +33,8 @@ describe 'building coupons' do
|
|
33
33
|
after {Stripe::Coupons.send(:remove_const, :GOLD25)}
|
34
34
|
|
35
35
|
it 'is accessible via hash lookup (symbol/string agnostic)' do
|
36
|
-
Stripe::Coupons[:gold25].must_equal Stripe::Coupons::GOLD25
|
37
|
-
Stripe::Coupons['gold25'].must_equal Stripe::Coupons::GOLD25
|
36
|
+
_(Stripe::Coupons[:gold25]).must_equal Stripe::Coupons::GOLD25
|
37
|
+
_(Stripe::Coupons['gold25']).must_equal Stripe::Coupons::GOLD25
|
38
38
|
end
|
39
39
|
|
40
40
|
describe 'uploading' do
|
@@ -116,7 +116,7 @@ describe 'building coupons' do
|
|
116
116
|
end
|
117
117
|
describe 'with missing mandatory values' do
|
118
118
|
it 'raises an exception after configuring it' do
|
119
|
-
proc {Stripe.coupon(:bad) {}}.must_raise Stripe::InvalidConfigurationError
|
119
|
+
_(proc {Stripe.coupon(:bad) {}}).must_raise Stripe::InvalidConfigurationError
|
120
120
|
end
|
121
121
|
end
|
122
122
|
end
|
@@ -26,3 +26,24 @@ Stripe.plan :metered do |plan|
|
|
26
26
|
plan.aggregate_usage = 'max'
|
27
27
|
plan.billing_scheme = 'per_unit'
|
28
28
|
end
|
29
|
+
|
30
|
+
Stripe.plan :tiered do |plan|
|
31
|
+
plan.name = 'Tiered'
|
32
|
+
plan.aggregate_usage = 'max'
|
33
|
+
plan.billing_scheme = 'tiered'
|
34
|
+
# interval must be either 'day', 'week', 'month' or 'year'
|
35
|
+
plan.interval = 'month'
|
36
|
+
plan.interval_count = 1
|
37
|
+
plan.tiers = [
|
38
|
+
{
|
39
|
+
unit_amount: 1500,
|
40
|
+
up_to: 10
|
41
|
+
},
|
42
|
+
{
|
43
|
+
unit_amount: 1000,
|
44
|
+
up_to: 'inf'
|
45
|
+
}
|
46
|
+
]
|
47
|
+
plan.tiers_mode = 'graduated'
|
48
|
+
plan.usage_type = 'metered'
|
49
|
+
end
|
@@ -24,7 +24,7 @@ describe Stripe::EventsController do
|
|
24
24
|
end
|
25
25
|
subject { post '/stripe/events', params.to_json }
|
26
26
|
|
27
|
-
it { subject.must_be :ok? }
|
27
|
+
it { _(subject).must_be :ok? }
|
28
28
|
end
|
29
29
|
|
30
30
|
describe 'signed webhooks' do
|
@@ -50,12 +50,44 @@ describe Stripe::EventsController do
|
|
50
50
|
|
51
51
|
it 'returns bad_request when invalid' do
|
52
52
|
Stripe::Webhook.expects(:construct_event).raises(Stripe::SignatureVerificationError.new('msg', 'sig_header'))
|
53
|
-
subject.must_be :bad_request?
|
53
|
+
_(subject).must_be :bad_request?
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'returns ok when valid' do
|
57
57
|
Stripe::Webhook.expects(:construct_event).returns(Stripe::Event.construct_from(params))
|
58
|
-
subject.must_be :ok?
|
58
|
+
_(subject).must_be :ok?
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'multiple signed webhooks' do
|
63
|
+
before do
|
64
|
+
header 'Stripe-Signature', 't=1537832721,v1=123,v0=123'
|
65
|
+
app.config.stripe.signing_secrets = ['SECRET1', 'SECRET2']
|
66
|
+
end
|
67
|
+
|
68
|
+
after { app.config.stripe.signing_secrets = nil }
|
69
|
+
|
70
|
+
let(:params) {
|
71
|
+
{
|
72
|
+
id: 'evt_00000000000001',
|
73
|
+
type: 'customer.updated',
|
74
|
+
data: {
|
75
|
+
object: 'customer',
|
76
|
+
fingerprint: 'xxxyyyzzz'
|
77
|
+
},
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
subject { post '/stripe/events', params.to_json }
|
82
|
+
|
83
|
+
it 'returns bad_request when invalid' do
|
84
|
+
Stripe::Webhook.expects(:construct_event).twice.raises(Stripe::SignatureVerificationError.new('msg', 'sig_header'))
|
85
|
+
_(subject).must_be :bad_request?
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'returns ok when valid' do
|
89
|
+
Stripe::Webhook.expects(:construct_event).returns(Stripe::Event.construct_from(params))
|
90
|
+
_(subject).must_be :ok?
|
59
91
|
end
|
60
92
|
end
|
61
93
|
end
|
@@ -8,13 +8,13 @@ describe Stripe::JavascriptHelper do
|
|
8
8
|
describe '#stripe_javascript_tag' do
|
9
9
|
describe 'when no options are passed' do
|
10
10
|
it 'should default to v3' do
|
11
|
-
view.stripe_javascript_tag.must_include 'https://js.stripe.com/v3/'
|
11
|
+
_(view.stripe_javascript_tag).must_include 'https://js.stripe.com/v3/'
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
describe 'when the v2 option is passed' do
|
16
16
|
it 'should default to v2' do
|
17
|
-
view.stripe_javascript_tag(:v2).must_include 'https://js.stripe.com/v2/'
|
17
|
+
_(view.stripe_javascript_tag(:v2)).must_include 'https://js.stripe.com/v2/'
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -22,12 +22,12 @@ describe Stripe::JavascriptHelper do
|
|
22
22
|
before { Rails.application.config.stripe.debug_js = true }
|
23
23
|
after { Rails.application.config.stripe.debug_js = false }
|
24
24
|
it 'should render the debug js' do
|
25
|
-
view.stripe_javascript_tag(:v1).must_include 'https://js.stripe.com/v1/stripe-debug.js'
|
25
|
+
_(view.stripe_javascript_tag(:v1)).must_include 'https://js.stripe.com/v1/stripe-debug.js'
|
26
26
|
end
|
27
27
|
|
28
28
|
describe 'when v3 is selected' do
|
29
29
|
it 'should not render debug js' do
|
30
|
-
view.stripe_javascript_tag(:v3).wont_include 'https://js.stripe.com/v1/stripe-debug.js'
|
30
|
+
_(view.stripe_javascript_tag(:v3)).wont_include 'https://js.stripe.com/v1/stripe-debug.js'
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -37,7 +37,7 @@ describe Stripe::JavascriptHelper do
|
|
37
37
|
subject { view.render :partial => 'stripe/js' }
|
38
38
|
|
39
39
|
it 'should render correctly' do
|
40
|
-
subject.must_include 'https://js.stripe.com/v3/'
|
40
|
+
_(subject).must_include 'https://js.stripe.com/v3/'
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -45,35 +45,35 @@ describe Stripe::JavascriptHelper do
|
|
45
45
|
subject { view.render :partial => 'stripe/js', locals: {stripe_js_version: 'v2'} }
|
46
46
|
|
47
47
|
it 'should render correctly' do
|
48
|
-
subject.must_include 'https://js.stripe.com/v2/'
|
48
|
+
_(subject).must_include 'https://js.stripe.com/v2/'
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
describe '#stripe_elements_tag' do
|
53
53
|
describe 'when no options are passed' do
|
54
54
|
it 'should display the form' do
|
55
|
-
view.stripe_elements_tag(
|
55
|
+
_(view.stripe_elements_tag(
|
56
56
|
submit_path: '/charge',
|
57
|
-
).must_include 'Credit or debit card'
|
57
|
+
)).must_include 'Credit or debit card'
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
describe 'with options' do
|
62
62
|
describe 'without default js' do
|
63
63
|
it 'wont include the default script tag' do
|
64
|
-
view.stripe_elements_tag(
|
64
|
+
_(view.stripe_elements_tag(
|
65
65
|
submit_path: '/charge',
|
66
66
|
js_path: 'another/path'
|
67
|
-
).wont_include '<script id="stripe_elements_js">'
|
67
|
+
)).wont_include '<script id="stripe_elements_js">'
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
71
|
describe 'without default css' do
|
72
72
|
it 'wont include the default style tag' do
|
73
|
-
view.stripe_elements_tag(
|
73
|
+
_(view.stripe_elements_tag(
|
74
74
|
submit_path: '/charge',
|
75
75
|
css_path: 'another/path'
|
76
|
-
).wont_include '<style>'
|
76
|
+
)).wont_include '<style>'
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
data/test/plan_builder_spec.rb
CHANGED
@@ -23,16 +23,16 @@ describe 'building plans' do
|
|
23
23
|
after { Stripe::Plans.send(:remove_const, :PRIMO) }
|
24
24
|
|
25
25
|
it 'is accessible via id' do
|
26
|
-
Stripe::Plans::PRIMO.wont_be_nil
|
26
|
+
_(Stripe::Plans::PRIMO).wont_be_nil
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'is accessible via collection' do
|
30
|
-
Stripe::Plans.all.must_include Stripe::Plans::PRIMO
|
30
|
+
_(Stripe::Plans.all).must_include Stripe::Plans::PRIMO
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'is accessible via hash lookup (symbol/string agnostic)' do
|
34
|
-
Stripe::Plans[:primo].must_equal Stripe::Plans::PRIMO
|
35
|
-
Stripe::Plans['primo'].must_equal Stripe::Plans::PRIMO
|
34
|
+
_(Stripe::Plans[:primo]).must_equal Stripe::Plans::PRIMO
|
35
|
+
_(Stripe::Plans['primo']).must_equal Stripe::Plans::PRIMO
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'accepts a billing interval of a day' do
|
@@ -42,7 +42,7 @@ describe 'building plans' do
|
|
42
42
|
plan.interval = 'day'
|
43
43
|
end
|
44
44
|
|
45
|
-
Stripe::Plans::DAILY.wont_be_nil
|
45
|
+
_(Stripe::Plans::DAILY).wont_be_nil
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'accepts a billing interval of a week' do
|
@@ -52,7 +52,7 @@ describe 'building plans' do
|
|
52
52
|
plan.interval = 'week'
|
53
53
|
end
|
54
54
|
|
55
|
-
Stripe::Plans::WEEKLY.wont_be_nil
|
55
|
+
_(Stripe::Plans::WEEKLY).wont_be_nil
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'accepts a billing interval of a month' do
|
@@ -62,7 +62,7 @@ describe 'building plans' do
|
|
62
62
|
plan.interval = 'month'
|
63
63
|
end
|
64
64
|
|
65
|
-
Stripe::Plans::MONTHLY.wont_be_nil
|
65
|
+
_(Stripe::Plans::MONTHLY).wont_be_nil
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'accepts a billing interval of a year' do
|
@@ -72,17 +72,17 @@ describe 'building plans' do
|
|
72
72
|
plan.interval = 'year'
|
73
73
|
end
|
74
74
|
|
75
|
-
Stripe::Plans::YEARLY.wont_be_nil
|
75
|
+
_(Stripe::Plans::YEARLY).wont_be_nil
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'denies arbitrary billing intervals' do
|
79
|
-
lambda {
|
79
|
+
_(lambda {
|
80
80
|
Stripe.plan :broken do |plan|
|
81
81
|
plan.name = 'Acme as a service BROKEN'
|
82
82
|
plan.amount = 999
|
83
83
|
plan.interval = 'anything'
|
84
84
|
end
|
85
|
-
}.must_raise Stripe::InvalidConfigurationError
|
85
|
+
}).must_raise Stripe::InvalidConfigurationError
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'accepts a statement descriptor' do
|
@@ -93,55 +93,55 @@ describe 'building plans' do
|
|
93
93
|
plan.statement_descriptor = 'ACME Monthly'
|
94
94
|
end
|
95
95
|
|
96
|
-
Stripe::Plans::DESCRIBED.wont_be_nil
|
96
|
+
_(Stripe::Plans::DESCRIBED).wont_be_nil
|
97
97
|
end
|
98
98
|
|
99
99
|
it 'denies statement descriptors that are too long' do
|
100
|
-
lambda {
|
100
|
+
_(lambda {
|
101
101
|
Stripe.plan :described do |plan|
|
102
102
|
plan.name = 'Acme as a service'
|
103
103
|
plan.amount = 999
|
104
104
|
plan.interval = 'month'
|
105
105
|
plan.statement_descriptor = 'ACME as a Service Monthly'
|
106
106
|
end
|
107
|
-
}.must_raise Stripe::InvalidConfigurationError
|
107
|
+
}).must_raise Stripe::InvalidConfigurationError
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'denies invalid values for active' do
|
111
|
-
lambda {
|
111
|
+
_(lambda {
|
112
112
|
Stripe.plan :broken do |plan|
|
113
113
|
plan.name = 'Acme as a service'
|
114
114
|
plan.amount = 999
|
115
115
|
plan.interval = 'month'
|
116
116
|
plan.active = 'whatever'
|
117
117
|
end
|
118
|
-
}.must_raise Stripe::InvalidConfigurationError
|
118
|
+
}).must_raise Stripe::InvalidConfigurationError
|
119
119
|
end
|
120
120
|
|
121
121
|
it 'denies invalid values for usage_type' do
|
122
|
-
lambda {
|
122
|
+
_(lambda {
|
123
123
|
Stripe.plan :broken do |plan|
|
124
124
|
plan.name = 'Acme as a service'
|
125
125
|
plan.amount = 999
|
126
126
|
plan.interval = 'month'
|
127
127
|
plan.usage_type = 'whatever'
|
128
128
|
end
|
129
|
-
}.must_raise Stripe::InvalidConfigurationError
|
129
|
+
}).must_raise Stripe::InvalidConfigurationError
|
130
130
|
end
|
131
131
|
|
132
132
|
it 'denies invalid values for aggregate_usage' do
|
133
|
-
lambda {
|
133
|
+
_(lambda {
|
134
134
|
Stripe.plan :broken do |plan|
|
135
135
|
plan.name = 'Acme as a service'
|
136
136
|
plan.amount = 999
|
137
137
|
plan.interval = 'month'
|
138
138
|
plan.aggregate_usage = 'whatever'
|
139
139
|
end
|
140
|
-
}.must_raise Stripe::InvalidConfigurationError
|
140
|
+
}).must_raise Stripe::InvalidConfigurationError
|
141
141
|
end
|
142
142
|
|
143
143
|
it 'denies aggregate_usage if usage type is liecensed' do
|
144
|
-
lambda {
|
144
|
+
_(lambda {
|
145
145
|
Stripe.plan :broken do |plan|
|
146
146
|
plan.name = 'Acme as a service'
|
147
147
|
plan.amount = 999
|
@@ -149,30 +149,30 @@ describe 'building plans' do
|
|
149
149
|
plan.usage_type = 'licensed'
|
150
150
|
plan.aggregate_usage = 'sum'
|
151
151
|
end
|
152
|
-
}.must_raise Stripe::InvalidConfigurationError
|
152
|
+
}).must_raise Stripe::InvalidConfigurationError
|
153
153
|
end
|
154
154
|
|
155
155
|
|
156
156
|
it 'denies invalid values for billing_scheme' do
|
157
|
-
lambda {
|
157
|
+
_(lambda {
|
158
158
|
Stripe.plan :broken do |plan|
|
159
159
|
plan.name = 'Acme as a service'
|
160
160
|
plan.amount = 999
|
161
161
|
plan.interval = 'month'
|
162
162
|
plan.billing_scheme = 'whatever'
|
163
163
|
end
|
164
|
-
}.must_raise Stripe::InvalidConfigurationError
|
164
|
+
}).must_raise Stripe::InvalidConfigurationError
|
165
165
|
end
|
166
166
|
|
167
167
|
it 'denies invalid values for tiers_mode' do
|
168
|
-
lambda {
|
168
|
+
_(lambda {
|
169
169
|
Stripe.plan :broken do |plan|
|
170
170
|
plan.name = 'Acme as a service'
|
171
171
|
plan.amount = 999
|
172
172
|
plan.interval = 'month'
|
173
173
|
plan.tiers_mode = 'whatever'
|
174
174
|
end
|
175
|
-
}.must_raise Stripe::InvalidConfigurationError
|
175
|
+
}).must_raise Stripe::InvalidConfigurationError
|
176
176
|
end
|
177
177
|
|
178
178
|
describe 'name and product id validation' do
|
@@ -182,18 +182,18 @@ describe 'building plans' do
|
|
182
182
|
plan.amount = 999
|
183
183
|
plan.interval = 'month'
|
184
184
|
end
|
185
|
-
Stripe::Plans::PRODDED.wont_be_nil
|
185
|
+
_(Stripe::Plans::PRODDED).wont_be_nil
|
186
186
|
end
|
187
187
|
|
188
188
|
it 'should be invalid when using both name and product id' do
|
189
|
-
lambda {
|
189
|
+
_(lambda {
|
190
190
|
Stripe.plan :broken do |plan|
|
191
191
|
plan.name = 'Acme as a service'
|
192
192
|
plan.product_id = 'acme'
|
193
193
|
plan.amount = 999
|
194
194
|
plan.interval = 'month'
|
195
195
|
end
|
196
|
-
}.must_raise Stripe::InvalidConfigurationError
|
196
|
+
}).must_raise Stripe::InvalidConfigurationError
|
197
197
|
end
|
198
198
|
end
|
199
199
|
|
@@ -275,6 +275,82 @@ describe 'building plans' do
|
|
275
275
|
Stripe::Plans::METERED.put!
|
276
276
|
end
|
277
277
|
|
278
|
+
it 'creates a tiered plan' do
|
279
|
+
Stripe::Plan.expects(:create).with(
|
280
|
+
:id => :tiered,
|
281
|
+
:currency => 'usd',
|
282
|
+
:product => {
|
283
|
+
:name => 'Tiered',
|
284
|
+
:statement_descriptor => nil,
|
285
|
+
},
|
286
|
+
:interval => 'month',
|
287
|
+
:interval_count => 1,
|
288
|
+
:trial_period_days => 0,
|
289
|
+
:usage_type => 'metered',
|
290
|
+
:aggregate_usage => 'max',
|
291
|
+
:billing_scheme => 'tiered',
|
292
|
+
:tiers => [
|
293
|
+
{
|
294
|
+
:unit_amount => 1500,
|
295
|
+
:up_to => 10
|
296
|
+
},
|
297
|
+
{
|
298
|
+
:unit_amount => 1000,
|
299
|
+
:up_to => 'inf'
|
300
|
+
}
|
301
|
+
],
|
302
|
+
:tiers_mode => 'graduated'
|
303
|
+
)
|
304
|
+
plan = Stripe::Plans::TIERED
|
305
|
+
Stripe::Plans::TIERED.put!
|
306
|
+
end
|
307
|
+
|
308
|
+
describe 'when passed invalid arguments for tiered pricing' do
|
309
|
+
it 'raises a Stripe::InvalidConfigurationError when billing tiers are invalid' do
|
310
|
+
lambda {
|
311
|
+
Stripe.plan "Bad Tiers".to_sym do |plan|
|
312
|
+
plan.name = 'Acme as a service BAD TIERS'
|
313
|
+
plan.constant_name = 'BAD_TIERS'
|
314
|
+
plan.interval = 'month'
|
315
|
+
plan.interval_count = 1
|
316
|
+
plan.trial_period_days = 30
|
317
|
+
plan.usage_type = 'metered'
|
318
|
+
plan.tiers_mode = 'graduated'
|
319
|
+
plan.billing_scheme = 'per_unit'
|
320
|
+
plan.aggregate_usage = 'sum'
|
321
|
+
plan.tiers = [
|
322
|
+
{
|
323
|
+
unit_amount: 1500,
|
324
|
+
up_to: 10
|
325
|
+
},
|
326
|
+
{
|
327
|
+
unit_amount: 1000,
|
328
|
+
}
|
329
|
+
]
|
330
|
+
end
|
331
|
+
}.must_raise Stripe::InvalidConfigurationError
|
332
|
+
end
|
333
|
+
|
334
|
+
it 'raises a Stripe::InvalidConfigurationError when billing tiers is not an array' do
|
335
|
+
lambda {
|
336
|
+
Stripe.plan "Bad Tiers".to_sym do |plan|
|
337
|
+
plan.name = 'Acme as a service BAD TIERS'
|
338
|
+
plan.constant_name = 'BAD_TIERS'
|
339
|
+
plan.interval = 'month'
|
340
|
+
plan.interval_count = 1
|
341
|
+
plan.trial_period_days = 30
|
342
|
+
plan.usage_type = 'metered'
|
343
|
+
plan.tiers_mode = 'graduated'
|
344
|
+
plan.billing_scheme = 'per_unit'
|
345
|
+
plan.aggregate_usage = 'sum'
|
346
|
+
plan.tiers = {
|
347
|
+
unit_amount: 1500,
|
348
|
+
up_to: 10
|
349
|
+
}
|
350
|
+
end
|
351
|
+
}.must_raise Stripe::InvalidConfigurationError
|
352
|
+
end
|
353
|
+
end
|
278
354
|
|
279
355
|
describe 'when using a product id' do
|
280
356
|
before do
|
@@ -343,10 +419,10 @@ describe 'building plans' do
|
|
343
419
|
|
344
420
|
describe 'with missing mandatory values' do
|
345
421
|
it 'raises an exception after configuring it' do
|
346
|
-
|
422
|
+
_(-> { Stripe.plan(:bad) {} }).must_raise Stripe::InvalidConfigurationError
|
347
423
|
end
|
348
424
|
end
|
349
|
-
|
425
|
+
|
350
426
|
describe 'with custom constant name' do
|
351
427
|
before do
|
352
428
|
Stripe.plan "Primo Plan".to_sym do |plan|
|
@@ -370,28 +446,28 @@ describe 'building plans' do
|
|
370
446
|
after { Stripe::Plans.send(:remove_const, :PRIMO_PLAN) }
|
371
447
|
|
372
448
|
it 'is accessible via upcased constant_name' do
|
373
|
-
Stripe::Plans::PRIMO_PLAN.wont_be_nil
|
449
|
+
_(Stripe::Plans::PRIMO_PLAN).wont_be_nil
|
374
450
|
end
|
375
451
|
|
376
452
|
it 'is accessible via collection' do
|
377
|
-
Stripe::Plans.all.must_include Stripe::Plans::PRIMO_PLAN
|
453
|
+
_(Stripe::Plans.all).must_include Stripe::Plans::PRIMO_PLAN
|
378
454
|
end
|
379
455
|
|
380
456
|
it 'is accessible via hash lookup (symbol/string agnostic)' do
|
381
|
-
Stripe::Plans[:primo_plan].must_equal Stripe::Plans::PRIMO_PLAN
|
382
|
-
Stripe::Plans['primo_plan'].must_equal Stripe::Plans::PRIMO_PLAN
|
457
|
+
_(Stripe::Plans[:primo_plan]).must_equal Stripe::Plans::PRIMO_PLAN
|
458
|
+
_(Stripe::Plans['primo_plan']).must_equal Stripe::Plans::PRIMO_PLAN
|
383
459
|
end
|
384
460
|
|
385
461
|
describe 'constant name validation' do
|
386
462
|
it 'should be invalid when providing a constant name that can not be used for Ruby constant' do
|
387
|
-
lambda {
|
463
|
+
_(lambda {
|
388
464
|
Stripe.plan "Primo Plan".to_sym do |plan|
|
389
465
|
plan.name = 'Acme as a service PRIMO'
|
390
466
|
plan.constant_name = 'PRIMO PLAN'
|
391
467
|
plan.amount = 999
|
392
468
|
plan.interval = 'month'
|
393
469
|
end
|
394
|
-
}.must_raise Stripe::InvalidConfigurationError
|
470
|
+
}).must_raise Stripe::InvalidConfigurationError
|
395
471
|
end
|
396
472
|
end
|
397
473
|
|