koudoku 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -15,6 +15,12 @@ After running `bundle install`, you can run a Rails generator to do the rest. Be
15
15
  rails g koudoku:install user
16
16
  rake db:migrate
17
17
 
18
+ Add the following to `app/views/layouts/application.html.erb` before your `<head>` tag closes:
19
+
20
+ <%= yield :koudoku %>
21
+
22
+ (This allows us to inject a Stripe `<script>` tag in the correct place. If you don't, the payment form will not work.)
23
+
18
24
  After installing, you'll need to add some subscription plans. (You can see an explanation of each of the attributes in the table below.)
19
25
 
20
26
  Plan.create({
@@ -23,7 +29,6 @@ After installing, you'll need to add some subscription plans. (You can see an ex
23
29
  interval: 'month',
24
30
  stripe_id: '1',
25
31
  features: ['1 Project', '1 Page', '1 User', '1 Organization'].join("\n\n"),
26
- interval: 'month',
27
32
  display_order: 1
28
33
  })
29
34
 
@@ -3,8 +3,6 @@ module Koudoku::Subscription
3
3
 
4
4
  included do
5
5
 
6
- attr_accessible :plan_id, :stripe_id, :current_price, :credit_card_token, :card_type, :last_four
7
-
8
6
  # We don't store these one-time use tokens, but this is what Stripe provides
9
7
  # client-side after storing the credit card information.
10
8
  attr_accessor :credit_card_token
@@ -58,7 +56,6 @@ module Koudoku::Subscription
58
56
 
59
57
  # otherwise
60
58
  else
61
-
62
59
  # if a new plan has been selected
63
60
  if self.plan.present?
64
61
 
@@ -94,7 +91,7 @@ module Koudoku::Subscription
94
91
 
95
92
  # store the customer id.
96
93
  self.stripe_id = customer.id
97
- self.last_four = customer.active_card.last4
94
+ self.last_four = customer.cards.retrieve(customer.default_card).last4
98
95
 
99
96
  finalize_new_subscription!
100
97
  finalize_upgrade!
@@ -125,8 +122,7 @@ module Koudoku::Subscription
125
122
  customer.save
126
123
 
127
124
  # update the last four based on this new card.
128
- self.last_four = customer.active_card.last4
129
-
125
+ self.last_four = customer.cards.retrieve(customer.default_card).last4
130
126
  finalize_card_update!
131
127
 
132
128
  end
@@ -1,5 +1,6 @@
1
1
  module Koudoku
2
2
  class ApplicationController < ::ApplicationController
3
3
  layout 'application'
4
+ helper :application
4
5
  end
5
6
  end
@@ -83,7 +83,7 @@ module Koudoku
83
83
  end
84
84
 
85
85
  def create
86
- @subscription = ::Subscription.new(params[:subscription])
86
+ @subscription = ::Subscription.new(subscription_params)
87
87
  @subscription.user = @owner
88
88
  if @subscription.save
89
89
  flash[:notice] = "You've been successfully upgraded."
@@ -108,7 +108,7 @@ module Koudoku
108
108
  end
109
109
 
110
110
  def update
111
- if @subscription.update_attributes(params[:subscription])
111
+ if @subscription.update_attributes(subscription_params)
112
112
  flash[:notice] = "You've successfully updated your subscription."
113
113
  redirect_to owner_subscription_path(@owner, @subscription)
114
114
  else
@@ -117,5 +117,9 @@ module Koudoku
117
117
  end
118
118
  end
119
119
 
120
+ private
121
+ def subscription_params
122
+ params.require(:subscription).permit(:plan_id, :stripe_id, :current_price, :credit_card_token, :card_type, :last_four)
123
+ end
120
124
  end
121
125
  end
@@ -1,4 +1,6 @@
1
+ <% content_for :koudoku do %>
1
2
  <script type="text/javascript" src="https://js.stripe.com/v1/"></script>
3
+ <% end %>
2
4
 
3
5
  <%= form_for @subscription, url: url, html: {id: 'payment-form', class: 'form-horizontal'} do |f| %>
4
6
 
@@ -52,8 +54,6 @@
52
54
  // All this code taken from Stripe's own examples at:
53
55
  // https://stripe.com/docs/tutorials/forms .
54
56
 
55
- Stripe.setPublishableKey("<%= Koudoku.stripe_publishable_key %>");
56
-
57
57
  function stripeResponseHandler(status, response) {
58
58
 
59
59
  if (response.error) {
@@ -73,6 +73,8 @@
73
73
  }
74
74
 
75
75
  $(document).ready(function() {
76
+
77
+ Stripe.setPublishableKey("<%= Koudoku.stripe_publishable_key %>");
76
78
 
77
79
  // By default, don't show errors.
78
80
  $(".payment-errors").hide()
@@ -38,7 +38,7 @@ RUBY
38
38
  end
39
39
 
40
40
  # Generate subscription.
41
- generate("model", "subscription stripe_id:string plan_id:integer last_four:string coupon_id:integer last_four:string card_type:string current_price:float #{subscription_owner_model}_id:integer")
41
+ generate("model", "subscription stripe_id:string plan_id:integer last_four:string coupon_id:integer card_type:string current_price:float #{subscription_owner_model}_id:integer")
42
42
  gsub_file "app/models/subscription.rb", /ActiveRecord::Base/, "ActiveRecord::Base\n include Koudoku::Subscription\n\n belongs_to :#{subscription_owner_model}\n belongs_to :coupon\n"
43
43
 
44
44
  # Add the plans.
@@ -47,11 +47,8 @@ RUBY
47
47
 
48
48
  # Add coupons.
49
49
  generate("model coupon code:string free_trial_length:string")
50
- gsub_file "app/models/plan.rb", /ActiveRecord::Base/, "ActiveRecord::Base\n has_many :subscriptions\n"
50
+ gsub_file "app/models/coupon.rb", /ActiveRecord::Base/, "ActiveRecord::Base\n has_many :subscriptions\n"
51
51
 
52
- # Update the owner relationship.
53
- gsub_file "app/models/#{subscription_owner_model}.rb", /ActiveRecord::Base/, "ActiveRecord::Base\n\n # Added by Koudoku.\n has_one :subscription\n\n"
54
-
55
52
  # Update the owner relationship.
56
53
  gsub_file "app/models/#{subscription_owner_model}.rb", /ActiveRecord::Base/, "ActiveRecord::Base\n\n # Added by Koudoku.\n has_one :subscription\n\n"
57
54
 
@@ -61,7 +58,16 @@ RUBY
61
58
  end
62
59
 
63
60
  # Add webhooks to the route.
64
- gsub_file "config/routes.rb", /Application.routes.draw do/, "Application.routes.draw do\n\n # Added by Koudoku.\n mount Koudoku::Engine, at: 'koudoku'\n match 'pricing' => 'koudoku::subscriptions#index', as: 'pricing'\n\n"
61
+ gsub_file "config/routes.rb", /Application.routes.draw do/, <<-RUBY
62
+ Application.routes.draw do
63
+
64
+ # Added by Koudoku.
65
+ mount Koudoku::Engine, at: 'koudoku'
66
+ scope module: 'koudoku' do
67
+ get 'pricing' => 'subscriptions#index', as: 'pricing'
68
+ end
69
+
70
+ RUBY
65
71
 
66
72
  # Show the user the API key we generated.
67
73
  say "\nTo enable support for Stripe webhooks, point it to \"/koudoku/webhooks?api_key=#{api_key}\". This API key has been randomly generated, so it's unique to your application.\n\n"
@@ -69,4 +75,4 @@ RUBY
69
75
  end
70
76
 
71
77
  end
72
- end
78
+ end
@@ -1,3 +1,3 @@
1
1
  module Koudoku
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -1,3 +1,3 @@
1
1
  class Coupon < ActiveRecord::Base
2
- attr_accessible :code, :free_trial_length
2
+
3
3
  end
@@ -3,5 +3,4 @@ class Customer < ActiveRecord::Base
3
3
  # Added by Koudoku.
4
4
  has_one :subscription
5
5
 
6
- attr_accessible :email
7
6
  end
@@ -6,5 +6,4 @@ class Plan < ActiveRecord::Base
6
6
  belongs_to :coupon
7
7
  has_many :subscriptions
8
8
 
9
- attr_accessible :display_order, :features, :highlight, :name, :price, :interval, :stripe_id
10
9
  end
@@ -4,5 +4,4 @@ class Subscription < ActiveRecord::Base
4
4
  belongs_to :customer
5
5
  belongs_to :coupon
6
6
 
7
- attr_accessible :card_type, :coupon_id, :current_price, :customer_id, :last_four, :last_four, :plan_id, :stripe_id
8
7
  end
@@ -1,4 +1,6 @@
1
1
  Rails.application.routes.draw do
2
2
  mount Koudoku::Engine, at: "koudoku"
3
- match 'pricing' => 'koudoku::subscriptions#index', as: 'pricing'
3
+ scope module: 'koudoku' do
4
+ get 'pricing' => 'subscriptions#index', as: 'pricing'
5
+ end
4
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koudoku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,30 +9,30 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-20 00:00:00.000000000 Z
12
+ date: 2013-08-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 3.2.11
21
+ version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ~>
27
+ - - '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 3.2.11
29
+ version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: stripe
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ! '>='
35
+ - - '>='
36
36
  - !ruby/object:Gem::Version
37
37
  version: '0'
38
38
  type: :runtime
@@ -40,7 +40,7 @@ dependencies:
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ! '>='
43
+ - - '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  - !ruby/object:Gem::Dependency
@@ -48,7 +48,7 @@ dependencies:
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ! '>='
51
+ - - '>='
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  type: :runtime
@@ -56,7 +56,7 @@ dependencies:
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  - !ruby/object:Gem::Dependency
@@ -64,7 +64,7 @@ dependencies:
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
- - - ! '>='
67
+ - - '>='
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  type: :development
@@ -72,7 +72,7 @@ dependencies:
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - ! '>='
75
+ - - '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  - !ruby/object:Gem::Dependency
@@ -80,7 +80,7 @@ dependencies:
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
- - - ! '>='
83
+ - - '>='
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  type: :development
@@ -88,7 +88,7 @@ dependencies:
88
88
  version_requirements: !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
- - - ! '>='
91
+ - - '>='
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  - !ruby/object:Gem::Dependency
@@ -96,7 +96,7 @@ dependencies:
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
- - - ! '>='
99
+ - - '>='
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  type: :development
@@ -104,7 +104,7 @@ dependencies:
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
- - - ! '>='
107
+ - - '>='
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  - !ruby/object:Gem::Dependency
@@ -112,7 +112,7 @@ dependencies:
112
112
  requirement: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements:
115
- - - ! '>='
115
+ - - '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
@@ -120,7 +120,7 @@ dependencies:
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  none: false
122
122
  requirements:
123
- - - ! '>='
123
+ - - '>='
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  - !ruby/object:Gem::Dependency
@@ -128,7 +128,7 @@ dependencies:
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  none: false
130
130
  requirements:
131
- - - ! '>='
131
+ - - '>='
132
132
  - !ruby/object:Gem::Version
133
133
  version: '0'
134
134
  type: :development
@@ -136,7 +136,7 @@ dependencies:
136
136
  version_requirements: !ruby/object:Gem::Requirement
137
137
  none: false
138
138
  requirements:
139
- - - ! '>='
139
+ - - '>='
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  - !ruby/object:Gem::Dependency
@@ -144,7 +144,7 @@ dependencies:
144
144
  requirement: !ruby/object:Gem::Requirement
145
145
  none: false
146
146
  requirements:
147
- - - ! '>='
147
+ - - '>='
148
148
  - !ruby/object:Gem::Version
149
149
  version: '0'
150
150
  type: :development
@@ -152,7 +152,7 @@ dependencies:
152
152
  version_requirements: !ruby/object:Gem::Requirement
153
153
  none: false
154
154
  requirements:
155
- - - ! '>='
155
+ - - '>='
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
158
  description: Robust subscription support for Rails with Stripe. Provides package levels,
@@ -225,16 +225,12 @@ files:
225
225
  - spec/dummy/config/locales/en.yml
226
226
  - spec/dummy/config/routes.rb
227
227
  - spec/dummy/config.ru
228
- - spec/dummy/db/development.sqlite3
229
228
  - spec/dummy/db/migrate/20130318201927_create_customers.rb
230
229
  - spec/dummy/db/migrate/20130318204455_create_subscriptions.rb
231
230
  - spec/dummy/db/migrate/20130318204458_create_plans.rb
232
231
  - spec/dummy/db/migrate/20130318204502_create_coupons.rb
233
232
  - spec/dummy/db/migrate/20130520163946_add_interval_to_plan.rb
234
233
  - spec/dummy/db/schema.rb
235
- - spec/dummy/db/test.sqlite3
236
- - spec/dummy/log/development.log
237
- - spec/dummy/log/test.log
238
234
  - spec/dummy/public/404.html
239
235
  - spec/dummy/public/422.html
240
236
  - spec/dummy/public/500.html
@@ -254,43 +250,38 @@ files:
254
250
  - spec/spec_helper.rb
255
251
  homepage: http://github.com/andrewculver/koudoku
256
252
  licenses: []
257
- post_install_message: ! '
253
+ post_install_message: |2+
258
254
 
259
255
  Koudoku is still in early development, so if this installation is an upgrade
260
-
261
256
  from an earlier version, be sure to check the CHANGELOG for any instructions
262
-
263
257
  you may need to follow to accommodate breaking changes:
264
258
 
265
-
266
259
  https://github.com/andrewculver/koudoku/blob/master/CHANGELOG.md
267
260
 
268
-
269
- '
270
261
  rdoc_options: []
271
262
  require_paths:
272
263
  - lib
273
264
  required_ruby_version: !ruby/object:Gem::Requirement
274
265
  none: false
275
266
  requirements:
276
- - - ! '>='
267
+ - - '>='
277
268
  - !ruby/object:Gem::Version
278
269
  version: '0'
279
270
  segments:
280
271
  - 0
281
- hash: -3050597766114074760
272
+ hash: -3013715524796379015
282
273
  required_rubygems_version: !ruby/object:Gem::Requirement
283
274
  none: false
284
275
  requirements:
285
- - - ! '>='
276
+ - - '>='
286
277
  - !ruby/object:Gem::Version
287
278
  version: '0'
288
279
  segments:
289
280
  - 0
290
- hash: -3050597766114074760
281
+ hash: -3013715524796379015
291
282
  requirements: []
292
283
  rubyforge_project:
293
- rubygems_version: 1.8.24
284
+ rubygems_version: 1.8.25
294
285
  signing_key:
295
286
  specification_version: 3
296
287
  summary: Robust subscription support for Rails with Stripe.
@@ -328,16 +319,12 @@ test_files:
328
319
  - spec/dummy/config/locales/en.yml
329
320
  - spec/dummy/config/routes.rb
330
321
  - spec/dummy/config.ru
331
- - spec/dummy/db/development.sqlite3
332
322
  - spec/dummy/db/migrate/20130318201927_create_customers.rb
333
323
  - spec/dummy/db/migrate/20130318204455_create_subscriptions.rb
334
324
  - spec/dummy/db/migrate/20130318204458_create_plans.rb
335
325
  - spec/dummy/db/migrate/20130318204502_create_coupons.rb
336
326
  - spec/dummy/db/migrate/20130520163946_add_interval_to_plan.rb
337
327
  - spec/dummy/db/schema.rb
338
- - spec/dummy/db/test.sqlite3
339
- - spec/dummy/log/development.log
340
- - spec/dummy/log/test.log
341
328
  - spec/dummy/public/404.html
342
329
  - spec/dummy/public/422.html
343
330
  - spec/dummy/public/500.html