stripe-rails 0.3.0 → 0.3.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 +3 -0
- data/README.md +13 -0
- data/lib/generators/templates/plans.rb +3 -0
- data/lib/stripe/engine.rb +14 -1
- data/lib/stripe/plans.rb +1 -2
- data/lib/stripe/rails/version.rb +1 -1
- data/test/callbacks_spec.rb +5 -0
- data/test/dummy/app/models/dummy/model_with_callbacks.rb +2 -0
- data/test/dummy/config/environments/test.rb +1 -0
- data/test/dummy/config/stripe/plans.rb +8 -1
- data/test/dummy/lib/dummy/module_with_callbacks.rb +2 -0
- data/test/plan_builder_spec.rb +14 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2093ec1a3bd46eb90811710db16bdfe309312e1c
|
4
|
+
data.tar.gz: 4b3f402cf1327a22688bd5bf6b6cd051be1d23f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98d339c9a0a0f858af220470bc722c39fc23707dd9a786a9fbc0788cfbb0b0ff71258d6c6b5b31f4b807493da274d63485d15e12083c6ec1357eb3693bb94f3e
|
7
|
+
data.tar.gz: ee4d0b67c1932dbdc05f287f0502d5ff7a49e7bc3497187c9c8f18642703316a6407ad51533cbcf6d49868f834790d7de3166752b8db44cb1eb37916a635ad23
|
data/Changelog.md
CHANGED
data/README.md
CHANGED
@@ -232,6 +232,16 @@ class InvoiceMailer < ActionMailer::Base
|
|
232
232
|
end
|
233
233
|
```
|
234
234
|
|
235
|
+
**Note:** `Stripe::Callbacks` won't get included until the including class has been loaded. This is usually not an issue in the production environment as eager loading is enabled by default (`config.eager_load = true`). You may run into an issue in your development environment where eager loading is disabled by default.
|
236
|
+
|
237
|
+
If you don't wish to enable eager loading in development, you can configure the classes to be eager loaded like so
|
238
|
+
|
239
|
+
```ruby
|
240
|
+
# in your application's config/environments/development.rb
|
241
|
+
config.stripe.eager_load = 'account', 'module/some_class', 'etc'
|
242
|
+
```
|
243
|
+
This will ensure that callbacks will get loaded in those configured classes if eager loading is disabled.
|
244
|
+
|
235
245
|
The naming convention for the callback events is after__{callback_name}! where `callback_name`
|
236
246
|
is name of the stripe event with all `.` characters substituted with underscores. So, for
|
237
247
|
example, the stripe event `customer.discount.created` can be hooked by `after_customer_discount_created!`
|
@@ -243,6 +253,8 @@ Each web hook is passed an instance of the stripe object to which the event corr
|
|
243
253
|
By default, the event is re-fetched securely from stripe.com to prevent damage to your system by
|
244
254
|
a malicious system spoofing real stripe events.
|
245
255
|
|
256
|
+
|
257
|
+
|
246
258
|
### Critical and non-critical hooks
|
247
259
|
|
248
260
|
So far, the examples have all used critical hooks, but in fact, each callback method comes in two flavors: "critical",
|
@@ -325,6 +337,7 @@ end
|
|
325
337
|
|
326
338
|
See the [complete listing of all stripe events][5], and the [webhook tutorial][6] for more great information on this subject.
|
327
339
|
|
340
|
+
|
328
341
|
## Thanks
|
329
342
|
|
330
343
|
<a href="http://thefrontside.net"></a>
|
data/lib/stripe/engine.rb
CHANGED
@@ -8,7 +8,7 @@ module Stripe
|
|
8
8
|
attr_accessor :testing
|
9
9
|
end
|
10
10
|
|
11
|
-
stripe_config = config.stripe = Struct.new(:api_base, :secret_key, :verify_ssl_certs, :publishable_key, :endpoint, :debug_js, :auto_mount).new
|
11
|
+
stripe_config = config.stripe = Struct.new(:api_base, :secret_key, :verify_ssl_certs, :publishable_key, :endpoint, :debug_js, :auto_mount, :eager_load).new
|
12
12
|
|
13
13
|
def stripe_config.api_key=(key)
|
14
14
|
warn "[DEPRECATION] to align with stripe nomenclature, stripe.api_key has been renamed to config.stripe.secret_key"
|
@@ -20,6 +20,7 @@ module Stripe
|
|
20
20
|
stripe.secret_key ||= ENV['STRIPE_SECRET_KEY']
|
21
21
|
stripe.endpoint ||= '/stripe'
|
22
22
|
stripe.auto_mount = true if stripe.auto_mount.nil?
|
23
|
+
stripe.eager_load ||= []
|
23
24
|
if stripe.debug_js.nil?
|
24
25
|
stripe.debug_js = ::Rails.env.development?
|
25
26
|
end
|
@@ -40,6 +41,18 @@ environment file directly.
|
|
40
41
|
MSG
|
41
42
|
end
|
42
43
|
|
44
|
+
initializer 'stripe.callbacks.eager_load' do |app|
|
45
|
+
app.config.after_initialize do
|
46
|
+
app.config.stripe.eager_load.each do |constant|
|
47
|
+
begin
|
48
|
+
constant.to_s.camelize.constantize
|
49
|
+
rescue NameError
|
50
|
+
require constant
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
43
56
|
initializer 'stripe.javascript_helper' do
|
44
57
|
ActiveSupport.on_load :action_controller do
|
45
58
|
helper Stripe::JavascriptHelper
|
data/lib/stripe/plans.rb
CHANGED
@@ -3,8 +3,7 @@ module Stripe
|
|
3
3
|
include ConfigurationBuilder
|
4
4
|
|
5
5
|
configuration_for :plan do
|
6
|
-
|
7
|
-
attr_accessor :name, :amount, :interval, :interval_count, :trial_period_days
|
6
|
+
attr_accessor :name, :amount, :interval, :interval_count, :trial_period_days, :currency
|
8
7
|
|
9
8
|
validates_presence_of :id, :name, :amount
|
10
9
|
validates_inclusion_of :interval, :in => %w(week month year), :message => "'%{value}' is not one of 'week', 'month' or 'year'"
|
data/lib/stripe/rails/version.rb
CHANGED
data/test/callbacks_spec.rb
CHANGED
@@ -31,6 +31,11 @@ describe Stripe::Callbacks do
|
|
31
31
|
::Stripe::Callbacks.clear_callbacks!
|
32
32
|
end
|
33
33
|
|
34
|
+
it 'has eager loaded the callbacks listed in the configuration' do
|
35
|
+
assert Dummy.const_defined?(:ModelWithCallbacks), 'should have eager loaded'
|
36
|
+
assert Dummy.const_defined?(:ModuleWithCallbacks), 'should have eager loaded'
|
37
|
+
end
|
38
|
+
|
34
39
|
it 'has a ping interface just to make sure that everything is working just fine' do
|
35
40
|
get '/stripe/ping'
|
36
41
|
assert last_response.ok?
|
@@ -2,6 +2,7 @@ Dummy::Application.configure do
|
|
2
2
|
|
3
3
|
config.stripe.api_base = 'http://localhost:5000'
|
4
4
|
config.stripe.verify_ssl_certs = false
|
5
|
+
config.stripe.eager_load = 'dummy/model_with_callbacks', 'dummy/module_with_callbacks'
|
5
6
|
|
6
7
|
# Settings specified here will take precedence over those in config/application.rb
|
7
8
|
|
@@ -2,4 +2,11 @@ Stripe.plan :gold do |plan|
|
|
2
2
|
plan.name = 'Solid Gold'
|
3
3
|
plan.amount = 699
|
4
4
|
plan.interval = 'month'
|
5
|
-
end
|
5
|
+
end
|
6
|
+
|
7
|
+
Stripe.plan :alternative_currency do |plan|
|
8
|
+
plan.name = 'Alternative Currency'
|
9
|
+
plan.amount = 699
|
10
|
+
plan.interval = 'month'
|
11
|
+
plan.currency = 'cad'
|
12
|
+
end
|
data/test/plan_builder_spec.rb
CHANGED
@@ -74,6 +74,7 @@ describe 'building plans' do
|
|
74
74
|
before do
|
75
75
|
Stripe::Plan.stubs(:retrieve).raises(Stripe::InvalidRequestError.new("not found", "id"))
|
76
76
|
end
|
77
|
+
|
77
78
|
it 'creates the plan online' do
|
78
79
|
Stripe::Plan.expects(:create).with(
|
79
80
|
:id => :gold,
|
@@ -87,6 +88,19 @@ describe 'building plans' do
|
|
87
88
|
Stripe::Plans::GOLD.put!
|
88
89
|
end
|
89
90
|
|
91
|
+
it 'creates a plan with an alternative currency' do
|
92
|
+
Stripe::Plan.expects(:create).with(
|
93
|
+
:id => :alternative_currency,
|
94
|
+
:currency => 'cad',
|
95
|
+
:name => 'Alternative Currency',
|
96
|
+
:amount => 699,
|
97
|
+
:interval => 'month',
|
98
|
+
:interval_count => 1,
|
99
|
+
:trial_period_days => 0
|
100
|
+
)
|
101
|
+
Stripe::Plans::ALTERNATIVE_CURRENCY.put!
|
102
|
+
end
|
103
|
+
|
90
104
|
end
|
91
105
|
describe 'when it is already present on stripe.com' do
|
92
106
|
before do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stripe-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rubygeek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- test/dummy/app/helpers/application_helper.rb
|
87
87
|
- test/dummy/app/mailers/.gitkeep
|
88
88
|
- test/dummy/app/models/.gitkeep
|
89
|
+
- test/dummy/app/models/dummy/model_with_callbacks.rb
|
89
90
|
- test/dummy/app/views/layouts/application.html.erb
|
90
91
|
- test/dummy/config.ru
|
91
92
|
- test/dummy/config/application.rb
|
@@ -105,6 +106,7 @@ files:
|
|
105
106
|
- test/dummy/config/routes.rb
|
106
107
|
- test/dummy/config/stripe/plans.rb
|
107
108
|
- test/dummy/lib/assets/.gitkeep
|
109
|
+
- test/dummy/lib/dummy/module_with_callbacks.rb
|
108
110
|
- test/dummy/log/.gitkeep
|
109
111
|
- test/dummy/public/404.html
|
110
112
|
- test/dummy/public/422.html
|
@@ -151,6 +153,7 @@ test_files:
|
|
151
153
|
- test/dummy/app/helpers/application_helper.rb
|
152
154
|
- test/dummy/app/mailers/.gitkeep
|
153
155
|
- test/dummy/app/models/.gitkeep
|
156
|
+
- test/dummy/app/models/dummy/model_with_callbacks.rb
|
154
157
|
- test/dummy/app/views/layouts/application.html.erb
|
155
158
|
- test/dummy/config.ru
|
156
159
|
- test/dummy/config/application.rb
|
@@ -170,6 +173,7 @@ test_files:
|
|
170
173
|
- test/dummy/config/routes.rb
|
171
174
|
- test/dummy/config/stripe/plans.rb
|
172
175
|
- test/dummy/lib/assets/.gitkeep
|
176
|
+
- test/dummy/lib/dummy/module_with_callbacks.rb
|
173
177
|
- test/dummy/log/.gitkeep
|
174
178
|
- test/dummy/public/404.html
|
175
179
|
- test/dummy/public/422.html
|