stripe-rails 1.0.0 → 1.0.1
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 +4 -4
- data/Changelog.md +4 -0
- data/Gemfile +3 -0
- data/app/views/stripe/_js.html.erb +14 -11
- data/gemfiles/rails4.gemfile +3 -0
- data/gemfiles/rails5.gemfile +3 -0
- data/lib/stripe/rails/version.rb +1 -1
- data/test/callbacks_spec.rb +103 -100
- data/test/dummy/app/controllers/stripes_controller.rb +4 -0
- data/test/dummy/app/views/layouts/application.html.erb +0 -2
- data/test/dummy/app/views/stripes/new.html.erb +3 -0
- data/test/dummy/config/routes.rb +1 -0
- data/test/dummy_stripes_controller_spec.rb +17 -0
- data/test/pings_controller_spec.rb +18 -0
- data/test/spec_helper.rb +2 -0
- data/test/support/application_system_test_case.rb +11 -0
- data/test/support/callback_helpers.rb +15 -0
- data/test/support/null_system_test_case.rb +11 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7064822cbaf76623c55cdb77ca09fc0024ad995
|
4
|
+
data.tar.gz: c431f805019acf8b747078e464219936bd105ab2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da180772c4e9efa49b565cefcdc9b81328cac4ed8d8afdde59f1313734c0df76b64f014520914f118a908341b0e239fd224e4e0d988cd1290bf179fc1574ba31
|
7
|
+
data.tar.gz: 073db41216f36f6041f1844ebe58413850dc4f3bb75bfc9cefe6305f9c6dec6aa233eb58164b1a515f0be88b1a33a61908bb8de6c9006799abfb917dac3468ed
|
data/Changelog.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## 1.0.1 (2017-08-08)
|
2
|
+
|
3
|
+
* Fixes a bug with Stripe JS V3, i.e. `Stripe.setPublishableKey` is no longer a function. Thanks to @kartikluke for reporting this.
|
4
|
+
|
1
5
|
## 1.0.0 (2017-07-24 - Breaky McBreakface)
|
2
6
|
|
3
7
|
* [BREAKING] Update to latest stripe events (thanks @hopsoft). Note that if you are using the `after_customer_card_created`, `after_customer_card_updated` or `after_customer_card_deleted` callbacks, you MUST update them to `after_customer_source_created`, `after_customer_source_updated` or `after_customer_source_deleted` respectively. You also need to start using [Stripe API Version > 2015-02-18](https://stripe.com/docs/upgrades#2015-02-18) or else the webhook might not work as expected.
|
data/Gemfile
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
-
<%- case (stripe_js_version || '
|
1
|
+
<%- case (stripe_js_version || 'v3') %>
|
2
2
|
<%- when 'v1', 'v2' %>
|
3
|
-
<%- if ::Rails.application.config.stripe.debug_js %>
|
4
|
-
<script type="text/javascript" src="https://js.stripe.com/<%=stripe_js_version%>/stripe-debug.js"></script>
|
5
|
-
<%- else %>
|
6
|
-
<script type="text/javascript" src="https://js.stripe.com/<%=stripe_js_version%>/"></script>
|
7
|
-
<%- end %>
|
3
|
+
<%- if ::Rails.application.config.stripe.debug_js %>
|
4
|
+
<script type="text/javascript" src="https://js.stripe.com/<%=stripe_js_version%>/stripe-debug.js"></script>
|
5
|
+
<%- else %>
|
6
|
+
<script type="text/javascript" src="https://js.stripe.com/<%=stripe_js_version%>/"></script>
|
7
|
+
<%- end %>
|
8
|
+
<script type="text/javascript">
|
9
|
+
Stripe.setPublishableKey("<%= Rails.application.config.stripe.publishable_key or fail 'No stripe.com publishable key found. Please set config.stripe.publishable_key in config/application.rb to one of your publishable keys, which can be found here: https://manage.stripe.com/#account/apikeys' %>")
|
10
|
+
</script>
|
8
11
|
<%- when 'v3' # the debug js for v3 isn't available %>
|
9
|
-
<script type="text/javascript" src="https://js.stripe.com/<%=stripe_js_version%>/"></script>
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
<script type="text/javascript" src="https://js.stripe.com/<%=stripe_js_version%>/"></script>
|
13
|
+
<script type="text/javascript">
|
14
|
+
var stripe = Stripe("<%= Rails.application.config.stripe.publishable_key or fail 'No stripe.com publishable key found. Please set config.stripe.publishable_key in config/application.rb to one of your publishable keys, which can be found here: https://manage.stripe.com/#account/apikeys' %>");
|
15
|
+
</script>
|
16
|
+
<%- end %>
|
data/gemfiles/rails4.gemfile
CHANGED
data/gemfiles/rails5.gemfile
CHANGED
data/lib/stripe/rails/version.rb
CHANGED
data/test/callbacks_spec.rb
CHANGED
@@ -3,114 +3,90 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe Stripe::Callbacks do
|
5
5
|
include Rack::Test::Methods
|
6
|
+
include CallbackHelpers
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
let(:app) { Rails.application }
|
9
|
+
let(:event) { JSON.parse(File.read File.expand_path('../event.json', __FILE__)) }
|
10
|
+
let(:invoice) { JSON.parse(File.read File.expand_path('../invoice.json', __FILE__)) }
|
11
|
+
let(:content) { event }
|
12
|
+
let(:observer) { Class.new }
|
10
13
|
|
11
14
|
before do
|
12
15
|
header 'Accept', 'application/json'
|
13
16
|
header 'Content-Type', 'application/json'
|
14
|
-
@observer = Class.new.tap do |cls|
|
15
|
-
cls.class_eval do
|
16
|
-
include Stripe::Callbacks
|
17
|
-
end
|
18
|
-
end
|
19
17
|
|
20
|
-
|
21
|
-
invoice = JSON.parse(File.read File.expand_path('../invoice.json', __FILE__))
|
22
|
-
event['data']['object'] = invoice
|
18
|
+
observer.include Stripe::Callbacks
|
23
19
|
|
24
|
-
|
25
|
-
self.type = @content['type']
|
26
|
-
end
|
27
|
-
|
28
|
-
def type=(type)
|
29
|
-
@content['type'] = type
|
30
|
-
@stubbed_event = Stripe::Event.construct_from(@content)
|
31
|
-
Stripe::Event.stubs(:retrieve).returns(@stubbed_event)
|
32
|
-
end
|
33
|
-
|
34
|
-
after do
|
35
|
-
::Stripe::Callbacks.clear_callbacks!
|
36
|
-
end
|
20
|
+
event['data']['object'] = invoice
|
37
21
|
|
38
|
-
|
39
|
-
assert Dummy.const_defined?(:ModelWithCallbacks), 'should have eager loaded'
|
40
|
-
assert Dummy.const_defined?(:ModuleWithCallbacks), 'should have eager loaded'
|
22
|
+
self.type = content['type']
|
41
23
|
end
|
24
|
+
after { ::Stripe::Callbacks.clear_callbacks! }
|
42
25
|
|
43
|
-
|
44
|
-
get '/stripe/ping'
|
45
|
-
assert last_response.ok?
|
46
|
-
end
|
26
|
+
subject { post 'stripe/events', JSON.pretty_generate(content) }
|
47
27
|
|
48
28
|
describe 'defined with a bang' do
|
49
|
-
|
50
|
-
before
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
29
|
+
let(:callback) { :after_invoice_payment_succeeded! }
|
30
|
+
before { run_callback_with(callback) {|target, e| @event = e; @target = target} }
|
31
|
+
|
32
|
+
describe 'when it is invoked for the invoice.payment_succeeded event' do
|
33
|
+
it 'is invoked for the invoice.payment_succeeded event' do
|
34
|
+
subject
|
35
|
+
@event.wont_be_nil
|
36
|
+
@event.type.must_equal 'invoice.payment_succeeded'
|
37
|
+
@target.total.must_equal 6999
|
56
38
|
end
|
57
39
|
end
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
post 'stripe/events/', JSON.pretty_generate(@content)
|
40
|
+
|
41
|
+
describe 'when the invoked.payment_failed webhook is called' do
|
42
|
+
before { self.type = 'invoked.payment_failed' }
|
43
|
+
|
44
|
+
it 'the invoice.payment_succeeded callback is not invoked' do
|
45
|
+
subject
|
46
|
+
@event.must_be_nil
|
47
|
+
end
|
67
48
|
end
|
49
|
+
|
68
50
|
describe 'if it raises an exception' do
|
69
|
-
before
|
70
|
-
|
71
|
-
end
|
51
|
+
before { run_callback_with(callback) { fail } }
|
52
|
+
|
72
53
|
it 'causes the whole webhook to fail' do
|
73
|
-
|
54
|
+
->{ subject }.must_raise RuntimeError
|
74
55
|
end
|
75
56
|
end
|
76
57
|
end
|
77
58
|
|
78
59
|
describe 'defined without a bang and raising an exception' do
|
79
|
-
|
80
|
-
|
81
|
-
after_invoice_payment_succeeded do |evt|
|
82
|
-
fail 'boom!'
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
60
|
+
let(:callback) { :after_invoice_payment_succeeded }
|
61
|
+
before { run_callback_with(callback) { fail } }
|
86
62
|
|
87
63
|
it 'does not cause the webhook to fail' do
|
88
|
-
|
64
|
+
subject
|
89
65
|
last_response.status.must_be :>=, 200
|
90
66
|
last_response.status.must_be :<, 300
|
91
67
|
end
|
92
68
|
end
|
93
69
|
|
94
|
-
describe '
|
95
|
-
events
|
96
|
-
before
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
70
|
+
describe 'the after_stripe_event callback to catch any event' do
|
71
|
+
let(:events) { [] }
|
72
|
+
before { run_callback_with(:after_stripe_event) { |_, evt| events << evt } }
|
73
|
+
|
74
|
+
describe 'when it gets invoked for a standard event' do
|
75
|
+
before { self.type = 'invoice.payment_failed' }
|
76
|
+
|
77
|
+
it 'it will be run' do
|
78
|
+
subject
|
79
|
+
events.first.type.must_equal 'invoice.payment_failed'
|
102
80
|
end
|
103
81
|
end
|
104
|
-
it 'gets invoked for any standard event' do
|
105
|
-
self.type = 'invoice.payment_failed'
|
106
|
-
post 'stripe/events/', JSON.pretty_generate(@content)
|
107
|
-
events.first.type.must_equal 'invoice.payment_failed'
|
108
|
-
end
|
109
82
|
|
110
|
-
it
|
111
|
-
self.type = 'foo.bar.baz'
|
112
|
-
|
113
|
-
|
83
|
+
describe 'when it gets invoked for an arbitrary event' do
|
84
|
+
before { self.type = 'foo.bar.baz' }
|
85
|
+
|
86
|
+
it 'it will be run' do
|
87
|
+
subject
|
88
|
+
events.first.type.must_equal 'foo.bar.baz'
|
89
|
+
end
|
114
90
|
end
|
115
91
|
end
|
116
92
|
|
@@ -121,60 +97,87 @@ describe Stripe::Callbacks do
|
|
121
97
|
self.type = 'invoice.updated'
|
122
98
|
@stubbed_event.data.previous_attributes = {}
|
123
99
|
end
|
100
|
+
|
124
101
|
describe 'specified as an single symbol' do
|
125
102
|
before do
|
126
|
-
|
103
|
+
observer.class_eval do
|
127
104
|
after_invoice_updated! :only => :closed do |invoice, evt|
|
128
105
|
events << evt
|
129
106
|
end
|
130
107
|
end
|
131
108
|
end
|
132
|
-
|
133
|
-
|
134
|
-
events
|
109
|
+
|
110
|
+
describe 'when a prior attribute was not specified' do
|
111
|
+
it 'does not fire events' do
|
112
|
+
subject
|
113
|
+
events.length.must_equal 0
|
114
|
+
end
|
135
115
|
end
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
events
|
116
|
+
|
117
|
+
describe 'when a prior attribute was specified' do
|
118
|
+
before { @stubbed_event.data.previous_attributes['closed'] = true }
|
119
|
+
it 'fires events' do
|
120
|
+
subject
|
121
|
+
events.length.must_equal 1
|
122
|
+
end
|
140
123
|
end
|
141
124
|
end
|
125
|
+
|
142
126
|
describe 'specified as an array' do
|
143
127
|
before do
|
144
|
-
|
128
|
+
observer.class_eval do
|
145
129
|
after_invoice_updated! :only => [:currency, :subtotal] do |invoice, evt|
|
146
130
|
events << evt
|
147
131
|
end
|
148
132
|
end
|
149
133
|
end
|
150
|
-
|
151
|
-
|
152
|
-
events
|
134
|
+
|
135
|
+
describe 'when a prior attribute was not specified' do
|
136
|
+
it 'does not fire events' do
|
137
|
+
subject
|
138
|
+
events.length.must_equal 0
|
139
|
+
end
|
153
140
|
end
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
events
|
141
|
+
|
142
|
+
describe 'when prior attributes were specified' do
|
143
|
+
before { @stubbed_event.data.previous_attributes['subtotal'] = 699 }
|
144
|
+
it 'fire events' do
|
145
|
+
subject
|
146
|
+
events.length.must_equal 1
|
147
|
+
end
|
158
148
|
end
|
159
149
|
end
|
150
|
+
|
160
151
|
describe 'specified as a lambda' do
|
161
152
|
before do
|
162
|
-
|
153
|
+
observer.class_eval do
|
163
154
|
after_invoice_updated :only => proc {|target, evt| evt.data.previous_attributes.to_hash.has_key? :closed} do |i,e|
|
164
155
|
events << e
|
165
156
|
end
|
166
157
|
end
|
167
158
|
end
|
168
|
-
|
169
|
-
|
170
|
-
events
|
159
|
+
|
160
|
+
describe 'when the lambda is not true' do
|
161
|
+
it 'does not fire events' do
|
162
|
+
subject
|
163
|
+
events.length.must_equal 0
|
164
|
+
end
|
171
165
|
end
|
172
166
|
|
173
|
-
|
174
|
-
@stubbed_event.data.previous_attributes['closed'] = 'false'
|
175
|
-
|
176
|
-
|
167
|
+
describe 'when the lambda is not true' do
|
168
|
+
before { @stubbed_event.data.previous_attributes['closed'] = 'false' }
|
169
|
+
it 'fires events' do
|
170
|
+
subject
|
171
|
+
events.length.must_equal 1
|
172
|
+
end
|
177
173
|
end
|
178
174
|
end
|
179
175
|
end
|
176
|
+
|
177
|
+
describe 'when there are eager loaded callbacks in the configuration (config/environment/test.rb)' do
|
178
|
+
it 'should be eager loaded' do
|
179
|
+
Dummy.const_defined?(:ModelWithCallbacks).must_equal true
|
180
|
+
Dummy.const_defined?(:ModuleWithCallbacks).must_equal true
|
181
|
+
end
|
182
|
+
end
|
180
183
|
end
|
data/test/dummy/config/routes.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
class DummyStripesControllerSpec < ApplicationSystemTestCase
|
2
|
+
setup do
|
3
|
+
Dummy::Application.configure do
|
4
|
+
config.stripe.publishable_key = 'pk_test_XXXYYYZZZ'
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
test "loading the default javascript helper" do
|
9
|
+
visit new_stripe_url
|
10
|
+
assert_text 'This page tests the loading and initialization of Stripe JS'
|
11
|
+
end
|
12
|
+
|
13
|
+
test "loading the v2 version of the javascript helper" do
|
14
|
+
visit new_stripe_url(version: 'v2')
|
15
|
+
assert_text 'This page tests the loading and initialization of Stripe JS'
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Stripe::PingsController do
|
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 ping interface' do
|
14
|
+
subject { get '/stripe/ping' }
|
15
|
+
|
16
|
+
it { subject.must_be :ok? }
|
17
|
+
end
|
18
|
+
end
|
data/test/spec_helper.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path("../null_system_test_case", __FILE__)
|
2
|
+
require "capybara/poltergeist"
|
3
|
+
require 'phantomjs/poltergeist'
|
4
|
+
|
5
|
+
# For Rails 4 compat
|
6
|
+
SystemTestCaseKlass = defined?(ActionDispatch::SystemTestCase) ? ActionDispatch::SystemTestCase : NullSystemTestCase
|
7
|
+
|
8
|
+
class ApplicationSystemTestCase < SystemTestCaseKlass
|
9
|
+
# Note: errors only show up with BOTH js_errors: true, inspector: true
|
10
|
+
driven_by :poltergeist, options: { js_errors: true, inspector: true, phantomjs: Phantomjs.path }
|
11
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module CallbackHelpers
|
2
|
+
def type=(type)
|
3
|
+
content['type'] = type
|
4
|
+
@stubbed_event = Stripe::Event.construct_from(content)
|
5
|
+
Stripe::Event.stubs(:retrieve).returns(@stubbed_event)
|
6
|
+
end
|
7
|
+
|
8
|
+
def run_callback_with(callback)
|
9
|
+
observer.class_eval do
|
10
|
+
send(callback) do |evt, target|
|
11
|
+
yield evt, target
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
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.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charles Lowell
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-08-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -100,11 +100,13 @@ files:
|
|
100
100
|
- test/dummy/app/assets/javascripts/application.js
|
101
101
|
- test/dummy/app/assets/stylesheets/application.css
|
102
102
|
- test/dummy/app/controllers/application_controller.rb
|
103
|
+
- test/dummy/app/controllers/stripes_controller.rb
|
103
104
|
- test/dummy/app/helpers/application_helper.rb
|
104
105
|
- test/dummy/app/mailers/.gitkeep
|
105
106
|
- test/dummy/app/models/.gitkeep
|
106
107
|
- test/dummy/app/models/dummy/model_with_callbacks.rb
|
107
108
|
- test/dummy/app/views/layouts/application.html.erb
|
109
|
+
- test/dummy/app/views/stripes/new.html.erb
|
108
110
|
- test/dummy/config.ru
|
109
111
|
- test/dummy/config/application.rb
|
110
112
|
- test/dummy/config/boot.rb
|
@@ -130,12 +132,17 @@ files:
|
|
130
132
|
- test/dummy/public/500.html
|
131
133
|
- test/dummy/public/favicon.ico
|
132
134
|
- test/dummy/script/rails
|
135
|
+
- test/dummy_stripes_controller_spec.rb
|
133
136
|
- test/event.json
|
134
137
|
- test/invoice.json
|
135
138
|
- test/javascript_helper_spec.rb
|
139
|
+
- test/pings_controller_spec.rb
|
136
140
|
- test/plan_builder_spec.rb
|
137
141
|
- test/spec_helper.rb
|
138
142
|
- test/stripe_rails_spec.rb
|
143
|
+
- test/support/application_system_test_case.rb
|
144
|
+
- test/support/callback_helpers.rb
|
145
|
+
- test/support/null_system_test_case.rb
|
139
146
|
homepage: https://github.com/Everapps/stripe-rails
|
140
147
|
licenses:
|
141
148
|
- MIT
|
@@ -169,11 +176,13 @@ test_files:
|
|
169
176
|
- test/dummy/app/assets/javascripts/application.js
|
170
177
|
- test/dummy/app/assets/stylesheets/application.css
|
171
178
|
- test/dummy/app/controllers/application_controller.rb
|
179
|
+
- test/dummy/app/controllers/stripes_controller.rb
|
172
180
|
- test/dummy/app/helpers/application_helper.rb
|
173
181
|
- test/dummy/app/mailers/.gitkeep
|
174
182
|
- test/dummy/app/models/.gitkeep
|
175
183
|
- test/dummy/app/models/dummy/model_with_callbacks.rb
|
176
184
|
- test/dummy/app/views/layouts/application.html.erb
|
185
|
+
- test/dummy/app/views/stripes/new.html.erb
|
177
186
|
- test/dummy/config.ru
|
178
187
|
- test/dummy/config/application.rb
|
179
188
|
- test/dummy/config/boot.rb
|
@@ -199,9 +208,14 @@ test_files:
|
|
199
208
|
- test/dummy/public/500.html
|
200
209
|
- test/dummy/public/favicon.ico
|
201
210
|
- test/dummy/script/rails
|
211
|
+
- test/dummy_stripes_controller_spec.rb
|
202
212
|
- test/event.json
|
203
213
|
- test/invoice.json
|
204
214
|
- test/javascript_helper_spec.rb
|
215
|
+
- test/pings_controller_spec.rb
|
205
216
|
- test/plan_builder_spec.rb
|
206
217
|
- test/spec_helper.rb
|
207
218
|
- test/stripe_rails_spec.rb
|
219
|
+
- test/support/application_system_test_case.rb
|
220
|
+
- test/support/callback_helpers.rb
|
221
|
+
- test/support/null_system_test_case.rb
|