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.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +17 -13
  3. data/.rubocop_todo.yml +7 -0
  4. data/.travis.yml +4 -3
  5. data/Gemfile +29 -24
  6. data/README.md +22 -1
  7. data/Rakefile +6 -5
  8. data/VERSION +1 -1
  9. data/app/controllers/paid_up/paid_up_controller.rb +16 -9
  10. data/app/controllers/paid_up/plans_controller.rb +2 -0
  11. data/app/controllers/paid_up/subscriptions_controller.rb +58 -49
  12. data/app/helpers/paid_up/features_helper.rb +35 -34
  13. data/app/helpers/paid_up/paid_up_helper.rb +10 -8
  14. data/app/helpers/paid_up/plans_helper.rb +75 -55
  15. data/app/helpers/paid_up/subscriptions_helper.rb +17 -13
  16. data/app/models/paid_up/ability.rb +53 -46
  17. data/app/models/paid_up/plan.rb +36 -34
  18. data/app/models/paid_up/plan_feature_setting.rb +2 -0
  19. data/app/models/paid_up/unlimited.rb +2 -0
  20. data/app/views/paid_up/features/_abilities_table.html.haml +1 -45
  21. data/app/views/paid_up/features/_boolean_state.html.haml +6 -0
  22. data/app/views/paid_up/features/_setting_state.html.haml +13 -0
  23. data/app/views/paid_up/subscriptions/index.html.haml +2 -2
  24. data/config/initializers/stripe.rb +2 -0
  25. data/config/locales/en.yml +4 -1
  26. data/config/routes.rb +3 -1
  27. data/lib/generators/paid_up/install/install_generator.rb +4 -1
  28. data/lib/generators/paid_up/install/templates/ability.rb +2 -0
  29. data/lib/generators/paid_up/install/templates/initializer.rb +2 -0
  30. data/lib/generators/paid_up/utils.rb +2 -0
  31. data/lib/paid_up/configuration.rb +4 -2
  32. data/lib/paid_up/engine.rb +2 -0
  33. data/lib/paid_up/extensions/integer.rb +2 -0
  34. data/lib/paid_up/extensions/stripe.rb +2 -0
  35. data/lib/paid_up/feature.rb +10 -7
  36. data/lib/paid_up/feature_setting_type.rb +45 -0
  37. data/lib/paid_up/feature_setting_types/rolify.rb +10 -0
  38. data/lib/paid_up/feature_setting_types/table.rb +7 -0
  39. data/lib/paid_up/localization.rb +2 -0
  40. data/lib/paid_up/mixins/paid_for.rb +59 -47
  41. data/lib/paid_up/mixins/subscriber.rb +45 -101
  42. data/lib/paid_up/railtie.rb +2 -0
  43. data/lib/paid_up/ruby_version_check.rb +15 -0
  44. data/lib/paid_up/subscription.rb +80 -0
  45. data/lib/paid_up/validators/rolify_rows.rb +11 -6
  46. data/lib/paid_up/validators/table_rows.rb +9 -6
  47. data/lib/paid_up/version.rb +2 -0
  48. data/lib/paid_up.rb +8 -0
  49. data/paid_up.gemspec +108 -115
  50. data/spec/controllers/paid_up/plans_spec.rb +2 -0
  51. data/spec/controllers/paid_up/subscriptions_spec.rb +18 -11
  52. data/spec/dummy/Rakefile +2 -0
  53. data/spec/dummy/app/assets/stylesheets/application.css.scss +6 -0
  54. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  55. data/spec/dummy/app/models/ability.rb +2 -0
  56. data/spec/dummy/app/models/doodad.rb +2 -0
  57. data/spec/dummy/app/models/group.rb +2 -0
  58. data/spec/dummy/app/models/post.rb +2 -0
  59. data/spec/dummy/app/models/role.rb +2 -0
  60. data/spec/dummy/app/models/user.rb +2 -0
  61. data/spec/dummy/app/views/layouts/application.html.haml +13 -11
  62. data/spec/dummy/bin/bundle +2 -0
  63. data/spec/dummy/bin/rails +2 -0
  64. data/spec/dummy/bin/rake +2 -0
  65. data/spec/dummy/bin/setup +10 -8
  66. data/spec/dummy/config/application.rb +2 -3
  67. data/spec/dummy/config/boot.rb +2 -0
  68. data/spec/dummy/config/environment.rb +2 -0
  69. data/spec/dummy/config/environments/development.rb +2 -0
  70. data/spec/dummy/config/environments/test.rb +2 -4
  71. data/spec/dummy/config/initializers/assets.rb +2 -0
  72. data/spec/dummy/config/initializers/backtrace_silencers.rb +1 -0
  73. data/spec/dummy/config/initializers/cookies_serializer.rb +2 -0
  74. data/spec/dummy/config/initializers/devise.rb +2 -0
  75. data/spec/dummy/config/initializers/filter_parameter_logging.rb +2 -0
  76. data/spec/dummy/config/initializers/inflections.rb +1 -0
  77. data/spec/dummy/config/initializers/mime_types.rb +1 -0
  78. data/spec/dummy/config/initializers/paid_up.rb +10 -16
  79. data/spec/dummy/config/initializers/rolify.rb +2 -0
  80. data/spec/dummy/config/initializers/session_store.rb +2 -0
  81. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
  82. data/spec/dummy/config/routes.rb +2 -0
  83. data/spec/dummy/config.ru +2 -0
  84. data/spec/dummy/db/schema.rb +14 -23
  85. data/spec/dummy/db/seeds.rb +8 -6
  86. data/spec/dummy/db/test.sqlite3 +0 -0
  87. data/spec/dummy/lib/tasks/system.rake +2 -0
  88. data/spec/factories/doodad.rb +2 -0
  89. data/spec/factories/group.rb +2 -0
  90. data/spec/factories/plan.rb +2 -0
  91. data/spec/factories/plan_feature_setting.rb +2 -0
  92. data/spec/factories/post.rb +2 -0
  93. data/spec/factories/user.rb +3 -1
  94. data/spec/models/group_spec.rb +9 -7
  95. data/spec/models/paid_up/feature_spec.rb +2 -0
  96. data/spec/models/paid_up/plan_feature_setting_spec.rb +2 -0
  97. data/spec/models/paid_up/plan_spec.rb +2 -0
  98. data/spec/models/scope_spec.rb +9 -7
  99. data/spec/models/user_spec.rb +60 -58
  100. data/spec/paid_up_spec.rb +2 -0
  101. data/spec/rails_helper.rb +16 -2
  102. data/spec/routing/paid_up/plans_spec.rb +2 -0
  103. data/spec/routing/paid_up/subscription_spec.rb +2 -0
  104. data/spec/spec_helper.rb +2 -0
  105. data/spec/support/controller_macros.rb +2 -0
  106. data/spec/support/factory_girl.rb +2 -0
  107. data/spec/support/loaded_site/features.rb +2 -0
  108. data/spec/support/loaded_site/groups.rb +2 -0
  109. data/spec/support/loaded_site/loaded_site.rb +2 -0
  110. data/spec/support/loaded_site/plans.rb +2 -0
  111. data/spec/support/loaded_site/posts.rb +2 -0
  112. data/spec/support/loaded_site/users.rb +4 -2
  113. data/spec/support/stripe.rb +2 -0
  114. data/spec/views/paid_up/plans_spec.rb +9 -7
  115. data/spec/views/paid_up/subscriptions_spec.rb +20 -19
  116. metadata +124 -90
  117. data/app/views/devise/confirmations/new.html.haml +0 -13
  118. data/app/views/devise/passwords/edit.html.haml +0 -19
  119. data/app/views/devise/passwords/new.html.haml +0 -14
  120. data/app/views/devise/registrations/_new_form.html.haml +0 -23
  121. data/app/views/devise/registrations/edit.html.haml +0 -39
  122. data/app/views/devise/registrations/new.html.haml +0 -11
  123. data/app/views/devise/sessions/_new_form.html.haml +0 -21
  124. data/app/views/devise/sessions/new.html.haml +0 -11
  125. data/app/views/devise/shared/_links.html.haml +0 -14
  126. data/app/views/devise/unlocks/new.html.haml +0 -14
  127. data/app/views/layouts/mailer.html.haml +0 -3
  128. data/app/views/layouts/mailer.text.haml +0 -1
  129. data/app/views/paid_up/subscription_mailer/payment_failed_email.html.haml +0 -0
  130. data/app/views/paid_up/subscription_mailer/payment_failed_email.text.haml +0 -0
  131. data/coverage/.last_run.json +0 -5
  132. data/coverage/.resultset.json +0 -1927
  133. data/spec/dummy/app/views/pages/index.html.haml +0 -1
  134. data/spec/dummy/config/environments/production.rb +0 -83
  135. 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
- if !discount.nil? && !discount.coupon.nil? && plan.amount != 0
8
- orig_amount = plan.amount
9
- amount = orig_amount
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
- html
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
- def plan_button(plan, text = nil, html_options = {})
43
- data = {}
44
- css_class = ''
45
- link = paid_up.new_plan_subscription_path(plan)
46
- if user_signed_in?
47
- text ||= :subscribe.l
48
- if current_user.stripe_data.delinquent
49
- icon_class = 'arrow-right'
50
- css_class += 'info'
51
- elsif current_user.can_upgrade_to? plan
52
- icon_class = 'arrow-up'
53
- css_class += 'success'
54
- elsif current_user.can_downgrade_to? plan
55
- icon_class = 'arrow-down'
56
- css_class += 'danger'
57
- data[:confirm] = :are_you_sure.l
58
- elsif current_user.is_subscribed_to? plan
59
- icon_class = 'ok'
60
- css_class += 'disabled disabled'
61
- link = '#'
62
- text = :already_subscribed.l
63
- else # Plans are equal in sort_order
64
- icon_class = 'arrow-right'
65
- css_class += 'info'
66
- end
67
- else
68
- text ||= :sign_up.l
69
- icon_class = 'arrow-right'
70
- css_class += 'success'
71
- end
72
- html_options[:method] ||= :get
73
- icon_button_to css_class, icon_class, text, link, html_options
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
- if subscription.current_period_start || subscription.current_period_end
12
- data[:paid_thru.l] = date_range(
13
- subscription.current_period_start,
14
- subscription.current_period_end
15
- )
16
- end
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
- if subscription.trial_start || subscription.trial_end
19
- data[:trial_period.l] = date_range(
20
- subscription.trial_start,
21
- subscription.trial_end
22
- )
23
- end
23
+ private
24
24
 
25
- dl data
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
- features = PaidUp::Feature.all
8
- features.each do |feature|
9
- case feature.setting_type
10
- when 'table_rows'
11
- can :index, feature.feature_model
12
- can :show, feature.feature_model, &:enabled
13
- if user.table_rows_allowed(feature.slug) > 0 ||
14
- user.table_rows_unlimited?(feature.slug)
15
- can :manage, feature.feature_model, user: user
16
- can :own, feature.feature_model
17
- cannot :create, feature.feature_model
18
- user.table_rows_remaining(feature.slug) > 0 &&
19
- can([:create, :new], feature.feature_model)
20
- else
21
- cannot :delete, feature.feature_model
22
- cannot :update, feature.feature_model
23
- cannot :own, feature.feature_model
24
- cannot :create, feature.feature_model
25
- end
26
- when 'rolify_rows'
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
@@ -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
- if raw.empty?
39
- false
40
- else
41
- raw.first.setting != 0
42
- end
47
+ raw&.first&.setting == 1
43
48
  when 'table_rows', 'rolify_rows'
44
- if raw.empty?
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
- if stripe_data.present?
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
- if stripe_data.present?
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
- if stripe_data.present?
76
- stripe_data.amount
77
- else
78
- 0
79
- end
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
- if stripe_id.present?
102
- self.stripe_data = Rails.cache.fetch(
103
- "#{stripe_id}/stripe_data", expires_in: 1.second
104
- ) do
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PaidUp
2
4
  # Plan-FeatureSetting Relationship
3
5
  class PlanFeatureSetting < ActiveRecord::Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PaidUp
2
4
  # Unlimited class: designed to output as 'Unlimited' for string, -1 for db,
3
5
  # or 999999999 for number.
@@ -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,6 @@
1
+ - if can? :use, feature.slug.to_sym
2
+ = icon 'ok'
3
+ = :allowed.l
4
+ - else
5
+ = icon 'remove'
6
+ = :not_allowed.l
@@ -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.subscription
14
- - if current_user.subscription.cancel_at_period_end
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Rails.configuration.stripe = {
2
4
  publishable_key: ENV['STRIPE_PUBLISHABLE_KEY'],
3
5
  secret_key: ENV['STRIPE_SECRET_KEY']
@@ -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
- could_not_update_subscription: 'Could not update subscription'
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,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  PaidUp::Engine.routes.draw do
2
4
  resources :plans, only: :index do
3
- resources :subscriptions, only: [:new, :create]
5
+ resources :subscriptions, only: %i(new create)
4
6
  end
5
7
 
6
8
  resources :subscriptions, only: [:index]
@@ -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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # CanCanCan Ability class
2
4
  class Ability
3
5
  include CanCan::Ability
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  PaidUp.configure do |config|
2
4
  config.anonymous_customer_stripe_id = 'anonymous-customer'
3
5
  config.anonymous_plan_stripe_id = 'anonymous-plan'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PaidUp
2
4
  module Generators
3
5
  # Generator Utilities
@@ -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
- @@configuration = configuration
7
+ @configuration = configuration
6
8
  end
7
9
 
8
10
  def self.configuration
9
- @@configuration ||= PaidUp::Configuration.new
11
+ @configuration ||= PaidUp::Configuration.new
10
12
  end
11
13
 
12
14
  # PaidUp Configuration
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PaidUp
2
4
  # PaidUp Engine
3
5
  class Engine < Rails::Engine
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PaidUp
2
4
  module Extensions
3
5
  # Integer extensions
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PaidUp
2
4
  module Extensions
3
5
  # Stripe Extensions