stripe-rails 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/release-drafter.yml +4 -0
- data/.travis.yml +5 -12
- data/Changelog.md +6 -0
- data/Gemfile +8 -11
- data/README.md +8 -0
- data/gemfiles/rails4.gemfile +9 -10
- data/lib/stripe/plans.rb +23 -9
- data/lib/stripe/rails/version.rb +1 -1
- data/test/coupon_builder_spec.rb +2 -0
- data/test/dummy/app/views/stripes/new.html.erb +5 -1
- data/test/dummy/config/application.rb +2 -0
- data/test/dummy/config/environments/development.rb +5 -5
- data/test/pings_controller_spec.rb +1 -0
- data/test/plan_builder_spec.rb +48 -3
- data/test/spec_helper.rb +3 -1
- data/test/support/application_system_test_case.rb +1 -4
- data/test/support/null_system_test_case.rb +1 -1
- metadata +3 -3
- data/gemfiles/rails5.gemfile +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a48f7cd53408976274d19e00765d59c76aa0e4ae69e7accaf4b0e58de6737db
|
4
|
+
data.tar.gz: 0cdb70b8481b375c043ed622082376da4342712ed1a389170eccbc944a668713
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe441c8ddb0f65fea0b8ae401609c8dc9ea3f24b8426168fc2b93f830fa895911e2f1649ef570d73b48f6f73dd80eb6b3fbd68f687561d5fd613424c97e558a9
|
7
|
+
data.tar.gz: e8451147cfcb761affc302a442da37ad0311ce09201a515d4c29205724463e301d9c63e5998df2af7481d9c38e33955fd24654837b88e7fda7a53e2878eebade
|
data/.travis.yml
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.5.
|
4
|
-
- 2.4.
|
5
|
-
- 2.3.
|
6
|
-
|
7
|
-
|
3
|
+
- 2.5.1
|
4
|
+
- 2.4.4
|
5
|
+
- 2.3.7
|
6
|
+
addons:
|
7
|
+
chrome: stable
|
8
8
|
env:
|
9
9
|
global:
|
10
10
|
- GIT_COMMITTED_AT=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then git log -1 --pretty=format:%ct;
|
@@ -22,13 +22,6 @@ script:
|
|
22
22
|
gemfile:
|
23
23
|
- Gemfile
|
24
24
|
- gemfiles/rails4.gemfile
|
25
|
-
- gemfiles/rails5.gemfile
|
26
|
-
matrix:
|
27
|
-
exclude:
|
28
|
-
- rvm: 2.1.10
|
29
|
-
gemfile: Gemfile
|
30
|
-
- rvm: 2.1.10
|
31
|
-
gemfile: gemfiles/rails5.gemfile
|
32
25
|
notifications:
|
33
26
|
slack:
|
34
27
|
secure: csciM073msTrOOdVYVXdAsrx2sR3Y1BKL0VvlSsYxBJawDa8BFNl6Fw8Uz1V2n4OfnkMvMCME4I3EXsCb4Kl5omnK+7ibeCzzzkCR5VwUs5/vLY7awUfCiihSCqg5ULAp2T1whQJUl5HY9Ot62sujIUX/FUhPzdbCqaKQ7cVkUo=
|
data/Changelog.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 1.3.0 (2018-07-23)
|
2
|
+
|
3
|
+
* do not create new product when product id is provided (#115) - Thanks to @renchap for reporting this
|
4
|
+
* updates travis to latest rubies (#112) - Note that after this change we will only run tests on Ruby 2.5, 2.4 and 2.3
|
5
|
+
|
6
|
+
|
1
7
|
## 1.2.2 (2018-04-16)
|
2
8
|
|
3
9
|
* adds callback form `customer.source.expiring`. Thanks @Japestrale!
|
data/Gemfile
CHANGED
@@ -3,23 +3,20 @@ source 'https://rubygems.org'
|
|
3
3
|
# Specify your gem's dependencies in stripe-rails.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
gem
|
7
|
-
gem "rake"
|
8
|
-
gem 'tzinfo'
|
9
|
-
gem 'mocha'
|
10
|
-
gem 'pry'
|
6
|
+
gem 'rake'
|
11
7
|
|
12
8
|
group :development, :test do
|
13
9
|
gem 'm'
|
14
10
|
end
|
15
11
|
|
16
12
|
group :test do
|
13
|
+
gem 'mocha'
|
17
14
|
gem 'simplecov', require: false
|
18
|
-
|
19
|
-
# release https://github.com/rebelidealist/stripe-ruby-mock/pull/433
|
20
|
-
gem 'stripe-ruby-mock', github: 'rebelidealist/stripe-ruby-mock'
|
21
|
-
gem 'poltergeist' # required for system tests
|
22
|
-
gem 'phantomjs' # ditto
|
23
|
-
gem 'puma' # ditto
|
15
|
+
gem 'stripe-ruby-mock'
|
24
16
|
gem 'webmock'
|
17
|
+
# Required for system tests
|
18
|
+
gem 'capybara'
|
19
|
+
gem 'chromedriver-helper'
|
20
|
+
gem 'puma'
|
21
|
+
gem 'selenium-webdriver'
|
25
22
|
end
|
data/README.md
CHANGED
@@ -145,6 +145,14 @@ Stripe.plan :gold do |plan|
|
|
145
145
|
plan.amount = 999 # $9.99
|
146
146
|
plan.interval = 'month'
|
147
147
|
end
|
148
|
+
|
149
|
+
Stripe.plan :bronze do |plan|
|
150
|
+
# Use an existing product id to prevent a new plan from
|
151
|
+
# getting created
|
152
|
+
plan.product_id = 'prod_XXXXXXXXXXXXXX'
|
153
|
+
plan.amount = 999 # $9.99
|
154
|
+
plan.interval = 'month'
|
155
|
+
end
|
148
156
|
```
|
149
157
|
|
150
158
|
This will define constants for these plans in the Stripe::Plans module so that you
|
data/gemfiles/rails4.gemfile
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
source :rubygems
|
2
2
|
|
3
|
-
gem 'rails', '~> 4'
|
3
|
+
gem 'rails', '~> 4.2'
|
4
4
|
|
5
|
-
gem
|
6
|
-
gem "rake"
|
7
|
-
gem 'tzinfo'
|
8
|
-
gem 'mocha'
|
9
|
-
gem 'pry'
|
5
|
+
gem 'rake'
|
10
6
|
gem 'responders', '~> 2.0' # to support Rails 4.2
|
11
7
|
gem 'stripe'
|
12
|
-
gem 'stripe-ruby-mock', '~> 2.4'
|
13
8
|
|
14
9
|
group :test do
|
10
|
+
gem 'mocha'
|
15
11
|
gem 'simplecov', require: false
|
16
|
-
gem '
|
17
|
-
gem 'phantomjs', :require => 'phantomjs/poltergeist'
|
18
|
-
gem 'puma'
|
12
|
+
gem 'stripe-ruby-mock'
|
19
13
|
gem 'webmock'
|
14
|
+
# Required for system tests
|
15
|
+
gem 'capybara'
|
16
|
+
gem 'chromedriver-helper'
|
17
|
+
gem 'puma'
|
18
|
+
gem 'selenium-webdriver'
|
20
19
|
end
|
data/lib/stripe/plans.rb
CHANGED
@@ -3,16 +3,26 @@ module Stripe
|
|
3
3
|
include ConfigurationBuilder
|
4
4
|
|
5
5
|
configuration_for :plan do
|
6
|
-
attr_accessor :name,
|
7
|
-
:
|
6
|
+
attr_accessor :name,
|
7
|
+
:amount,
|
8
|
+
:interval,
|
9
|
+
:interval_count,
|
10
|
+
:trial_period_days,
|
11
|
+
:currency,
|
12
|
+
:metadata,
|
13
|
+
:statement_descriptor,
|
14
|
+
:product_id
|
8
15
|
|
9
|
-
validates_presence_of :id, :amount, :currency
|
16
|
+
validates_presence_of :id, :amount, :currency
|
10
17
|
|
11
|
-
validates_inclusion_of
|
12
|
-
|
18
|
+
validates_inclusion_of :interval,
|
19
|
+
:in => %w(day week month year),
|
20
|
+
:message => "'%{value}' is not one of 'day', 'week', 'month' or 'year'"
|
13
21
|
|
14
22
|
validates :statement_descriptor, :length => { :maximum => 22 }
|
15
23
|
|
24
|
+
validate :name_or_product_id
|
25
|
+
|
16
26
|
def initialize(*args)
|
17
27
|
super(*args)
|
18
28
|
@currency = 'usd'
|
@@ -21,6 +31,9 @@ module Stripe
|
|
21
31
|
end
|
22
32
|
|
23
33
|
private
|
34
|
+
def name_or_product_id
|
35
|
+
errors.add(:base, 'must have a product_id or a name') unless (@product_id.present? ^ @name.present?)
|
36
|
+
end
|
24
37
|
|
25
38
|
def create_options
|
26
39
|
if api_version_after_switch_to_products_in_plans
|
@@ -44,10 +57,7 @@ module Stripe
|
|
44
57
|
def default_create_options
|
45
58
|
{
|
46
59
|
:currency => @currency,
|
47
|
-
product:
|
48
|
-
:name => @name,
|
49
|
-
:statement_descriptor => @statement_descriptor,
|
50
|
-
},
|
60
|
+
product: product_options,
|
51
61
|
:amount => @amount,
|
52
62
|
:interval => @interval,
|
53
63
|
:interval_count => @interval_count,
|
@@ -56,6 +66,10 @@ module Stripe
|
|
56
66
|
}
|
57
67
|
end
|
58
68
|
|
69
|
+
def product_options
|
70
|
+
@product_id.presence || { :name => @name, :statement_descriptor => @statement_descriptor }
|
71
|
+
end
|
72
|
+
|
59
73
|
def create_options_without_products
|
60
74
|
{
|
61
75
|
:currency => @currency,
|
data/lib/stripe/rails/version.rb
CHANGED
data/test/coupon_builder_spec.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
1
|
<%= stripe_javascript_tag (params[:version] || :v3) %>
|
2
2
|
|
3
|
-
<
|
3
|
+
<script>
|
4
|
+
if (typeof(Stripe) != 'undefined') {
|
5
|
+
document.write("<p>This page tests the loading and initialization of Stripe JS</p>");
|
6
|
+
}
|
7
|
+
</script>
|
@@ -10,6 +10,8 @@ require "stripe-rails"
|
|
10
10
|
|
11
11
|
module Dummy
|
12
12
|
class Application < Rails::Application
|
13
|
+
config.stripe.publishable_key = 'pk_test_XXXYYYZZZ'
|
14
|
+
|
13
15
|
# Settings in config/environments/* take precedence over those specified here.
|
14
16
|
# Application configuration should go into files in config/initializers
|
15
17
|
# -- all .rb files in that directory are automatically loaded.
|
@@ -14,7 +14,7 @@ Dummy::Application.configure do
|
|
14
14
|
config.action_controller.perform_caching = false
|
15
15
|
|
16
16
|
# Don't care if the mailer can't send
|
17
|
-
config.action_mailer.raise_delivery_errors = false
|
17
|
+
# config.action_mailer.raise_delivery_errors = false
|
18
18
|
|
19
19
|
# Print deprecation notices to the Rails logger
|
20
20
|
config.active_support.deprecation = :log
|
@@ -23,15 +23,15 @@ Dummy::Application.configure do
|
|
23
23
|
config.action_dispatch.best_standards_support = :builtin
|
24
24
|
|
25
25
|
# Raise exception on mass assignment protection for Active Record models
|
26
|
-
config.active_record.mass_assignment_sanitizer = :strict
|
26
|
+
# config.active_record.mass_assignment_sanitizer = :strict
|
27
27
|
|
28
28
|
# Log the query plan for queries taking more than this (works
|
29
29
|
# with SQLite, MySQL, and PostgreSQL)
|
30
|
-
config.active_record.auto_explain_threshold_in_seconds = 0.5
|
30
|
+
# config.active_record.auto_explain_threshold_in_seconds = 0.5
|
31
31
|
|
32
32
|
# Do not compress assets
|
33
|
-
config.assets.compress = false
|
33
|
+
# config.assets.compress = false
|
34
34
|
|
35
35
|
# Expands the lines which load the assets
|
36
|
-
config.assets.debug = true
|
36
|
+
# config.assets.debug = true
|
37
37
|
end
|
data/test/plan_builder_spec.rb
CHANGED
@@ -14,9 +14,7 @@ describe 'building plans' do
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
after
|
18
|
-
Stripe::Plans.send(:remove_const, :PRIMO)
|
19
|
-
end
|
17
|
+
after { Stripe::Plans.send(:remove_const, :PRIMO) }
|
20
18
|
|
21
19
|
it 'is accessible via id' do
|
22
20
|
Stripe::Plans::PRIMO.wont_be_nil
|
@@ -103,6 +101,28 @@ describe 'building plans' do
|
|
103
101
|
}.must_raise Stripe::InvalidConfigurationError
|
104
102
|
end
|
105
103
|
|
104
|
+
describe 'name and product id validation' do
|
105
|
+
it 'should be valid when using just the product id' do
|
106
|
+
Stripe.plan :prodded do |plan|
|
107
|
+
plan.product_id = 'acme'
|
108
|
+
plan.amount = 999
|
109
|
+
plan.interval = 'month'
|
110
|
+
end
|
111
|
+
Stripe::Plans::PRODDED.wont_be_nil
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should be invalid when using both name and product id' do
|
115
|
+
lambda {
|
116
|
+
Stripe.plan :broken do |plan|
|
117
|
+
plan.name = 'Acme as a service'
|
118
|
+
plan.product_id = 'acme'
|
119
|
+
plan.amount = 999
|
120
|
+
plan.interval = 'month'
|
121
|
+
end
|
122
|
+
}.must_raise Stripe::InvalidConfigurationError
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
106
126
|
describe 'uploading' do
|
107
127
|
include FixtureLoader
|
108
128
|
|
@@ -166,6 +186,31 @@ describe 'building plans' do
|
|
166
186
|
)
|
167
187
|
Stripe::Plans::GOLD.put!
|
168
188
|
end
|
189
|
+
|
190
|
+
describe 'when using a product id' do
|
191
|
+
before do
|
192
|
+
Stripe::Plans::GOLD.product_id = 'prod_XXXXXXXXXXXXXX'
|
193
|
+
Stripe::Plans::GOLD.name = nil
|
194
|
+
end
|
195
|
+
after do
|
196
|
+
Stripe::Plans::GOLD.product_id = nil
|
197
|
+
Stripe::Plans::GOLD.name = 'Solid Gold'
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'creates the plan online with the product id' do
|
201
|
+
Stripe::Plan.expects(:create).with(
|
202
|
+
:id => :gold,
|
203
|
+
:currency => 'usd',
|
204
|
+
:product => 'prod_XXXXXXXXXXXXXX',
|
205
|
+
:amount => 699,
|
206
|
+
:interval => 'month',
|
207
|
+
:interval_count => 1,
|
208
|
+
:trial_period_days => 0,
|
209
|
+
:metadata => nil,
|
210
|
+
)
|
211
|
+
Stripe::Plans::GOLD.put!
|
212
|
+
end
|
213
|
+
end
|
169
214
|
end
|
170
215
|
|
171
216
|
describe 'when api_version is not set for api versions that support products' do
|
data/test/spec_helper.rb
CHANGED
@@ -8,6 +8,8 @@ require 'minitest/autorun'
|
|
8
8
|
require 'webmock/minitest'
|
9
9
|
WebMock.disable_net_connect!(allow_localhost: true)
|
10
10
|
|
11
|
+
require 'selenium-webdriver'
|
12
|
+
|
11
13
|
# Configure Rails Environment
|
12
14
|
ENV["RAILS_ENV"] = "test"
|
13
15
|
ENV['STRIPE_SECRET_KEY'] = 'XYZ'
|
@@ -28,4 +30,4 @@ end
|
|
28
30
|
Stripe::Engine.testing = true
|
29
31
|
require 'mocha/setup'
|
30
32
|
|
31
|
-
require 'irb'
|
33
|
+
require 'irb'
|
@@ -1,11 +1,8 @@
|
|
1
1
|
require File.expand_path("null_system_test_case", __dir__)
|
2
|
-
require "capybara/poltergeist"
|
3
|
-
require 'phantomjs/poltergeist'
|
4
2
|
|
5
3
|
# For Rails 4 compat
|
6
4
|
SystemTestCaseKlass = defined?(ActionDispatch::SystemTestCase) ? ActionDispatch::SystemTestCase : NullSystemTestCase
|
7
5
|
|
8
6
|
class ApplicationSystemTestCase < SystemTestCaseKlass
|
9
|
-
|
10
|
-
driven_by :poltergeist, options: { js_errors: true, inspector: true, phantomjs: Phantomjs.path }
|
7
|
+
driven_by :selenium_chrome_headless
|
11
8
|
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.3.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: 2018-
|
13
|
+
date: 2018-07-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -62,6 +62,7 @@ extensions: []
|
|
62
62
|
extra_rdoc_files: []
|
63
63
|
files:
|
64
64
|
- ".codeclimate.yml"
|
65
|
+
- ".github/release-drafter.yml"
|
65
66
|
- ".gitignore"
|
66
67
|
- ".rubocop.yml"
|
67
68
|
- ".travis.yml"
|
@@ -80,7 +81,6 @@ files:
|
|
80
81
|
- app/views/stripe/_js.html.erb
|
81
82
|
- config/routes.rb
|
82
83
|
- gemfiles/rails4.gemfile
|
83
|
-
- gemfiles/rails5.gemfile
|
84
84
|
- lib/generators/stripe/install_generator.rb
|
85
85
|
- lib/generators/templates/coupons.rb
|
86
86
|
- lib/generators/templates/plans.rb
|
data/gemfiles/rails5.gemfile
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
source :rubygems
|
2
|
-
|
3
|
-
gem 'rails', '~> 5'
|
4
|
-
|
5
|
-
gem "bundler", ">= 1.3.0"
|
6
|
-
gem "rake"
|
7
|
-
gem 'tzinfo'
|
8
|
-
gem 'mocha'
|
9
|
-
gem 'pry'
|
10
|
-
gem 'responders', '~> 2.0' # to support Rails 4.2
|
11
|
-
gem 'stripe'
|
12
|
-
gem 'stripe-ruby-mock', '~> 2.4'
|
13
|
-
|
14
|
-
group :test do
|
15
|
-
gem 'simplecov', require: false
|
16
|
-
gem 'poltergeist'
|
17
|
-
gem 'phantomjs', :require => 'phantomjs/poltergeist'
|
18
|
-
gem 'puma'
|
19
|
-
gem 'webmock'
|
20
|
-
end
|