stripe-rails 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b69dd28ba0f7e285499222f566f1a3d94792a3d928c07e6f820231758a1076f2
4
- data.tar.gz: 20001b39f130cf45f32b4418acd4a7b25c2f855eb4c82150af7a0efdd1761b01
3
+ metadata.gz: eb58cd2c4b57bfb766859f950ea819137df7d25df3064654877db23a853fc181
4
+ data.tar.gz: b93b09f34648ff133397a56606a37bb5067130d19aef9007c823e13b993a4cfe
5
5
  SHA512:
6
- metadata.gz: a5ca715db15caf73a7261911590c31e8155bf65769ca5d28b3c2c548ddb76f5560ce2a56e45241daf8d614de0a4bfa2fd6c9b5f45d5909cdee8ef224cf7ae727
7
- data.tar.gz: 5883ebce3e32917174404c92c9114e683de9e63bde4bb8c23c8a2d5bfe13ee8586a545bcc9a5c853289cf8be4812a14db0890eff795243f2aaef55a2ee548c4c
6
+ metadata.gz: 39ff75adfde760950733e00324423c99506d53f9cee614a7adc0ec61a2ea14758e9d9a1dc49a4cd2ceac83ed7c7597c8c276cb0cb169ba813c7e2de9da7fe237
7
+ data.tar.gz: 861343d690279311225fda2091e0d318c08c2c4c33e98d4fb73f9e528750a6751e7b0f07a2b1c43341da8a4011e4ff3618c3cee799445a38dd720bfab6d6b250
@@ -1,4 +1,15 @@
1
1
  <!--
2
- Please give us ~1 week to get back to you.
2
+ Thanks a bunch for helping out with the project!
3
+
4
+ Please remember to,
5
+
6
+ 1. Add tests if they do not exist, fix em if they are breaking
7
+ 2. Fix any issues that are stopping Code Climate from passing
8
+ 2. Add a short description of the feature and tag yourself on Changelog.md
9
+
10
+ That's it!
11
+
12
+ Please give me ~1 week to get back to you.
13
+
3
14
  If you'd like to receive occasional updates, sign up for our newsletter at http://tinyletter.com/stripe-rails
4
15
  -->
@@ -1,4 +1,7 @@
1
- ## Unreleased
1
+ ## 2.1.0 (2020-10-18)
2
+
3
+ - Added option to ignore missing API key and don't show any warning. Thanks @ndbroadbent!
4
+ - Handle passing nil to signing_secret= and add tests. Thanks @martron!
2
5
 
3
6
  ## 2.0.0 (2020-09-18)
4
7
 
data/README.md CHANGED
@@ -137,6 +137,14 @@ you prefer to environment variables, you can also set `STRIPE_PUBLISHABLE_KEY`:
137
137
  export STRIPE_PUBLISHABLE_KEY=pk_test_XXXYYYZZZ
138
138
  ```
139
139
 
140
+ If no API key is provided, `stripe-rails` will show a warning: "No stripe.com API key was configured ...". You can silence this warning by setting the `ignore_missing_secret_key` option to `true`:
141
+
142
+ ```ruby
143
+ # config/environments/production.rb
144
+ # ...
145
+ config.stripe.ignore_missing_secret_key = true
146
+ ```
147
+
140
148
  ### Manually set your API version (optional)
141
149
 
142
150
  If you need to test a new API version in development, you can override the version number manually.
@@ -8,12 +8,12 @@ module Stripe
8
8
  attr_accessor :testing
9
9
  end
10
10
 
11
- stripe_config = config.stripe = Struct.new(:api_base, :api_version, :secret_key, :verify_ssl_certs, :signing_secret, :signing_secrets, :publishable_key, :endpoint, :debug_js, :auto_mount, :eager_load, :open_timeout, :read_timeout) do
11
+ stripe_config = config.stripe = Struct.new(:api_base, :api_version, :secret_key, :ignore_missing_secret_key, :verify_ssl_certs, :signing_secret, :signing_secrets, :publishable_key, :endpoint, :debug_js, :auto_mount, :eager_load, :open_timeout, :read_timeout) do
12
12
  # for backwards compatibility treat signing_secret as an alias for signing_secrets
13
13
  def signing_secret=(value)
14
- self.signing_secrets = Array(value)
14
+ self.signing_secrets = value.nil? ? value : Array(value)
15
15
  end
16
-
16
+
17
17
  def signing_secret
18
18
  self.signing_secrets && self.signing_secrets.first
19
19
  end
@@ -43,7 +43,7 @@ module Stripe
43
43
  end
44
44
  secret_key = app.config.stripe.secret_key
45
45
  Stripe.api_key = secret_key unless secret_key.nil?
46
- $stderr.puts <<-MSG unless Stripe.api_key
46
+ $stderr.puts <<-MSG unless Stripe.api_key || app.config.stripe.ignore_missing_secret_key
47
47
  No stripe.com API key was configured for environment #{::Rails.env}! this application will be
48
48
  unable to interact with stripe.com. You can set your API key with either the environment
49
49
  variable `STRIPE_SECRET_KEY` (recommended) or by setting `config.stripe.secret_key` in your
@@ -1,5 +1,5 @@
1
1
  module Stripe
2
2
  module Rails
3
- VERSION = '2.0.0'.freeze
3
+ VERSION = '2.1.0'.freeze
4
4
  end
5
5
  end
@@ -10,6 +10,10 @@ describe Stripe::EventsController do
10
10
  end
11
11
 
12
12
  describe 'the events interface' do
13
+ subject { post '/stripe/events', params.to_json }
14
+
15
+ before { stripe_events_stub }
16
+
13
17
  let(:params) {
14
18
  {
15
19
  id: 'evt_00000000000000',
@@ -17,14 +21,29 @@ describe Stripe::EventsController do
17
21
  data: {object: 'customer'},
18
22
  }
19
23
  }
20
-
21
- before do
24
+ let(:stripe_events_stub) do
22
25
  stub_request(:get, "https://api.stripe.com/v1/events/evt_00000000000000").
23
26
  to_return(status: 200, body: Stripe::Event.construct_from(params).to_json, headers: {})
24
27
  end
25
- subject { post '/stripe/events', params.to_json }
26
28
 
27
29
  it { _(subject).must_be :ok? }
30
+
31
+ it 'should call the stripe_events_stub' do
32
+ subject
33
+ assert_requested(stripe_events_stub)
34
+ end
35
+
36
+ describe 'when signing_secret is nil' do
37
+ before do
38
+ header 'Stripe-Signature', 't=1537832721,v1=123,v0=123'
39
+ app.config.stripe.signing_secret = nil
40
+ end
41
+
42
+ it 'should call the stripe_events_stub' do
43
+ subject
44
+ assert_requested(stripe_events_stub)
45
+ end
46
+ end
28
47
  end
29
48
 
30
49
  describe 'signed webhooks' do
@@ -12,9 +12,10 @@ describe "Configuring the stripe engine" do
12
12
  def rerun_initializers!; initializers.each{|init| init.run(app) }; end
13
13
 
14
14
  after do
15
- Stripe.api_version = nil
16
- Stripe.api_base = 'https://api.stripe.com'
17
- Stripe.api_key = 'XYZ'
15
+ Stripe.api_version = nil
16
+ Stripe.api_base = 'https://api.stripe.com'
17
+ Stripe.api_key = 'XYZ'
18
+ ENV['STRIPE_SECRET_KEY'] = 'XYZ'
18
19
  end
19
20
 
20
21
  describe 'Stripe configurations' do
@@ -40,7 +41,7 @@ describe "Configuring the stripe engine" do
40
41
  app.config.stripe.open_timeout = 33
41
42
  app.config.stripe.read_timeout = 88
42
43
  rerun_initializers!
43
- end
44
+ end
44
45
 
45
46
  it "reads values that is set in the environment" do
46
47
  subject
@@ -56,6 +57,16 @@ describe "Configuring the stripe engine" do
56
57
  _(app.config.stripe.signing_secrets.length).must_equal 1
57
58
  end
58
59
 
60
+ it "supports nil signing_secret" do
61
+ subject
62
+
63
+ app.config.stripe.signing_secret = nil
64
+ rerun_initializers!
65
+
66
+ _(app.config.stripe.signing_secret).must_equal nil
67
+ _(app.config.stripe.signing_secrets).must_equal nil
68
+ end
69
+
59
70
  it "supports multiple signing secrets" do
60
71
  subject
61
72
 
@@ -90,4 +101,36 @@ describe "Configuring the stripe engine" do
90
101
  _(-> { subject }).must_output '', warning_msg
91
102
  end
92
103
  end
104
+
105
+ describe 'missing stripe.secret_key' do
106
+ subject do
107
+ ENV['STRIPE_SECRET_KEY'] = nil
108
+ Stripe.api_key = nil
109
+ app.config.stripe.secret_key = nil
110
+ rerun_initializers!
111
+ end
112
+ let(:warning_msg) { /No stripe.com API key was configured for environment test!/ }
113
+
114
+ it 'should output a warning' do
115
+ _(-> { subject }).must_output '', warning_msg
116
+ end
117
+ end
118
+
119
+ describe 'stripe.ignore_missing_secret_key' do
120
+ subject do
121
+ ENV['STRIPE_SECRET_KEY'] = nil
122
+ Stripe.api_key = nil
123
+ app.config.stripe.secret_key = nil
124
+ app.config.stripe.ignore_missing_secret_key = true
125
+ rerun_initializers!
126
+ end
127
+
128
+ after do
129
+ app.config.stripe.ignore_missing_secret_key = false
130
+ end
131
+
132
+ it 'should not output a warning' do
133
+ _(-> { subject }).must_output '', ''
134
+ end
135
+ end
93
136
  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: 2.0.0
4
+ version: 2.1.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: 2020-09-18 00:00:00.000000000 Z
13
+ date: 2020-10-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails