stripe-rails 1.4.1 → 1.4.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bf8cbe43d20c035c706373d6b7c1c243ecbbbc1f413b566d873fae9233ec99b
4
- data.tar.gz: 614d54926d8eab719fc561e93d09936b11230da6fcb92aa409c6f5d296de1ce5
3
+ metadata.gz: cc77c2742f14d5d7042f2a3ed06af604144c2d956e0fd5a627f45c01e82a9461
4
+ data.tar.gz: 570149b8d68d0429d5257e45099739ba9da0c52fe1c5432251207e98edc2f9e8
5
5
  SHA512:
6
- metadata.gz: 7c38b50e62b9ffb78e267d9f7d7149d3e9abd745a71075ce0bb6ef9297f70a8be2c345d9decfe08de1e38c16a8ca6ea83873ed7cb1e9ccad4875fae76c1fd6bc
7
- data.tar.gz: 5ff91f2d49f04e30cd3332764873faed47a8e3b46f2ac98f02e067e5f900db2202438f59543571a4e9bd5be5a830ed112d477092b2679f55c1808b160db75586
6
+ metadata.gz: f5eb46629a7af4564ce45f3bb4f219f93413c88bc46773b2546fb8032d40441c164d62ac207e868ac2efb46622df0cb1a1256e6b9915bd9cfd3675e6d88d8a1b
7
+ data.tar.gz: f865412f3696550203443d037b26fb8472a818049014622b67391b7565c0fe97116391129378734cf7e422c110b0c8a740d1c75e913cf229b203a3315e6647c0
@@ -1,3 +1,7 @@
1
+ ## 1.4.2 (2018-08-06)
2
+
3
+ * New attributes for Stripe Billing Plans.
4
+
1
5
  ## 1.4.1 (2018-08-03)
2
6
 
3
7
  * Fixes ActionController::UnknownFormat errors - Thanks to @ndbroadbent !
@@ -3,15 +3,21 @@ module Stripe
3
3
  include ConfigurationBuilder
4
4
 
5
5
  configuration_for :plan do
6
- attr_accessor :name,
6
+ attr_accessor :active,
7
+ :aggregate_usage,
7
8
  :amount,
9
+ :billing_scheme,
10
+ :currency,
8
11
  :interval,
9
12
  :interval_count,
10
- :trial_period_days,
11
- :currency,
12
13
  :metadata,
14
+ :name,
15
+ :nickname,
16
+ :product_id,
13
17
  :statement_descriptor,
14
- :product_id
18
+ :tiers_mode,
19
+ :trial_period_days,
20
+ :usage_type
15
21
 
16
22
  validates_presence_of :id, :amount, :currency
17
23
 
@@ -21,7 +27,14 @@ module Stripe
21
27
 
22
28
  validates :statement_descriptor, :length => { :maximum => 22 }
23
29
 
30
+ validates :active, inclusion: { in: [true, false] }, allow_nil: true
31
+ validates :usage_type, inclusion: { in: %w{ metered licensed } }, allow_nil: true
32
+ validates :billing_scheme, inclusion: { in: %w{ per_unit tiered } }, allow_nil: true
33
+ validates :aggregate_usage, inclusion: { in: %w{ sum last_during_period last_ever max } }, allow_nil: true
34
+ validates :tiers_mode, inclusion: { in: %w{ graduated volume } }, allow_nil: true
35
+
24
36
  validate :name_or_product_id
37
+ validate :aggregate_usage_must_be_metered, if: ->(p) { p.aggregate_usage.present? }
25
38
 
26
39
  def initialize(*args)
27
40
  super(*args)
@@ -31,6 +44,10 @@ module Stripe
31
44
  end
32
45
 
33
46
  private
47
+ def aggregate_usage_must_be_metered
48
+ errors.add(:aggregate_usage, 'usage_type must be metered') unless (usage_type == 'metered')
49
+ end
50
+
34
51
  def name_or_product_id
35
52
  errors.add(:base, 'must have a product_id or a name') unless (@product_id.present? ^ @name.present?)
36
53
  end
@@ -1,5 +1,5 @@
1
1
  module Stripe
2
2
  module Rails
3
- VERSION = '1.4.1'
3
+ VERSION = '1.4.2'
4
4
  end
5
5
  end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Stripe::EventsController do
4
+ parallelize_me!
5
+ include Rack::Test::Methods
6
+
7
+ let(:app) { Rails.application }
8
+ before do
9
+ header 'Accept', 'application/json'
10
+ header 'Content-Type', 'application/json'
11
+ end
12
+
13
+ describe 'the events interface' do
14
+ let(:params) {
15
+ {
16
+ id: 'evt_00000000000000',
17
+ type: 'customer.updated',
18
+ data: {object: 'customer'},
19
+ }
20
+ }
21
+ subject { post '/stripe/events', params.to_json }
22
+
23
+ it { subject.must_be :ok? }
24
+ end
25
+ end
@@ -11,6 +11,12 @@ describe 'building plans' do
11
11
  plan.trial_period_days = 30
12
12
  plan.metadata = {:number_of_awesome_things => 5}
13
13
  plan.statement_descriptor = 'Acme Primo'
14
+ plan.active = true
15
+ plan.nickname = 'primo'
16
+ plan.usage_type = 'metered'
17
+ plan.billing_scheme = 'per_unit'
18
+ plan.aggregate_usage = 'sum'
19
+ plan.tiers_mode = 'graduated'
14
20
  end
15
21
  end
16
22
 
@@ -101,6 +107,74 @@ describe 'building plans' do
101
107
  }.must_raise Stripe::InvalidConfigurationError
102
108
  end
103
109
 
110
+ it 'denies invalid values for active' do
111
+ lambda {
112
+ Stripe.plan :broken do |plan|
113
+ plan.name = 'Acme as a service'
114
+ plan.amount = 999
115
+ plan.interval = 'month'
116
+ plan.active = 'whatever'
117
+ end
118
+ }.must_raise Stripe::InvalidConfigurationError
119
+ end
120
+
121
+ it 'denies invalid values for usage_type' do
122
+ lambda {
123
+ Stripe.plan :broken do |plan|
124
+ plan.name = 'Acme as a service'
125
+ plan.amount = 999
126
+ plan.interval = 'month'
127
+ plan.usage_type = 'whatever'
128
+ end
129
+ }.must_raise Stripe::InvalidConfigurationError
130
+ end
131
+
132
+ it 'denies invalid values for aggregate_usage' do
133
+ lambda {
134
+ Stripe.plan :broken do |plan|
135
+ plan.name = 'Acme as a service'
136
+ plan.amount = 999
137
+ plan.interval = 'month'
138
+ plan.aggregate_usage = 'whatever'
139
+ end
140
+ }.must_raise Stripe::InvalidConfigurationError
141
+ end
142
+
143
+ it 'denies aggregate_usage if usage type is liecensed' do
144
+ lambda {
145
+ Stripe.plan :broken do |plan|
146
+ plan.name = 'Acme as a service'
147
+ plan.amount = 999
148
+ plan.interval = 'month'
149
+ plan.usage_type = 'licensed'
150
+ plan.aggregate_usage = 'sum'
151
+ end
152
+ }.must_raise Stripe::InvalidConfigurationError
153
+ end
154
+
155
+
156
+ it 'denies invalid values for billing_scheme' do
157
+ lambda {
158
+ Stripe.plan :broken do |plan|
159
+ plan.name = 'Acme as a service'
160
+ plan.amount = 999
161
+ plan.interval = 'month'
162
+ plan.billing_scheme = 'whatever'
163
+ end
164
+ }.must_raise Stripe::InvalidConfigurationError
165
+ end
166
+
167
+ it 'denies invalid values for tiers_mode' do
168
+ lambda {
169
+ Stripe.plan :broken do |plan|
170
+ plan.name = 'Acme as a service'
171
+ plan.amount = 999
172
+ plan.interval = 'month'
173
+ plan.tiers_mode = 'whatever'
174
+ end
175
+ }.must_raise Stripe::InvalidConfigurationError
176
+ end
177
+
104
178
  describe 'name and product id validation' do
105
179
  it 'should be valid when using just the product id' do
106
180
  Stripe.plan :prodded do |plan|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Lowell
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-09-04 00:00:00.000000000 Z
13
+ date: 2018-09-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -142,6 +142,7 @@ files:
142
142
  - test/dummy_apis_controller_spec.rb
143
143
  - test/dummy_stripes_controller_spec.rb
144
144
  - test/event.json
145
+ - test/events_controller_spec.rb
145
146
  - test/fixtures/stripe_plans.json
146
147
  - test/fixtures/stripe_plans_headers.json
147
148
  - test/fixtures/stripe_plans_headers_2017.json
@@ -226,6 +227,7 @@ test_files:
226
227
  - test/dummy_apis_controller_spec.rb
227
228
  - test/dummy_stripes_controller_spec.rb
228
229
  - test/event.json
230
+ - test/events_controller_spec.rb
229
231
  - test/fixtures/stripe_plans.json
230
232
  - test/fixtures/stripe_plans_headers.json
231
233
  - test/fixtures/stripe_plans_headers_2017.json