koudoku 0.0.11 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +56 -17
  3. data/Rakefile +1 -32
  4. data/app/concerns/koudoku/plan.rb +0 -8
  5. data/app/concerns/koudoku/subscription.rb +36 -20
  6. data/app/controllers/koudoku/subscriptions_controller.rb +45 -11
  7. data/app/views/koudoku/subscriptions/_card.html.erb +1 -1
  8. data/app/views/koudoku/subscriptions/show.html.erb +6 -6
  9. data/config/initializers/stripe_event.rb +27 -0
  10. data/config/routes.rb +3 -1
  11. data/lib/generators/koudoku/install_generator.rb +27 -31
  12. data/lib/generators/koudoku/templates/app/models/coupon.rb +5 -0
  13. data/lib/generators/koudoku/templates/app/models/plan.rb +6 -0
  14. data/lib/generators/koudoku/templates/app/models/subscription.rb +8 -0
  15. data/lib/generators/koudoku/templates/config/initializers/koudoku.rb +13 -0
  16. data/lib/generators/koudoku/views_generator.rb +5 -2
  17. data/lib/koudoku/version.rb +1 -1
  18. data/lib/koudoku.rb +28 -10
  19. data/spec/concerns/koudoku/plan_spec.rb +13 -13
  20. data/spec/dummy/app/models/plan.rb +0 -1
  21. data/spec/dummy/config/application.rb +0 -6
  22. data/spec/dummy/config/environments/development.rb +2 -7
  23. data/spec/dummy/config/environments/production.rb +2 -0
  24. data/spec/dummy/config/environments/test.rb +2 -3
  25. data/spec/dummy/config/initializers/koudoku.rb +1 -1
  26. data/spec/dummy/db/development.sqlite3 +0 -0
  27. data/spec/dummy/db/test.sqlite3 +0 -0
  28. data/spec/dummy/log/development.log +48 -0
  29. data/spec/dummy/log/test.log +203 -0
  30. metadata +60 -48
  31. data/app/controllers/koudoku/webhooks_controller.rb +0 -39
  32. data/spec/controllers/koudoku/webhooks_controller_spec.rb +0 -76
  33. data/spec/dummy/spec/factories/coupons.rb +0 -8
  34. data/spec/dummy/spec/factories/plans.rb +0 -12
  35. data/spec/dummy/spec/factories/subscriptions.rb +0 -14
  36. data/spec/dummy/spec/models/coupon_spec.rb +0 -5
  37. data/spec/dummy/spec/models/plan_spec.rb +0 -5
  38. data/spec/dummy/spec/models/subscription_spec.rb +0 -5
metadata CHANGED
@@ -1,139 +1,153 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koudoku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Culver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-30 00:00:00.000000000 Z
11
+ date: 2015-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: stripe
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: stripe_event
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bluecloth
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - '>='
59
+ - - ">="
46
60
  - !ruby/object:Gem::Version
47
61
  version: '0'
48
62
  type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - '>='
66
+ - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: jquery-rails
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - '>='
73
+ - - ">="
60
74
  - !ruby/object:Gem::Version
61
75
  version: '0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - '>='
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: sqlite3
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - '>='
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
89
  version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - '>='
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rspec-rails
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - '>='
101
+ - - ">="
88
102
  - !ruby/object:Gem::Version
89
103
  version: '0'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - '>='
108
+ - - ">="
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: capybara
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - '>='
115
+ - - ">="
102
116
  - !ruby/object:Gem::Version
103
117
  version: '0'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - '>='
122
+ - - ">="
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: factory_girl_rails
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
- - - '>='
129
+ - - ">="
116
130
  - !ruby/object:Gem::Version
117
131
  version: '0'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
- - - '>='
136
+ - - ">="
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: pry
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
- - - '>='
143
+ - - ">="
130
144
  - !ruby/object:Gem::Version
131
145
  version: '0'
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
- - - '>='
150
+ - - ">="
137
151
  - !ruby/object:Gem::Version
138
152
  version: '0'
139
153
  description: Robust subscription support for Rails with Stripe. Provides package levels,
@@ -144,6 +158,9 @@ executables: []
144
158
  extensions: []
145
159
  extra_rdoc_files: []
146
160
  files:
161
+ - MIT-LICENSE
162
+ - README.md
163
+ - Rakefile
147
164
  - app/assets/javascripts/koudoku/application.js
148
165
  - app/assets/stylesheets/koudoku/application.css
149
166
  - app/assets/stylesheets/koudoku/pricing-table.scss
@@ -151,7 +168,6 @@ files:
151
168
  - app/concerns/koudoku/subscription.rb
152
169
  - app/controllers/koudoku/application_controller.rb
153
170
  - app/controllers/koudoku/subscriptions_controller.rb
154
- - app/controllers/koudoku/webhooks_controller.rb
155
171
  - app/helpers/koudoku/application_helper.rb
156
172
  - app/views/koudoku/subscriptions/_card.html.erb
157
173
  - app/views/koudoku/subscriptions/_pricing_table.html.erb
@@ -164,20 +180,23 @@ files:
164
180
  - app/views/koudoku/subscriptions/unauthorized.html.erb
165
181
  - app/views/layouts/koudoku/application.html.erb
166
182
  - config/environment.rb
183
+ - config/initializers/stripe_event.rb
167
184
  - config/routes.rb
168
185
  - lib/generators/koudoku/install_generator.rb
186
+ - lib/generators/koudoku/templates/app/models/coupon.rb
187
+ - lib/generators/koudoku/templates/app/models/plan.rb
188
+ - lib/generators/koudoku/templates/app/models/subscription.rb
189
+ - lib/generators/koudoku/templates/config/initializers/koudoku.rb
169
190
  - lib/generators/koudoku/views_generator.rb
191
+ - lib/koudoku.rb
170
192
  - lib/koudoku/engine.rb
171
193
  - lib/koudoku/version.rb
172
- - lib/koudoku.rb
173
194
  - lib/tasks/koudoku_tasks.rake
174
- - MIT-LICENSE
175
- - Rakefile
176
- - README.md
177
195
  - spec/concerns/koudoku/plan_spec.rb
178
196
  - spec/concerns/koudoku/subscription_spec.rb
179
197
  - spec/controllers/koudoku/subscriptions_controller.rb
180
- - spec/controllers/koudoku/webhooks_controller_spec.rb
198
+ - spec/dummy/README.rdoc
199
+ - spec/dummy/Rakefile
181
200
  - spec/dummy/app/assets/javascripts/application.js
182
201
  - spec/dummy/app/assets/stylesheets/application.css
183
202
  - spec/dummy/app/controllers/application_controller.rb
@@ -188,6 +207,7 @@ files:
188
207
  - spec/dummy/app/models/subscription.rb
189
208
  - spec/dummy/app/views/koudoku/subscriptions/_social_proof.html.erb
190
209
  - spec/dummy/app/views/layouts/application.html.erb
210
+ - spec/dummy/config.ru
191
211
  - spec/dummy/config/application.rb
192
212
  - spec/dummy/config/boot.rb
193
213
  - spec/dummy/config/database.yml
@@ -206,35 +226,30 @@ files:
206
226
  - spec/dummy/config/locales/devise.en.yml
207
227
  - spec/dummy/config/locales/en.yml
208
228
  - spec/dummy/config/routes.rb
209
- - spec/dummy/config.ru
229
+ - spec/dummy/db/development.sqlite3
210
230
  - spec/dummy/db/migrate/20130318201927_create_customers.rb
211
231
  - spec/dummy/db/migrate/20130318204455_create_subscriptions.rb
212
232
  - spec/dummy/db/migrate/20130318204458_create_plans.rb
213
233
  - spec/dummy/db/migrate/20130318204502_create_coupons.rb
214
234
  - spec/dummy/db/migrate/20130520163946_add_interval_to_plan.rb
215
235
  - spec/dummy/db/schema.rb
236
+ - spec/dummy/db/test.sqlite3
237
+ - spec/dummy/log/development.log
238
+ - spec/dummy/log/test.log
216
239
  - spec/dummy/public/404.html
217
240
  - spec/dummy/public/422.html
218
241
  - spec/dummy/public/500.html
219
242
  - spec/dummy/public/favicon.ico
220
- - spec/dummy/Rakefile
221
- - spec/dummy/README.rdoc
222
243
  - spec/dummy/script/rails
223
- - spec/dummy/spec/factories/coupons.rb
224
- - spec/dummy/spec/factories/plans.rb
225
- - spec/dummy/spec/factories/subscriptions.rb
226
- - spec/dummy/spec/models/coupon_spec.rb
227
- - spec/dummy/spec/models/plan_spec.rb
228
- - spec/dummy/spec/models/subscription_spec.rb
229
244
  - spec/dummy/test/fixtures/customers.yml
230
245
  - spec/dummy/test/unit/customer_test.rb
231
246
  - spec/helpers/koudoku/application_helper_spec.rb
232
247
  - spec/spec_helper.rb
233
248
  homepage: http://github.com/andrewculver/koudoku
234
- licenses: []
249
+ licenses:
250
+ - MIT
235
251
  metadata: {}
236
- post_install_message: |2+
237
-
252
+ post_install_message: |+
238
253
  Koudoku is still in early development, so if this installation is an upgrade
239
254
  from an earlier version, be sure to check the CHANGELOG for any instructions
240
255
  you may need to follow to accommodate breaking changes:
@@ -246,17 +261,17 @@ require_paths:
246
261
  - lib
247
262
  required_ruby_version: !ruby/object:Gem::Requirement
248
263
  requirements:
249
- - - '>='
264
+ - - ">="
250
265
  - !ruby/object:Gem::Version
251
266
  version: '0'
252
267
  required_rubygems_version: !ruby/object:Gem::Requirement
253
268
  requirements:
254
- - - '>='
269
+ - - ">="
255
270
  - !ruby/object:Gem::Version
256
271
  version: '0'
257
272
  requirements: []
258
273
  rubyforge_project:
259
- rubygems_version: 2.0.6
274
+ rubygems_version: 2.2.2
260
275
  signing_key:
261
276
  specification_version: 4
262
277
  summary: Robust subscription support for Rails with Stripe.
@@ -264,7 +279,6 @@ test_files:
264
279
  - spec/concerns/koudoku/plan_spec.rb
265
280
  - spec/concerns/koudoku/subscription_spec.rb
266
281
  - spec/controllers/koudoku/subscriptions_controller.rb
267
- - spec/controllers/koudoku/webhooks_controller_spec.rb
268
282
  - spec/dummy/app/assets/javascripts/application.js
269
283
  - spec/dummy/app/assets/stylesheets/application.css
270
284
  - spec/dummy/app/controllers/application_controller.rb
@@ -294,12 +308,16 @@ test_files:
294
308
  - spec/dummy/config/locales/en.yml
295
309
  - spec/dummy/config/routes.rb
296
310
  - spec/dummy/config.ru
311
+ - spec/dummy/db/development.sqlite3
297
312
  - spec/dummy/db/migrate/20130318201927_create_customers.rb
298
313
  - spec/dummy/db/migrate/20130318204455_create_subscriptions.rb
299
314
  - spec/dummy/db/migrate/20130318204458_create_plans.rb
300
315
  - spec/dummy/db/migrate/20130318204502_create_coupons.rb
301
316
  - spec/dummy/db/migrate/20130520163946_add_interval_to_plan.rb
302
317
  - spec/dummy/db/schema.rb
318
+ - spec/dummy/db/test.sqlite3
319
+ - spec/dummy/log/development.log
320
+ - spec/dummy/log/test.log
303
321
  - spec/dummy/public/404.html
304
322
  - spec/dummy/public/422.html
305
323
  - spec/dummy/public/500.html
@@ -307,12 +325,6 @@ test_files:
307
325
  - spec/dummy/Rakefile
308
326
  - spec/dummy/README.rdoc
309
327
  - spec/dummy/script/rails
310
- - spec/dummy/spec/factories/coupons.rb
311
- - spec/dummy/spec/factories/plans.rb
312
- - spec/dummy/spec/factories/subscriptions.rb
313
- - spec/dummy/spec/models/coupon_spec.rb
314
- - spec/dummy/spec/models/plan_spec.rb
315
- - spec/dummy/spec/models/subscription_spec.rb
316
328
  - spec/dummy/test/fixtures/customers.yml
317
329
  - spec/dummy/test/unit/customer_test.rb
318
330
  - spec/helpers/koudoku/application_helper_spec.rb
@@ -1,39 +0,0 @@
1
- module Koudoku
2
- class WebhooksController < ApplicationController
3
-
4
- def create
5
-
6
- raise "API key not configured. For security reasons you must configure this in 'config/koudoku.rb'." unless Koudoku.webhooks_api_key.present?
7
- raise "Invalid API key. Be sure the webhooks URL Stripe is configured with includes ?api_key= and the correct key." unless params[:api_key] == Koudoku.webhooks_api_key
8
-
9
- data_json = JSON.parse request.body.read
10
-
11
- if data_json['type'] == "invoice.payment_succeeded"
12
-
13
- stripe_id = data_json['data']['object']['customer']
14
- amount = data_json['data']['object']['total'].to_f / 100.0
15
- subscription = ::Subscription.find_by_stripe_id(stripe_id)
16
- subscription.payment_succeeded(amount)
17
-
18
- elsif data_json['type'] == "charge.failed"
19
-
20
- stripe_id = data_json['data']['object']['customer']
21
-
22
- subscription = ::Subscription.find_by_stripe_id(stripe_id)
23
- subscription.charge_failed
24
-
25
- elsif data_json['type'] == "charge.dispute.created"
26
-
27
- stripe_id = data_json['data']['object']['customer']
28
-
29
- subscription = ::Subscription.find_by_stripe_id(stripe_id)
30
- subscription.charge_disputed
31
-
32
- end
33
-
34
- render nothing: true
35
-
36
- end
37
-
38
- end
39
- end
@@ -1,76 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Koudoku::WebhooksController do
4
-
5
- before do
6
-
7
- # disable any interaction with stripe for these tests.
8
- Subscription.any_instance.stub(:processing!).and_return(true)
9
-
10
- end
11
-
12
- describe 'when a valid subscription exists' do
13
- before do
14
- # here is the corresponding customer in our database.
15
- @customer = Customer.create(email: 'andrew.culver@gmail.com')
16
- @subscription = Subscription.create(customer_id: @customer.id, stripe_id: 'customer-id')
17
- # make sure they get this exact instance.
18
- Subscription.stub('find_by_stripe_id').and_return(@subscription)
19
- end
20
- describe "invoice.payment_succeeded" do
21
- describe "POST create" do
22
- it 'calls payment_succeeded for the subscription' do
23
- @subscription.should_receive(:payment_succeeded).once
24
- raw_post :create, {use_route: 'koudoku', api_key: Koudoku.webhooks_api_key}, webhooks_json('invoice.payment_succeeded', total: '1234', customer: @subscription.stripe_id)
25
- end
26
- it 'returns 200' do
27
- raw_post :create, {use_route: 'koudoku', api_key: Koudoku.webhooks_api_key}, webhooks_json('invoice.payment_succeeded', total: '1234', customer: @subscription.stripe_id)
28
- response.code.should eq("200")
29
- end
30
- end
31
- end
32
- describe "charge.failed" do
33
- describe "POST create" do
34
- it 'calls charge_failed for the subscription' do
35
- @subscription.should_receive(:charge_failed).once
36
- raw_post :create, {use_route: 'koudoku', api_key: Koudoku.webhooks_api_key}, webhooks_json('charge.failed', customer: @subscription.stripe_id)
37
- end
38
- it 'returns 200' do
39
- raw_post :create, {use_route: 'koudoku', api_key: Koudoku.webhooks_api_key}, webhooks_json('charge.failed', customer: @subscription.stripe_id)
40
- response.code.should eq("200")
41
- end
42
- end
43
- end
44
- describe "charge.dispute.created" do
45
- describe "POST create" do
46
- it 'calls charge_disputed for the subscription' do
47
- @subscription.should_receive(:charge_disputed).once
48
- raw_post :create, {use_route: 'koudoku', api_key: Koudoku.webhooks_api_key}, webhooks_json('charge.dispute.created', customer: @subscription.stripe_id)
49
- end
50
- it 'returns 200' do
51
- raw_post :create, {use_route: 'koudoku', api_key: Koudoku.webhooks_api_key}, webhooks_json('charge.dispute.created', customer: @subscription.stripe_id)
52
- response.code.should eq("200")
53
- end
54
- end
55
- end
56
- end
57
- it 'returns an error if the subscription can not be found' do
58
- expect {
59
- raw_post :create, {use_route: 'koudoku', api_key: Koudoku.webhooks_api_key}, webhooks_json('invoice.payment_succeeded', total: '1234', customer: 'some-random-id')
60
- }.to raise_error
61
- end
62
- describe "everything else" do
63
- describe "POST create" do
64
- it "should raise an error for invalid api keys" do
65
- expect {
66
- raw_post :create, {use_route: 'koudoku', api_key: 'not-the-api-key'}, webhooks_json('resource.something_else', total: '1234')
67
- }.to raise_error
68
- end
69
- it "should not raise an error for valid api keys" do
70
- expect {
71
- raw_post :create, {use_route: 'koudoku', api_key: Koudoku.webhooks_api_key}, webhooks_json('resource.something_else', total: '1234')
72
- }.to_not raise_error
73
- end
74
- end
75
- end
76
- end
@@ -1,8 +0,0 @@
1
- # Read about factories at https://github.com/thoughtbot/factory_girl
2
-
3
- FactoryGirl.define do
4
- factory :coupon do
5
- code "MyString"
6
- free_trial_length "MyString"
7
- end
8
- end
@@ -1,12 +0,0 @@
1
- # Read about factories at https://github.com/thoughtbot/factory_girl
2
-
3
- FactoryGirl.define do
4
- factory :plan do
5
- name "MyString"
6
- stripe_id "MyString"
7
- price 1.5
8
- features "MyText"
9
- highlight false
10
- display_order 1
11
- end
12
- end
@@ -1,14 +0,0 @@
1
- # Read about factories at https://github.com/thoughtbot/factory_girl
2
-
3
- FactoryGirl.define do
4
- factory :subscription do
5
- stripe_id "MyString"
6
- plan_id 1
7
- last_four "MyString"
8
- coupon_id 1
9
- last_four "MyString"
10
- card_type "MyString"
11
- current_price 1.5
12
- customer_id 1
13
- end
14
- end
@@ -1,5 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Coupon do
4
- pending "add some examples to (or delete) #{__FILE__}"
5
- end
@@ -1,5 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Plan do
4
- pending "add some examples to (or delete) #{__FILE__}"
5
- end
@@ -1,5 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Subscription do
4
- pending "add some examples to (or delete) #{__FILE__}"
5
- end