paid_up 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/paid_up.rb CHANGED
@@ -39,8 +39,7 @@ end
39
39
 
40
40
  Integer.send(:include, PaidUp::Extensions::Integer)
41
41
 
42
- Stripe::Customer.send(:include, PaidUp::Extensions::Stripe)
43
- Stripe::Plan.send(:include, PaidUp::Extensions::Stripe)
42
+ Stripe::APIResource.send(:include, PaidUp::Extensions::Stripe)
44
43
 
45
44
  ActiveRecord::Base.send(:include, PaidUp::Mixins::Subscriber)
46
45
  ActiveRecord::Base.send(:include, PaidUp::Mixins::PaidFor)
@@ -6,6 +6,7 @@ module PaidUp::Extensions
6
6
  begin
7
7
  self.retrieve(id)
8
8
  rescue
9
+ item[:id] ||= id
9
10
  self.create(item)
10
11
  end
11
12
  end
@@ -28,10 +28,10 @@ module PaidUp::Mixins
28
28
  nil
29
29
  end
30
30
  }
31
- self.send(:define_method, :subscribe_to_plan) { |plan_to_set, stripeToken = nil|
31
+ self.send(:define_method, :subscribe_to_plan) { |plan_to_set, stripe_token = nil, trial_end = nil|
32
32
  if stripe_id.present? && !subscription.nil? # There is an existing subscription
33
- if stripeToken.present? # The customer has entered a new card
34
- subscription.source = stripeToken
33
+ if stripe_token.present? # The customer has entered a new card
34
+ subscription.source = stripe_token
35
35
  subscription.save
36
36
  reload
37
37
  end
@@ -39,13 +39,18 @@ module PaidUp::Mixins
39
39
  stripe_data.coupon = coupon_code
40
40
  stripe_data.save
41
41
  end
42
+ if trial_end.present?
43
+ stripe_data.subscription.trial_end = trial_end
44
+ stripe_data.subscription.save
45
+ end
42
46
  subscription.plan = plan_to_set.stripe_id
43
47
  result = subscription.save || ( raise(:could_not_update_subscription.l) && false )
44
48
  else # Totally new subscription
45
49
  args = {
46
- source: stripeToken,
50
+ source: stripe_token,
47
51
  plan: plan_to_set.stripe_id,
48
- email: email
52
+ email: email,
53
+ trial_end: trial_end
49
54
  }
50
55
  if coupon_code.present?
51
56
  args[:coupon] = coupon_code
@@ -70,7 +75,11 @@ module PaidUp::Mixins
70
75
  subscribe_to_plan PaidUp::Plan.free
71
76
  }
72
77
  self.send(:define_method, :plan) {
73
- PaidUp::Plan.find_by_stripe_id(subscription.plan.id)
78
+ if subscription.present?
79
+ PaidUp::Plan.find_by_stripe_id(subscription.plan.id)
80
+ else
81
+ PaidUp::Plan.free
82
+ end
74
83
  }
75
84
  self.send(:define_method, :table_rows_unlimited?) { |table_name|
76
85
  table_rows_allowed(table_name) == PaidUp::Unlimited.to_i
@@ -110,16 +119,24 @@ module PaidUp::Mixins
110
119
  stripe_data.subscriptions.data.first
111
120
  }
112
121
  self.send(:define_method, :is_subscribed_to?) { |plan_to_check|
113
- plan.id == plan_to_check.id
122
+ plan.present? && plan.id == plan_to_check.id
114
123
  }
115
124
  self.send(:define_method, :can_upgrade_to?) { |plan_to_check|
116
- !is_subscribed_to?(plan_to_check) && (plan_to_check.sort_order.to_i > plan.sort_order.to_i)
125
+ plan.nil? || (
126
+ !is_subscribed_to?(plan_to_check) &&
127
+ (plan_to_check.sort_order.to_i > plan.sort_order.to_i)
128
+ )
117
129
  }
118
130
  self.send(:define_method, :can_downgrade_to?) { |plan_to_check|
119
- !is_subscribed_to?(plan_to_check) && (plan_to_check.sort_order.to_i < plan.sort_order.to_i)
131
+ !plan.nil? && (
132
+ !is_subscribed_to?(plan_to_check) &&
133
+ (plan_to_check.sort_order.to_i < plan.sort_order.to_i)
134
+ )
120
135
  }
121
136
  self.send(:define_method, :using_free_plan?) {
122
- plan.stripe_id == PaidUp.configuration.free_plan_stripe_id || stripe_data.delinquent
137
+ plan.nil? ||
138
+ stripe_data.delinquent ||
139
+ (plan.stripe_id == PaidUp.configuration.free_plan_stripe_id)
123
140
  }
124
141
  self.send(:define_method, :set_default_attributes) {
125
142
  if new_record?
data/paid_up.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: paid_up 0.9.1 ruby lib
5
+ # stub: paid_up 0.9.2 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "paid_up"
9
- s.version = "0.9.1"
9
+ s.version = "0.9.2"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Karen Lundgren"]
14
- s.date = "2016-02-14"
14
+ s.date = "2016-02-16"
15
15
  s.description = "Allows a model of your choosing (such as users) to subscribe to a plan, which enables features."
16
16
  s.email = "karen.e.lundgren@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -34,6 +34,8 @@ Gem::Specification.new do |s|
34
34
  "app/helpers/paid_up/paid_up_helper.rb",
35
35
  "app/helpers/paid_up/plans_helper.rb",
36
36
  "app/helpers/paid_up/subscriptions_helper.rb",
37
+ "app/mailers/paid_up/paid_up_mailer.rb",
38
+ "app/mailers/paid_up/subscription_mailer.rb",
37
39
  "app/models/paid_up/ability.rb",
38
40
  "app/models/paid_up/plan.rb",
39
41
  "app/models/paid_up/plan_feature_setting.rb",
@@ -48,9 +50,13 @@ Gem::Specification.new do |s|
48
50
  "app/views/devise/sessions/new.html.haml",
49
51
  "app/views/devise/shared/_links.html.haml",
50
52
  "app/views/devise/unlocks/new.html.haml",
53
+ "app/views/layouts/mailer.html.haml",
54
+ "app/views/layouts/mailer.text.haml",
51
55
  "app/views/paid_up/features/_abilities_table.html.haml",
52
56
  "app/views/paid_up/features/_table.html.haml",
53
57
  "app/views/paid_up/plans/index.html.haml",
58
+ "app/views/paid_up/subscription_mailer/payment_failed_email.html.haml",
59
+ "app/views/paid_up/subscription_mailer/payment_failed_email.text.haml",
54
60
  "app/views/paid_up/subscriptions/index.html.haml",
55
61
  "app/views/paid_up/subscriptions/new.html.haml",
56
62
  "config/initializers/stripe.rb",
@@ -139,6 +145,7 @@ Gem::Specification.new do |s|
139
145
  "spec/dummy/db/seeds.rb",
140
146
  "spec/dummy/db/test.sqlite3",
141
147
  "spec/dummy/lib/assets/.keep",
148
+ "spec/dummy/lib/tasks/system.rake",
142
149
  "spec/dummy/log/.keep",
143
150
  "spec/dummy/log/development.log",
144
151
  "spec/dummy/public/404.html",
@@ -157,6 +164,8 @@ Gem::Specification.new do |s|
157
164
  "spec/factories/plan.rb",
158
165
  "spec/factories/plan_feature_setting.rb",
159
166
  "spec/factories/user.rb",
167
+ "spec/mailers/paid_up/subscription_mailer_spec.rb",
168
+ "spec/mailers/previews/paid_up/subscription_mailer_preview.rb",
160
169
  "spec/models/group_spec.rb",
161
170
  "spec/models/paid_up/feature_spec.rb",
162
171
  "spec/models/paid_up/plan_feature_setting_spec.rb",
@@ -201,6 +210,7 @@ Gem::Specification.new do |s|
201
210
  s.add_runtime_dependency(%q<stripe>, ["~> 1.21"])
202
211
  s.add_development_dependency(%q<jeweler>, ["~> 2"])
203
212
  s.add_development_dependency(%q<bundler>, ["~> 1"])
213
+ s.add_development_dependency(%q<web-console>, ["~> 3.0"])
204
214
  s.add_development_dependency(%q<sqlite3>, ["~> 1.3"])
205
215
  s.add_development_dependency(%q<forgery>, ["~> 0.6"])
206
216
  s.add_development_dependency(%q<bootstrap-sass>, ["~> 3.3"])
@@ -223,6 +233,7 @@ Gem::Specification.new do |s|
223
233
  s.add_dependency(%q<stripe>, ["~> 1.21"])
224
234
  s.add_dependency(%q<jeweler>, ["~> 2"])
225
235
  s.add_dependency(%q<bundler>, ["~> 1"])
236
+ s.add_dependency(%q<web-console>, ["~> 3.0"])
226
237
  s.add_dependency(%q<sqlite3>, ["~> 1.3"])
227
238
  s.add_dependency(%q<forgery>, ["~> 0.6"])
228
239
  s.add_dependency(%q<bootstrap-sass>, ["~> 3.3"])
@@ -246,6 +257,7 @@ Gem::Specification.new do |s|
246
257
  s.add_dependency(%q<stripe>, ["~> 1.21"])
247
258
  s.add_dependency(%q<jeweler>, ["~> 2"])
248
259
  s.add_dependency(%q<bundler>, ["~> 1"])
260
+ s.add_dependency(%q<web-console>, ["~> 3.0"])
249
261
  s.add_dependency(%q<sqlite3>, ["~> 1.3"])
250
262
  s.add_dependency(%q<forgery>, ["~> 0.6"])
251
263
  s.add_dependency(%q<bootstrap-sass>, ["~> 3.3"])
@@ -1,17 +1,4 @@
1
1
  Rails.application.routes.draw do
2
-
3
-
4
-
5
- mount PaidUp::Engine => '/', :as => 'paid_up'
6
2
  devise_for :users
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
- end
3
+ mount PaidUp::Engine => '/', :as => 'paid_up'
4
+ end
Binary file
@@ -1,99 +1,114 @@
1
- # Dir[Rails.root.join("spec/factories/*.rb")].each {|f| require f}
2
-
3
1
  ###############
4
- # Plans #
2
+ # Plans #
5
3
  ###############
6
4
 
7
5
  Stripe::Plan.find_or_create_by_id(
8
- 'anonymous-plan',
9
- {
10
- :amount => 0,
11
- :interval => 'month',
12
- :name => 'Anonymous Plan',
13
- :currency => 'usd',
14
- :id => 'anonymous-plan'
15
- }
6
+ 'anonymous-plan',
7
+ {
8
+ amount: 0,
9
+ interval: 'month',
10
+ name: 'Anonymous Plan',
11
+ currency: 'usd'
12
+ }
16
13
  )
17
14
  anonymous_plan = PaidUp::Plan.create(
18
- title: 'Anonymous',
19
- stripe_id: 'anonymous-plan',
20
- description: "What you can do without logging in.",
21
- sort_order: -1
15
+ title: 'Anonymous',
16
+ stripe_id: 'anonymous-plan',
17
+ description: "What you can do without logging in.",
18
+ sort_order: -1
22
19
  )
23
20
  Stripe::Plan.find_or_create_by_id(
24
- 'free-plan',
25
- {
26
- :amount => 0,
27
- :interval => 'month',
28
- :name => 'Free Plan',
29
- :currency => 'usd',
30
- :id => 'free-plan'
31
- }
21
+ 'free-plan',
22
+ {
23
+ amount: 0,
24
+ interval: 'month',
25
+ name: 'Free Plan',
26
+ currency: 'usd'
27
+ }
32
28
  )
33
29
  free_plan = PaidUp::Plan.create(
34
- title: 'Free',
35
- stripe_id: 'free-plan',
36
- description: "Can't beat the price!",
37
- sort_order: 0
30
+ title: 'Free',
31
+ stripe_id: 'free-plan',
32
+ description: "Can't beat the price!",
33
+ sort_order: 0
38
34
  )
39
35
  Stripe::Plan.find_or_create_by_id(
40
- 'no-ads-plan',
41
- {
42
- :amount => 100,
43
- :interval => 'month',
44
- :name => 'No Ads Plan',
45
- :currency => 'usd',
46
- :id => 'no-ads-plan'
47
- }
36
+ 'no-ads-plan',
37
+ {
38
+ amount: 100,
39
+ interval: 'month',
40
+ name: 'No Ads Plan',
41
+ currency: 'usd'
42
+ }
48
43
  )
49
44
  no_ads_plan = PaidUp::Plan.create(
50
- title: 'No Ads',
51
- stripe_id: 'no-ads-plan',
52
- description: "No frills, just removes the ads.",
53
- sort_order: 1
45
+ title: 'No Ads',
46
+ stripe_id: 'no-ads-plan',
47
+ description: "No frills, just removes the ads.",
48
+ sort_order: 1
54
49
  )
55
50
  Stripe::Plan.find_or_create_by_id(
56
- 'group-leader-plan',
57
- {
58
- :amount => 500,
59
- :interval => 'month',
60
- :name => 'Group Leader Plan',
61
- :currency => 'usd',
62
- :id => 'group-leader-plan'
63
- }
51
+ 'group-leader-plan',
52
+ {
53
+ amount: 500,
54
+ interval: 'month',
55
+ name: 'Group Leader Plan',
56
+ currency: 'usd'
57
+ }
64
58
  )
65
59
  group_leader_plan = PaidUp::Plan.create(
66
- title: 'Group Leader',
67
- stripe_id: 'group-leader-plan',
68
- description: "For leaders of single groups, with configuration.",
69
- sort_order: 2
60
+ title: 'Group Leader',
61
+ stripe_id: 'group-leader-plan',
62
+ description: "For leaders of single groups, with configuration.",
63
+ sort_order: 2
70
64
  )
71
65
  Stripe::Plan.find_or_create_by_id(
72
- 'professional-plan',
66
+ 'professional-plan',
67
+ {
68
+ amount: 1000,
69
+ interval: 'month',
70
+ name: 'Professional Plan',
71
+ currency: 'usd'
72
+ }
73
+ )
74
+ professional_plan = PaidUp::Plan.create(
75
+ title: 'Professional',
76
+ stripe_id: 'professional-plan',
77
+ description: "Designed for professionals with unlimited groups, a calendar and configuration.",
78
+ sort_order: 3
79
+ )
80
+
81
+ ###############
82
+ # Coupons #
83
+ ###############
84
+
85
+ Stripe::Coupon.find_or_create_by_id(
86
+ '25OFF',
73
87
  {
74
- :amount => 1000,
75
- :interval => 'month',
76
- :name => 'Professional Plan',
77
- :currency => 'usd',
78
- :id => 'professional-plan'
88
+ percent_off: 25,
89
+ currency: 'usd',
90
+ duration: 'forever'
79
91
  }
80
92
  )
81
- professional_plan = PaidUp::Plan.create(
82
- title: 'Professional',
83
- stripe_id: 'professional-plan',
84
- description: "Designed for professionals with unlimited groups, a calendar and configuration.",
85
- sort_order: 3
93
+
94
+ Stripe::Coupon.find_or_create_by_id(
95
+ 'MINUS25',
96
+ {
97
+ amount_off: 25,
98
+ currency: 'usd',
99
+ duration: 'forever'
100
+ }
86
101
  )
102
+
87
103
  ######################
88
104
  # Anonymous Customer #
89
105
  ######################
90
106
  Stripe::Customer.find_or_create_by_id(
91
- 'anonymous-customer',
92
- {
93
- id: 'anonymous-customer',
94
- description: 'Anonymous Customer',
95
- plan: 'anonymous-plan'
96
- }
107
+ 'anonymous-customer',
108
+ {
109
+ description: 'Anonymous Customer',
110
+ plan: 'anonymous-plan'
111
+ }
97
112
  )
98
113
  #######################
99
114
  # PlanFeatureSettings #
@@ -101,105 +116,112 @@ Stripe::Customer.find_or_create_by_id(
101
116
 
102
117
  # Ad Free
103
118
  PaidUp::PlanFeatureSetting.create(
104
- feature: 'ad_free',
105
- plan: no_ads_plan,
106
- setting: 1
119
+ feature: 'ad_free',
120
+ plan: no_ads_plan,
121
+ setting: 1
107
122
  )
108
123
 
109
124
  # Group Leader
110
125
  PaidUp::PlanFeatureSetting.create(
111
- feature: 'ad_free',
112
- plan: group_leader_plan,
113
- setting: 1
126
+ feature: 'ad_free',
127
+ plan: group_leader_plan,
128
+ setting: 1
114
129
  )
115
130
  PaidUp::PlanFeatureSetting.create(
116
- feature: 'groups',
117
- plan: group_leader_plan,
118
- setting: 5
131
+ feature: 'groups',
132
+ plan: group_leader_plan,
133
+ setting: 5
119
134
  )
120
135
  PaidUp::PlanFeatureSetting.create(
121
- feature: 'doodads',
122
- plan: group_leader_plan,
123
- setting: 10
136
+ feature: 'doodads',
137
+ plan: group_leader_plan,
138
+ setting: 10
124
139
  )
125
140
 
126
141
  # Professional
127
142
  PaidUp::PlanFeatureSetting.create(
128
- feature: 'ad_free',
129
- plan: professional_plan,
130
- setting: 1
143
+ feature: 'ad_free',
144
+ plan: professional_plan,
145
+ setting: 1
131
146
  )
132
147
  PaidUp::PlanFeatureSetting.create(
133
- feature: 'groups',
134
- plan: professional_plan,
135
- setting: PaidUp::Unlimited.to_i(:db)
148
+ feature: 'groups',
149
+ plan: professional_plan,
150
+ setting: PaidUp::Unlimited.to_i(:db)
136
151
  )
137
152
  PaidUp::PlanFeatureSetting.create(
138
- feature: 'doodads',
139
- plan: professional_plan,
140
- setting: PaidUp::Unlimited.to_i(:db)
153
+ feature: 'doodads',
154
+ plan: professional_plan,
155
+ setting: PaidUp::Unlimited.to_i(:db)
141
156
  )
142
157
 
143
158
  ###############
144
- # Users #
159
+ # Users #
145
160
  ###############
146
161
 
147
162
  free_subscriber = FactoryGirl.create(
148
- :user,
149
- name: 'Free Subscriber',
150
- plan: free_plan
163
+ :user,
164
+ name: 'Free Subscriber',
165
+ plan: free_plan
151
166
  )
152
167
 
153
168
  no_ads_subscriber = FactoryGirl.create(
154
- :user,
155
- name: 'No Ads Subscriber',
156
- plan: no_ads_plan
169
+ :user,
170
+ name: 'No Ads Subscriber',
171
+ plan: no_ads_plan
157
172
  )
158
173
 
159
174
  group_leader_subscriber = FactoryGirl.create(
160
- :user,
161
- name: 'Group Leader Subscriber',
162
- plan: group_leader_plan
175
+ :user,
176
+ name: 'Group Leader Subscriber',
177
+ plan: group_leader_plan
163
178
  )
164
179
 
165
180
  disabling_subscriber = FactoryGirl.create(
166
- :user,
167
- name: 'Disabling Subscriber',
168
- plan: group_leader_plan
181
+ :user,
182
+ name: 'Disabling Subscriber',
183
+ plan: group_leader_plan
169
184
  )
170
185
 
171
186
  professional_subscriber = FactoryGirl.create(
172
- :user,
173
- name: 'Professional Subscriber',
174
- plan: professional_plan
187
+ :user,
188
+ name: 'Professional Subscriber',
189
+ plan: professional_plan
175
190
  )
176
191
 
177
192
  blank_subscriber = FactoryGirl.create(
178
- :user,
179
- name: 'Blank Subscriber',
180
- plan: professional_plan
193
+ :user,
194
+ name: 'Blank Subscriber',
195
+ plan: professional_plan
196
+ )
197
+
198
+ past_due_subscriber = FactoryGirl.create(
199
+ :user,
200
+ name: 'Past Due Subscriber',
201
+ plan: professional_plan,
202
+ past_due: true
181
203
  )
182
204
 
183
205
  ###############
184
- # Groups #
206
+ # Groups #
185
207
  ###############
186
208
 
187
209
  FactoryGirl.create(
188
- :group,
189
- title: 'First Group',
190
- owner: group_leader_subscriber
210
+ :group,
211
+ title: 'First Group',
212
+ owner: group_leader_subscriber
191
213
  )
192
214
 
193
215
  FactoryGirl.create(
194
- :group,
195
- title: 'Second Group',
196
- owner: professional_subscriber
216
+ :group,
217
+ title: 'Second Group',
218
+ owner: professional_subscriber
197
219
  )
198
220
 
199
221
  FactoryGirl.create(
200
- :group,
201
- title: 'Third Group',
202
- owner: professional_subscriber
222
+ :group,
223
+ title: 'Third Group',
224
+ owner: professional_subscriber
203
225
  )
204
226
 
205
227
  5.times do
@@ -207,7 +229,13 @@ FactoryGirl.create(
207
229
  end
208
230
 
209
231
  FactoryGirl.create(
210
- :group,
211
- title: 'Disabled Group',
212
- owner: disabling_subscriber
232
+ :group,
233
+ title: 'Disabled Group',
234
+ owner: disabling_subscriber
235
+ )
236
+
237
+ FactoryGirl.create(
238
+ :group,
239
+ title: 'Past Due Group',
240
+ owner: past_due_subscriber
213
241
  )