paid_up 0.11.7 → 0.12.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +17 -13
- data/.rubocop_todo.yml +7 -0
- data/.travis.yml +4 -3
- data/Gemfile +29 -24
- data/README.md +22 -1
- data/Rakefile +6 -5
- data/VERSION +1 -1
- data/app/controllers/paid_up/paid_up_controller.rb +16 -9
- data/app/controllers/paid_up/plans_controller.rb +2 -0
- data/app/controllers/paid_up/subscriptions_controller.rb +58 -49
- data/app/helpers/paid_up/features_helper.rb +35 -34
- data/app/helpers/paid_up/paid_up_helper.rb +10 -8
- data/app/helpers/paid_up/plans_helper.rb +75 -55
- data/app/helpers/paid_up/subscriptions_helper.rb +17 -13
- data/app/models/paid_up/ability.rb +53 -46
- data/app/models/paid_up/plan.rb +36 -34
- data/app/models/paid_up/plan_feature_setting.rb +2 -0
- data/app/models/paid_up/unlimited.rb +2 -0
- data/app/views/paid_up/features/_abilities_table.html.haml +1 -45
- data/app/views/paid_up/features/_boolean_state.html.haml +6 -0
- data/app/views/paid_up/features/_setting_state.html.haml +13 -0
- data/app/views/paid_up/subscriptions/index.html.haml +2 -2
- data/config/initializers/stripe.rb +2 -0
- data/config/locales/en.yml +4 -1
- data/config/routes.rb +3 -1
- data/lib/generators/paid_up/install/install_generator.rb +4 -1
- data/lib/generators/paid_up/install/templates/ability.rb +2 -0
- data/lib/generators/paid_up/install/templates/initializer.rb +2 -0
- data/lib/generators/paid_up/utils.rb +2 -0
- data/lib/paid_up/configuration.rb +4 -2
- data/lib/paid_up/engine.rb +2 -0
- data/lib/paid_up/extensions/integer.rb +2 -0
- data/lib/paid_up/extensions/stripe.rb +2 -0
- data/lib/paid_up/feature.rb +10 -7
- data/lib/paid_up/feature_setting_type.rb +45 -0
- data/lib/paid_up/feature_setting_types/rolify.rb +10 -0
- data/lib/paid_up/feature_setting_types/table.rb +7 -0
- data/lib/paid_up/localization.rb +2 -0
- data/lib/paid_up/mixins/paid_for.rb +59 -47
- data/lib/paid_up/mixins/subscriber.rb +45 -101
- data/lib/paid_up/railtie.rb +2 -0
- data/lib/paid_up/ruby_version_check.rb +15 -0
- data/lib/paid_up/subscription.rb +80 -0
- data/lib/paid_up/validators/rolify_rows.rb +11 -6
- data/lib/paid_up/validators/table_rows.rb +9 -6
- data/lib/paid_up/version.rb +2 -0
- data/lib/paid_up.rb +8 -0
- data/paid_up.gemspec +108 -115
- data/spec/controllers/paid_up/plans_spec.rb +2 -0
- data/spec/controllers/paid_up/subscriptions_spec.rb +18 -11
- data/spec/dummy/Rakefile +2 -0
- data/spec/dummy/app/assets/stylesheets/application.css.scss +6 -0
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/models/ability.rb +2 -0
- data/spec/dummy/app/models/doodad.rb +2 -0
- data/spec/dummy/app/models/group.rb +2 -0
- data/spec/dummy/app/models/post.rb +2 -0
- data/spec/dummy/app/models/role.rb +2 -0
- data/spec/dummy/app/models/user.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.haml +13 -11
- data/spec/dummy/bin/bundle +2 -0
- data/spec/dummy/bin/rails +2 -0
- data/spec/dummy/bin/rake +2 -0
- data/spec/dummy/bin/setup +10 -8
- data/spec/dummy/config/application.rb +2 -3
- data/spec/dummy/config/boot.rb +2 -0
- data/spec/dummy/config/environment.rb +2 -0
- data/spec/dummy/config/environments/development.rb +2 -0
- data/spec/dummy/config/environments/test.rb +2 -4
- data/spec/dummy/config/initializers/assets.rb +2 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +1 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +2 -0
- data/spec/dummy/config/initializers/devise.rb +2 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +2 -0
- data/spec/dummy/config/initializers/inflections.rb +1 -0
- data/spec/dummy/config/initializers/mime_types.rb +1 -0
- data/spec/dummy/config/initializers/paid_up.rb +10 -16
- data/spec/dummy/config/initializers/rolify.rb +2 -0
- data/spec/dummy/config/initializers/session_store.rb +2 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
- data/spec/dummy/config/routes.rb +2 -0
- data/spec/dummy/config.ru +2 -0
- data/spec/dummy/db/schema.rb +14 -23
- data/spec/dummy/db/seeds.rb +8 -6
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/tasks/system.rake +2 -0
- data/spec/factories/doodad.rb +2 -0
- data/spec/factories/group.rb +2 -0
- data/spec/factories/plan.rb +2 -0
- data/spec/factories/plan_feature_setting.rb +2 -0
- data/spec/factories/post.rb +2 -0
- data/spec/factories/user.rb +3 -1
- data/spec/models/group_spec.rb +9 -7
- data/spec/models/paid_up/feature_spec.rb +2 -0
- data/spec/models/paid_up/plan_feature_setting_spec.rb +2 -0
- data/spec/models/paid_up/plan_spec.rb +2 -0
- data/spec/models/scope_spec.rb +9 -7
- data/spec/models/user_spec.rb +60 -58
- data/spec/paid_up_spec.rb +2 -0
- data/spec/rails_helper.rb +16 -2
- data/spec/routing/paid_up/plans_spec.rb +2 -0
- data/spec/routing/paid_up/subscription_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/controller_macros.rb +2 -0
- data/spec/support/factory_girl.rb +2 -0
- data/spec/support/loaded_site/features.rb +2 -0
- data/spec/support/loaded_site/groups.rb +2 -0
- data/spec/support/loaded_site/loaded_site.rb +2 -0
- data/spec/support/loaded_site/plans.rb +2 -0
- data/spec/support/loaded_site/posts.rb +2 -0
- data/spec/support/loaded_site/users.rb +4 -2
- data/spec/support/stripe.rb +2 -0
- data/spec/views/paid_up/plans_spec.rb +9 -7
- data/spec/views/paid_up/subscriptions_spec.rb +20 -19
- metadata +124 -90
- data/app/views/devise/confirmations/new.html.haml +0 -13
- data/app/views/devise/passwords/edit.html.haml +0 -19
- data/app/views/devise/passwords/new.html.haml +0 -14
- data/app/views/devise/registrations/_new_form.html.haml +0 -23
- data/app/views/devise/registrations/edit.html.haml +0 -39
- data/app/views/devise/registrations/new.html.haml +0 -11
- data/app/views/devise/sessions/_new_form.html.haml +0 -21
- data/app/views/devise/sessions/new.html.haml +0 -11
- data/app/views/devise/shared/_links.html.haml +0 -14
- data/app/views/devise/unlocks/new.html.haml +0 -14
- data/app/views/layouts/mailer.html.haml +0 -3
- data/app/views/layouts/mailer.text.haml +0 -1
- data/app/views/paid_up/subscription_mailer/payment_failed_email.html.haml +0 -0
- data/app/views/paid_up/subscription_mailer/payment_failed_email.text.haml +0 -0
- data/coverage/.last_run.json +0 -5
- data/coverage/.resultset.json +0 -1927
- data/spec/dummy/app/views/pages/index.html.haml +0 -1
- data/spec/dummy/config/environments/production.rb +0 -83
- data/spec/dummy/config/initializers/high_voltage.rb +0 -3
@@ -1,33 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PaidUp
|
2
4
|
# PaidUp Plans Helper
|
3
5
|
module PlansHelper
|
4
6
|
include ::ActionView::Helpers::NumberHelper
|
5
7
|
|
6
8
|
def plan_charge_human(plan, discount)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
amount -= (discount.coupon.percent_off || 0) * 0.01 * amount
|
11
|
-
amount -= (discount.coupon.amount_off || 0)
|
12
|
-
amount = amount > 0 ? amount : 0
|
13
|
-
|
14
|
-
orig_money = Money.new(orig_amount, plan.currency)
|
15
|
-
money = Money.new(amount, plan.currency)
|
16
|
-
|
17
|
-
html = content_tag(
|
18
|
-
:s,
|
19
|
-
(orig_money.format + '/' + plan_period_phrase(plan))
|
20
|
-
)
|
21
|
-
html << ' '
|
22
|
-
html << content_tag(
|
23
|
-
:span,
|
24
|
-
(money.format + '/' + plan_period_phrase(plan)),
|
25
|
-
class: 'text-danger'
|
26
|
-
)
|
27
|
-
else
|
28
|
-
html = plan.money.format + '/' + plan_period_phrase(plan)
|
9
|
+
interval = plan_period_phrase(plan)
|
10
|
+
if plan.adjust?(discount)
|
11
|
+
return amount_per_interval(plan.money.format, interval)
|
29
12
|
end
|
30
|
-
|
13
|
+
plan_charge_reduced(
|
14
|
+
plan.money.format,
|
15
|
+
plan.adjusted_money(discount).format,
|
16
|
+
interval
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def plan_button(plan, text = nil, html_options = {})
|
21
|
+
atts = plan_button_atts(plan)
|
22
|
+
atts[:text] = text if text.present?
|
23
|
+
atts[:link] ||= paid_up.new_plan_subscription_path(plan)
|
24
|
+
|
25
|
+
html_options[:method] ||= :get
|
26
|
+
html_options[:data] = atts.delete(:data)
|
27
|
+
|
28
|
+
icon_button_to(
|
29
|
+
atts[:css_class], atts[:icon_class], atts[:text], atts[:link],
|
30
|
+
html_options
|
31
|
+
)
|
31
32
|
end
|
32
33
|
|
33
34
|
def plan_period_phrase(plan)
|
@@ -39,38 +40,57 @@ module PaidUp
|
|
39
40
|
period_phrase + plan.interval.capitalize
|
40
41
|
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
43
|
+
private
|
44
|
+
|
45
|
+
def amount_per_interval(amount, interval)
|
46
|
+
"#{amount}/#{interval}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def plan_charge_reduced(old_money, new_money, interval)
|
50
|
+
html = []
|
51
|
+
html << content_tag(:s, amount_per_interval(old_money, interval))
|
52
|
+
html << content_tag(
|
53
|
+
:span, amount_per_interval(new_money, interval), class: 'text-danger'
|
54
|
+
)
|
55
|
+
html.join(' ')
|
56
|
+
end
|
57
|
+
|
58
|
+
# rubocop:disable Metrics/AbcSize
|
59
|
+
# This is just this complex.
|
60
|
+
def plan_button_atts(plan)
|
61
|
+
return anonymous_atts unless user_signed_in?
|
62
|
+
return delinquent_atts if current_user.stripe_data.delinquent
|
63
|
+
return same_plan_atts if current_user.subscribed_to? plan
|
64
|
+
return upgrade_atts if current_user.can_upgrade_to? plan
|
65
|
+
return downgrade_atts if current_user.can_downgrade_to? plan
|
66
|
+
sidegrade_atts
|
67
|
+
end
|
68
|
+
# rubocop:enable Metrics/AbcSize
|
69
|
+
|
70
|
+
def anonymous_atts
|
71
|
+
{ text: :sign_up.l, icon_class: 'arrow-right', css_class: 'success' }
|
72
|
+
end
|
73
|
+
|
74
|
+
def delinquent_atts
|
75
|
+
{ text: :subscribe.l, icon_class: 'arrow-right', css_class: 'info' }
|
76
|
+
end
|
77
|
+
|
78
|
+
def upgrade_atts
|
79
|
+
{ text: :subscribe.l, icon_class: 'arrow-up', css_class: 'success' }
|
80
|
+
end
|
81
|
+
|
82
|
+
def downgrade_atts
|
83
|
+
{ text: :subscribe.l, icon_class: 'arrow-down', css_class: 'danger',
|
84
|
+
data: { confirm: :are_you_sure.l } }
|
85
|
+
end
|
86
|
+
|
87
|
+
def same_plan_atts
|
88
|
+
{ text: :already_subscribed.l, icon_class: 'ok', css_class: 'disabled',
|
89
|
+
link: '#' }
|
90
|
+
end
|
91
|
+
|
92
|
+
def sidegrade_atts
|
93
|
+
{ text: :subscribe.l, icon_class: 'arrow-right', css_class: 'info' }
|
74
94
|
end
|
75
95
|
end
|
76
96
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PaidUp
|
2
4
|
# PaidUp Subscriptions Helper
|
3
5
|
module SubscriptionsHelper
|
@@ -8,21 +10,23 @@ module PaidUp
|
|
8
10
|
|
9
11
|
data[:status.l] = subscription.status
|
10
12
|
|
11
|
-
|
12
|
-
data
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
data = add_date_if_set(
|
14
|
+
data, :paid_thru, subscription.current_period_start,
|
15
|
+
subscription.current_period_end
|
16
|
+
)
|
17
|
+
data = add_date_if_set(
|
18
|
+
data, :trial_period, subscription.trial_start, subscription.trial_end
|
19
|
+
)
|
20
|
+
dl data
|
21
|
+
end
|
17
22
|
|
18
|
-
|
19
|
-
data[:trial_period.l] = date_range(
|
20
|
-
subscription.trial_start,
|
21
|
-
subscription.trial_end
|
22
|
-
)
|
23
|
-
end
|
23
|
+
private
|
24
24
|
|
25
|
-
|
25
|
+
def add_date_if_set(data, text_sym, date_start, date_end)
|
26
|
+
if date_start || date_end
|
27
|
+
data[text_sym.l] = date_range(date_start, date_end)
|
28
|
+
end
|
29
|
+
data
|
26
30
|
end
|
27
31
|
end
|
28
32
|
end
|
@@ -1,56 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PaidUp
|
2
4
|
# PaidUp Ability model
|
3
5
|
module Ability
|
4
6
|
include CanCan::Ability
|
5
7
|
|
6
8
|
def initialize_paid_up(user)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
can :index, feature.feature_model
|
28
|
-
can :show, feature.feature_model, &:enabled
|
29
|
-
if user.rolify_rows_allowed(feature.slug) > 0 ||
|
30
|
-
user.rolify_rows_unlimited?(feature.slug)
|
31
|
-
can(
|
32
|
-
:manage,
|
33
|
-
feature.feature_model,
|
34
|
-
id: feature.feature_model.with_role(:owner, user).ids
|
35
|
-
)
|
36
|
-
can :own, feature.feature_model
|
37
|
-
cannot :create, feature.feature_model
|
38
|
-
user.rolify_rows_remaining(feature.slug) > 0 &&
|
39
|
-
can([:create, :new], feature.feature_model)
|
40
|
-
else
|
41
|
-
cannot :delete, feature.feature_model
|
42
|
-
cannot :update, feature.feature_model
|
43
|
-
cannot :own, feature.feature_model
|
44
|
-
cannot :create, feature.feature_model
|
45
|
-
end
|
46
|
-
when 'boolean'
|
47
|
-
if user.plan.feature_setting feature.slug
|
48
|
-
can :use, feature.slug.to_sym
|
49
|
-
end
|
50
|
-
else
|
51
|
-
raise(:unknown_feature_type.l)
|
52
|
-
end
|
9
|
+
PaidUp::Feature.all.each do |feature|
|
10
|
+
method = "enable_#{feature.setting_type}".to_sym
|
11
|
+
send(method, user, feature)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def enable_read(model)
|
18
|
+
can :index, model
|
19
|
+
can :show, model, &:enabled?
|
20
|
+
end
|
21
|
+
|
22
|
+
def enable_rows(model, allowed, remaining)
|
23
|
+
if allowed.positive?
|
24
|
+
can :own, model
|
25
|
+
cannot :create, model
|
26
|
+
can(%i(create new), model) if remaining.positive?
|
27
|
+
else
|
28
|
+
cannot %i(delete update own create), model
|
53
29
|
end
|
54
30
|
end
|
31
|
+
|
32
|
+
def enable_table_rows(user, feature)
|
33
|
+
model = feature.feature_model
|
34
|
+
enable_read(model)
|
35
|
+
return if user.new_record?
|
36
|
+
slug = feature.slug
|
37
|
+
table_setting = user.table_setting(slug)
|
38
|
+
allowed = table_setting.rows_allowed
|
39
|
+
remaining = table_setting.rows_remaining
|
40
|
+
can :manage, model, user: user if allowed.positive?
|
41
|
+
enable_rows(model, allowed, remaining)
|
42
|
+
end
|
43
|
+
|
44
|
+
def enable_rolify_rows(user, feature)
|
45
|
+
model = feature.feature_model
|
46
|
+
enable_read(model)
|
47
|
+
return if user.new_record?
|
48
|
+
slug = feature.slug
|
49
|
+
rolify_setting = user.rolify_setting(slug)
|
50
|
+
allowed = rolify_setting.rows_allowed
|
51
|
+
remaining = rolify_setting.rows_remaining
|
52
|
+
if allowed.positive?
|
53
|
+
can :manage, model, id: model.with_role(:owner, user).ids
|
54
|
+
end
|
55
|
+
enable_rows(model, allowed, remaining)
|
56
|
+
end
|
57
|
+
|
58
|
+
def enable_boolean(user, feature)
|
59
|
+
slug = feature.slug
|
60
|
+
can :use, slug.to_sym if user.plan.feature_setting slug
|
61
|
+
end
|
55
62
|
end
|
56
63
|
end
|
data/app/models/paid_up/plan.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PaidUp
|
2
4
|
# PaidUp Plan model
|
3
5
|
class Plan < ActiveRecord::Base
|
@@ -19,9 +21,17 @@ module PaidUp
|
|
19
21
|
|
20
22
|
default_scope { order('sort_order ASC') }
|
21
23
|
scope :subscribable, -> { where('sort_order >= ?', 0) }
|
24
|
+
scope :within, ->(ids) { where(id: ids) }
|
25
|
+
scope :without, ->(ids) { where.not(id: ids) }
|
22
26
|
scope :free, (lambda do
|
23
27
|
find_by_stripe_id(PaidUp.configuration.free_plan_stripe_id)
|
24
28
|
end)
|
29
|
+
scope :display, (lambda do |within, without|
|
30
|
+
plans = subscribable
|
31
|
+
plans = plans.within(within) if within.present?
|
32
|
+
plans = plans.without(without) if without.present?
|
33
|
+
plans
|
34
|
+
end)
|
25
35
|
|
26
36
|
def reload(*args, &blk)
|
27
37
|
super(*args, &blk)
|
@@ -30,22 +40,13 @@ module PaidUp
|
|
30
40
|
end
|
31
41
|
|
32
42
|
def feature_setting(feature_name)
|
33
|
-
feature = PaidUp::Feature.find_by_slug(feature_name)
|
34
|
-
raise(:feature_not_found.l)
|
43
|
+
feature = PaidUp::Feature.find_by_slug!(feature_name)
|
35
44
|
raw = plan_feature_settings.where(feature: feature_name)
|
36
45
|
case feature.setting_type
|
37
46
|
when 'boolean'
|
38
|
-
|
39
|
-
false
|
40
|
-
else
|
41
|
-
raw.first.setting != 0
|
42
|
-
end
|
47
|
+
raw&.first&.setting == 1
|
43
48
|
when 'table_rows', 'rolify_rows'
|
44
|
-
|
45
|
-
0
|
46
|
-
else
|
47
|
-
raw.first.setting
|
48
|
-
end
|
49
|
+
raw&.first&.setting || 0
|
49
50
|
else
|
50
51
|
raise :error_handling_feature_setting.l feature: feature
|
51
52
|
end
|
@@ -56,33 +57,37 @@ module PaidUp
|
|
56
57
|
end
|
57
58
|
|
58
59
|
def interval
|
59
|
-
|
60
|
-
stripe_data.interval
|
61
|
-
else
|
62
|
-
:default_interval.l
|
63
|
-
end
|
60
|
+
stripe_data&.interval || :default_interval.l
|
64
61
|
end
|
65
62
|
|
66
63
|
def interval_count
|
67
|
-
|
68
|
-
stripe_data.interval_count
|
69
|
-
else
|
70
|
-
1
|
71
|
-
end
|
64
|
+
stripe_data&.interval_count || 1
|
72
65
|
end
|
73
66
|
|
74
67
|
def amount
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
68
|
+
stripe_data&.amount || 0
|
69
|
+
end
|
70
|
+
|
71
|
+
def adjusted_amount(discount)
|
72
|
+
return amount unless adjust?(discount)
|
73
|
+
adjusted = amount
|
74
|
+
adjusted -= (discount.coupon.percent_off || 0) * 0.01 * adjusted
|
75
|
+
adjusted -= (discount.coupon.amount_off || 0)
|
76
|
+
[adjusted, 0].max
|
80
77
|
end
|
81
78
|
|
82
79
|
def money
|
83
80
|
Money.new(amount, currency)
|
84
81
|
end
|
85
82
|
|
83
|
+
def adjusted_money(discount)
|
84
|
+
Money.new(adjusted_amount(discount), currency)
|
85
|
+
end
|
86
|
+
|
87
|
+
def adjust?(discount)
|
88
|
+
discount.present? && discount.coupon.present? && !amount.zero?
|
89
|
+
end
|
90
|
+
|
86
91
|
def charge
|
87
92
|
money.amount
|
88
93
|
end
|
@@ -98,13 +103,10 @@ module PaidUp
|
|
98
103
|
private
|
99
104
|
|
100
105
|
def load_stripe_data
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
Stripe::Plan.retrieve stripe_id
|
106
|
-
end
|
107
|
-
end
|
106
|
+
return unless stripe_id.present?
|
107
|
+
self.stripe_data = Rails.cache.fetch(
|
108
|
+
"#{stripe_id}/stripe_data", expires_in: 1.minute
|
109
|
+
) { Stripe::Plan.retrieve stripe_id }
|
108
110
|
end
|
109
111
|
|
110
112
|
def expire_stripe_data
|
@@ -2,48 +2,4 @@
|
|
2
2
|
- for feature in features
|
3
3
|
%tr{ id: feature.slug + '_ability'}
|
4
4
|
%th= feature.title
|
5
|
-
%td
|
6
|
-
- case feature.setting_type
|
7
|
-
- when 'boolean'
|
8
|
-
- if can? :use, feature.slug.to_sym
|
9
|
-
= icon 'ok'
|
10
|
-
= :allowed.l
|
11
|
-
- else
|
12
|
-
= icon 'remove'
|
13
|
-
= :not_allowed.l
|
14
|
-
- when 'table_rows'
|
15
|
-
- if can? :own, feature.feature_model
|
16
|
-
= icon 'ok'
|
17
|
-
- else
|
18
|
-
= icon 'remove'
|
19
|
-
- if current_user.table_rows_unlimited?(feature.slug)
|
20
|
-
= :unlimited.l
|
21
|
-
- else
|
22
|
-
- remaining = current_user.table_rows_remaining(feature.slug)
|
23
|
-
- allowed = current_user.table_rows_allowed(feature.slug)
|
24
|
-
- used = current_user.table_rows(feature.slug)
|
25
|
-
- if remaining < 0
|
26
|
-
= :x_used_y_allowed.l x: used, y: allowed
|
27
|
-
- elsif allowed == 0
|
28
|
-
= :not_allowed.l
|
29
|
-
- else
|
30
|
-
= :x_of_y_remaining.l x: remaining, y: allowed
|
31
|
-
- when 'rolify_rows'
|
32
|
-
- if can? :own, feature.feature_model
|
33
|
-
= icon 'ok'
|
34
|
-
- else
|
35
|
-
= icon 'remove'
|
36
|
-
- if current_user.rolify_rows_unlimited?(feature.slug)
|
37
|
-
= :unlimited.l
|
38
|
-
- else
|
39
|
-
- remaining = current_user.rolify_rows_remaining(feature.slug)
|
40
|
-
- allowed = current_user.rolify_rows_allowed(feature.slug)
|
41
|
-
- used = current_user.rolify_rows(feature.slug)
|
42
|
-
- if remaining < 0
|
43
|
-
= :x_used_y_allowed.l x: used, y: allowed
|
44
|
-
- elsif allowed == 0
|
45
|
-
= :not_allowed.l
|
46
|
-
- else
|
47
|
-
= :x_of_y_remaining.l x: remaining, y: allowed
|
48
|
-
- else
|
49
|
-
= :error.l
|
5
|
+
%td= feature_state(feature)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
- if can? :own, model
|
2
|
+
= icon 'ok'
|
3
|
+
- else
|
4
|
+
= icon 'remove'
|
5
|
+
|
6
|
+
- if unlimited
|
7
|
+
= :unlimited.l
|
8
|
+
- if remaining.negative?
|
9
|
+
= :x_used_y_allowed.l x: used, y: allowed
|
10
|
+
- elsif allowed.zero?
|
11
|
+
= :not_allowed.l
|
12
|
+
- else
|
13
|
+
= :x_of_y_remaining.l x: remaining, y: allowed
|
@@ -10,8 +10,8 @@
|
|
10
10
|
%h2
|
11
11
|
= current_user.plan.title
|
12
12
|
.small= plan_charge_human current_user.plan, current_user.stripe_data.discount
|
13
|
-
= subscription_dl current_user.
|
14
|
-
- if current_user.
|
13
|
+
= subscription_dl current_user.paid_up_subscription
|
14
|
+
- if current_user.paid_up_subscription.cancel_at_period_end
|
15
15
|
%h3= :canceled.l
|
16
16
|
%h3= :abilities.l
|
17
17
|
= feature_abilities_table
|
data/config/locales/en.yml
CHANGED
@@ -38,7 +38,10 @@ en:
|
|
38
38
|
could_not_associate_subscription: 'Could not associate subscription'
|
39
39
|
could_not_create_subscription: 'Could not create subscription'
|
40
40
|
could_not_subscribe_to_plan: "Could not subscribe to %{plan}"
|
41
|
-
|
41
|
+
could_not_update_cancel: 'Could not update to reflect cancel'
|
42
|
+
could_not_update_card: 'Could not update card'
|
43
|
+
could_not_update_coupon: 'Could not update coupon'
|
44
|
+
could_not_update_subscription: 'Could not update plan'
|
42
45
|
coupon_code: 'Coupon Code'
|
43
46
|
currently_awaiting_confirmation_for_resource: "Currently awaiting confirmation for %{resource}"
|
44
47
|
cvc: 'CVC/CVV'
|
data/config/routes.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PaidUp
|
2
4
|
# PaidUp Install Generator
|
3
5
|
class InstallGenerator < Rails::Generators::Base
|
@@ -16,7 +18,8 @@ module PaidUp
|
|
16
18
|
def install_devise
|
17
19
|
output(
|
18
20
|
'To start with, Devise is used to authenticate users. No need to '\
|
19
|
-
"install it separately, I'll do that now.", :magenta
|
21
|
+
"install it separately, I'll do that now.", :magenta
|
22
|
+
)
|
20
23
|
generate('devise:install')
|
21
24
|
generate('devise User')
|
22
25
|
end
|
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# PaidUp Module
|
2
4
|
module PaidUp
|
3
5
|
def self.configure(configuration = PaidUp::Configuration.new)
|
4
6
|
block_given? && yield(configuration)
|
5
|
-
|
7
|
+
@configuration = configuration
|
6
8
|
end
|
7
9
|
|
8
10
|
def self.configuration
|
9
|
-
|
11
|
+
@configuration ||= PaidUp::Configuration.new
|
10
12
|
end
|
11
13
|
|
12
14
|
# PaidUp Configuration
|
data/lib/paid_up/engine.rb
CHANGED