stripe-rails 1.6.1 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +5 -0
- data/README.md +19 -0
- data/lib/stripe/callbacks.rb +1 -0
- data/lib/stripe/configuration_builder.rb +3 -2
- data/lib/stripe/plans.rb +10 -0
- data/lib/stripe/rails/version.rb +1 -1
- data/test/dummy/config/stripe/plans.rb +7 -0
- data/test/plan_builder_spec.rb +77 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f24ac8d0b91f140510d25e7c614a14e2f2574ea8f3b280c052691f088d5aa9bf
|
4
|
+
data.tar.gz: ce0d05dde985042654708e2701012dfd7c74d38f22c19df4a2cc703effa582b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6353b526babcf9e9e5a5a36282470167aa6a794242038ad78bfabcef3bba00ea76c4aefee7891de01d12f1d0dd52470c1e614f454c5e88e13bc63173258e58b3
|
7
|
+
data.tar.gz: 4b7045a4a6f1abbaafa970ad55c24b96ec31e8d4e1caa1b2ca41dc90346b10f21f3fadbc2cec102087c733f716d39eb79b83a6f2f401d22aeacff7ecfb1f65a8
|
data/Changelog.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## 1.7.0 (2019-05-09)
|
2
|
+
|
3
|
+
* [New Feature] add support for Plan to use a constant name different from plan id thanks @alexagranov !
|
4
|
+
* Add checkout.session.completed webhook thanks @Nitrino !
|
5
|
+
|
1
6
|
## 1.6.1 (2019-03-04)
|
2
7
|
|
3
8
|
* Add new invoice webhooks thanks @noahezekwugo !
|
data/README.md
CHANGED
@@ -194,6 +194,25 @@ Stripe::Plans::SILVER # => 'silver: ACME Silver'
|
|
194
194
|
Stripe::Plans::GOLD # => 'gold: ACME Gold'
|
195
195
|
```
|
196
196
|
|
197
|
+
If you have to support an existing plan with a Stripe plan id that can not
|
198
|
+
be used as a Ruby constant, provide the plan id as a symbol when
|
199
|
+
defining the plan, but provide the name for the constant to define with `constant_name`:
|
200
|
+
|
201
|
+
```ruby
|
202
|
+
Stripe.plan "Silver-Plan".to_sym do |plan|
|
203
|
+
plan.constant_name = 'SILVER_PLAN'
|
204
|
+
end
|
205
|
+
|
206
|
+
Stripe::Plans::SILVER_PLAN # => will be defined
|
207
|
+
# Will map to plan :id => "Silver-Plan" on Stripe
|
208
|
+
```
|
209
|
+
|
210
|
+
**Note** - If you're planning on running `rake stripe:prepare` to
|
211
|
+
create your subscription plans, Stripe will restrict plan ids to match
|
212
|
+
this regexp (`/\A[a-zA-Z0-9_\-]+\z/`) when created via API but still
|
213
|
+
allows creation of plan ids that don't follow this restriction when
|
214
|
+
manually created on stripe.com.
|
215
|
+
|
197
216
|
Coupons are created in much the same way:
|
198
217
|
|
199
218
|
```ruby
|
data/lib/stripe/callbacks.rb
CHANGED
@@ -68,8 +68,9 @@ module Stripe
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def globalize!
|
71
|
-
@
|
72
|
-
@stripe_configuration_class.
|
71
|
+
id_to_use = @constant_name || @id
|
72
|
+
@stripe_configuration_class[id_to_use.to_s.downcase] = self
|
73
|
+
@stripe_configuration_class.const_set(id_to_use.to_s.upcase, self)
|
73
74
|
end
|
74
75
|
|
75
76
|
def put!
|
data/lib/stripe/plans.rb
CHANGED
@@ -7,6 +7,7 @@ module Stripe
|
|
7
7
|
:aggregate_usage,
|
8
8
|
:amount,
|
9
9
|
:billing_scheme,
|
10
|
+
:constant_name,
|
10
11
|
:currency,
|
11
12
|
:interval,
|
12
13
|
:interval_count,
|
@@ -35,6 +36,7 @@ module Stripe
|
|
35
36
|
|
36
37
|
validate :name_or_product_id
|
37
38
|
validate :aggregate_usage_must_be_metered, if: ->(p) { p.aggregate_usage.present? }
|
39
|
+
validate :valid_constant_name, unless: ->(p) { p.constant_name.nil? }
|
38
40
|
|
39
41
|
def initialize(*args)
|
40
42
|
super(*args)
|
@@ -52,6 +54,14 @@ module Stripe
|
|
52
54
|
errors.add(:base, 'must have a product_id or a name') unless (@product_id.present? ^ @name.present?)
|
53
55
|
end
|
54
56
|
|
57
|
+
module ConstTester; end
|
58
|
+
def valid_constant_name
|
59
|
+
ConstTester.const_set(constant_name.to_s.upcase, constant_name)
|
60
|
+
ConstTester.send(:remove_const, constant_name.to_s.upcase.to_sym)
|
61
|
+
rescue NameError
|
62
|
+
errors.add(:constant_name, 'is not a valid Ruby constant name.')
|
63
|
+
end
|
64
|
+
|
55
65
|
def create_options
|
56
66
|
if CurrentApiVersion.after_switch_to_products_in_plans?
|
57
67
|
default_create_options
|
data/lib/stripe/rails/version.rb
CHANGED
@@ -4,6 +4,13 @@ Stripe.plan :gold do |plan|
|
|
4
4
|
plan.interval = 'month'
|
5
5
|
end
|
6
6
|
|
7
|
+
Stripe.plan "Solid Gold".to_sym do |plan|
|
8
|
+
plan.constant_name = 'SOLID_GOLD'
|
9
|
+
plan.name = 'Solid Gold'
|
10
|
+
plan.amount = 699
|
11
|
+
plan.interval = 'month'
|
12
|
+
end
|
13
|
+
|
7
14
|
Stripe.plan :alternative_currency do |plan|
|
8
15
|
plan.name = 'Alternative Currency'
|
9
16
|
plan.amount = 699
|
data/test/plan_builder_spec.rb
CHANGED
@@ -346,4 +346,81 @@ describe 'building plans' do
|
|
346
346
|
proc {Stripe.plan(:bad) {}}.must_raise Stripe::InvalidConfigurationError
|
347
347
|
end
|
348
348
|
end
|
349
|
+
|
350
|
+
describe 'with custom constant name' do
|
351
|
+
before do
|
352
|
+
Stripe.plan "Primo Plan".to_sym do |plan|
|
353
|
+
plan.name = 'Acme as a service PRIMO'
|
354
|
+
plan.constant_name = 'PRIMO_PLAN'
|
355
|
+
plan.amount = 699
|
356
|
+
plan.interval = 'month'
|
357
|
+
plan.interval_count = 3
|
358
|
+
plan.trial_period_days = 30
|
359
|
+
plan.metadata = {:number_of_awesome_things => 5}
|
360
|
+
plan.statement_descriptor = 'Acme Primo'
|
361
|
+
plan.active = true
|
362
|
+
plan.nickname = 'primo'
|
363
|
+
plan.usage_type = 'metered'
|
364
|
+
plan.billing_scheme = 'per_unit'
|
365
|
+
plan.aggregate_usage = 'sum'
|
366
|
+
plan.tiers_mode = 'graduated'
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
after { Stripe::Plans.send(:remove_const, :PRIMO_PLAN) }
|
371
|
+
|
372
|
+
it 'is accessible via upcased constant_name' do
|
373
|
+
Stripe::Plans::PRIMO_PLAN.wont_be_nil
|
374
|
+
end
|
375
|
+
|
376
|
+
it 'is accessible via collection' do
|
377
|
+
Stripe::Plans.all.must_include Stripe::Plans::PRIMO_PLAN
|
378
|
+
end
|
379
|
+
|
380
|
+
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
|
383
|
+
end
|
384
|
+
|
385
|
+
describe 'constant name validation' do
|
386
|
+
it 'should be invalid when providing a constant name that can not be used for Ruby constant' do
|
387
|
+
lambda {
|
388
|
+
Stripe.plan "Primo Plan".to_sym do |plan|
|
389
|
+
plan.name = 'Acme as a service PRIMO'
|
390
|
+
plan.constant_name = 'PRIMO PLAN'
|
391
|
+
plan.amount = 999
|
392
|
+
plan.interval = 'month'
|
393
|
+
end
|
394
|
+
}.must_raise Stripe::InvalidConfigurationError
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
describe 'uploading' do
|
399
|
+
include FixtureLoader
|
400
|
+
|
401
|
+
describe 'when none exists on stripe.com' do
|
402
|
+
let(:headers) { load_request_fixture('stripe_plans_headers_2017.json') }
|
403
|
+
before do
|
404
|
+
Stripe::Plan.stubs(:retrieve).raises(Stripe::InvalidRequestError.new("not found", "id"))
|
405
|
+
|
406
|
+
stub_request(:get, "https://api.stripe.com/v1/plans").
|
407
|
+
with(headers: { 'Authorization'=>'Bearer XYZ',}).
|
408
|
+
to_return(status: 200, body: load_request_fixture('stripe_plans.json'), headers: JSON.parse(headers))
|
409
|
+
end
|
410
|
+
|
411
|
+
it 'creates the plan online' do
|
412
|
+
Stripe::Plan.expects(:create).with(
|
413
|
+
:id => "Solid Gold".to_sym,
|
414
|
+
:currency => 'usd',
|
415
|
+
:name => 'Solid Gold',
|
416
|
+
:amount => 699,
|
417
|
+
:interval => 'month',
|
418
|
+
:interval_count => 1,
|
419
|
+
:trial_period_days => 0
|
420
|
+
)
|
421
|
+
Stripe::Plans::SOLID_GOLD.put!
|
422
|
+
end
|
423
|
+
end
|
424
|
+
end
|
425
|
+
end
|
349
426
|
end
|
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
|
+
version: 1.7.0
|
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: 2019-
|
13
|
+
date: 2019-05-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -184,8 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
184
|
- !ruby/object:Gem::Version
|
185
185
|
version: '0'
|
186
186
|
requirements: []
|
187
|
-
|
188
|
-
rubygems_version: 2.7.7
|
187
|
+
rubygems_version: 3.0.3
|
189
188
|
signing_key:
|
190
189
|
specification_version: 4
|
191
190
|
summary: A gem to integrate stripe into your rails app
|