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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 15d045e897fa830551be519557e9ea72bc586d86
4
- data.tar.gz: 2fc056d3ef1cf75b97759506b30359dc58236768
3
+ metadata.gz: 7c1ccc499e297cd644e9ccc070f7f6119fb5a2b1
4
+ data.tar.gz: 6034b27662459169830dc94407dea76f8041df25
5
5
  SHA512:
6
- metadata.gz: a4380cb08afb3191361ae4c6eb69361f26a6886858b50b0f55194933ddf5637f0c79281093f37660e21776ce7477cf13f6e4d81771b89f33d631a5bef4c6fff6
7
- data.tar.gz: 9e054bbb52211b2f8a3409304c97798fd7f48f09c0d3b38eb553696fdcf69750ef1f5a2fad690abbd4b19a81ae4ec187882b3f68e9d6d7e991953eb7b801809f
6
+ metadata.gz: 8f8d9e47d52c69a1592fba66075862f2b4e670b19dab0110bed23e398e77f6f18f1aef33c36dc16813fee79a82ba8375f2d3d0e8413378aa01acc0bd13db2aca
7
+ data.tar.gz: 4f77687abf07baf11e5db79e1d1af7b9d9e0fff697ab0138787938b3349f4bcd39de07ceae18f6ed9cb90e1ad98ec00b8d4f94e5d7d7294fb5be4841e15fa9c7
data/.rubocop.yml CHANGED
@@ -1,20 +1,24 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
1
3
  AllCops:
4
+ TargetRubyVersion: 2.3
5
+ DisplayCopNames: true
2
6
  Exclude:
3
7
  - paid_up.gemspec
4
8
  - db/migrate/*
5
9
  - spec/dummy/db/schema.rb
6
10
  - spec/dummy/db/migrate/*
7
- Style/ClassVars:
8
- Enabled: false
9
- Metrics/AbcSize:
10
- Enabled: false
11
- Metrics/ClassLength:
12
- Enabled: false
13
- Metrics/CyclomaticComplexity:
14
- Enabled: false
15
- Metrics/MethodLength:
16
- Enabled: false
11
+
12
+ Metrics/BlockLength:
13
+ Exclude:
14
+ - spec/*
15
+ - spec/*/*
16
+ - spec/*/*/*
17
+ - spec/dummy/db/seeds/*
18
+
17
19
  Metrics/ModuleLength:
18
- Enabled: false
19
- Metrics/PerceivedComplexity:
20
- Enabled: false
20
+ Exclude:
21
+ - spec/*
22
+ - spec/*/*
23
+ - spec/*/*/*
24
+
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,7 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2017-03-29 15:07:04 -0600 using RuboCop version 0.48.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
data/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.2
4
- - 2.2.3
5
- - 2.3.0
3
+ - 2.3.0
4
+ - 2.3.1
5
+ - 2.4.0
6
+ - 2.4.1
data/Gemfile CHANGED
@@ -1,48 +1,53 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
- gem 'dotenv-rails', '~> 2.2', require: 'dotenv/rails-now', groups: [:development, :test]
5
+ group :test, :development do
6
+ gem 'dotenv-rails', '~> 2.2', require: 'dotenv/rails-now'
7
+ end
4
8
 
5
- gem 'rails', '~> 4.2'
6
- gem 'rails-i18n', '~> 4'
7
9
  gem 'haml-rails', '~> 0.9'
8
10
  gem 'jquery-rails', '~> 4'
9
- gem 'uglifier', '~> 2.7'
11
+ gem 'rails', '>= 4', '< 6'
12
+ gem 'rails-i18n', '>= 4', '< 6'
13
+ gem 'uglifier', '>= 2.7', '< 4'
10
14
 
11
- gem 'bootstrap_leather', '~> 0.5'
15
+ gem 'bootstrap_leather', '~> 0.9'
12
16
 
13
17
  gem 'chronic', '~> 0.10'
14
18
  gem 'money', '~> 6.5'
15
19
 
16
- gem 'devise', '~> 3.4'
17
- gem 'cancancan', '~> 1.10'
20
+ gem 'cancancan', '~> 1'
21
+ gem 'devise', '>= 3.4', '< 5'
18
22
  gem 'rolify', '~> 5'
19
- gem 'stripe', '~> 1.36'
23
+ gem 'stripe', '>= 1.36', '< 3'
20
24
 
21
25
  group :development do
22
- gem 'jeweler', '~> 2'
23
26
  gem 'bundler', '~> 1'
24
- gem 'web-console', '~> 3.0'
25
- gem 'pre-commit', '~> 0.27'
26
- gem 'rubocop', '~> 0.37'
27
27
  gem 'coffeelint', '~> 1.14'
28
- gem 'scss_lint', '~> 0.47.0', require: false
28
+ gem 'juwelier', '~> 2'
29
+ gem 'nokogiri', '>= 1.7'
30
+ gem 'pre-commit', '~> 0.32'
31
+ gem 'rubocop', git: 'https://github.com/bbatsov/rubocop.git' # Wait for 0.49
32
+ gem 'scss_lint', '~> 0.52.0', require: false
33
+ gem 'web-console', '~> 3'
29
34
  end
30
35
 
31
36
  group :test, :development do
32
- gem 'sqlite3', '~> 1.3'
33
- gem 'forgery', '~> 0.6'
34
- gem 'bootstrap-sass', '~> 3.3'
35
- gem 'sass-rails', '~> 5.0'
36
- gem 'high_voltage', '~> 2.3'
37
- gem 'rspec-rails', '~> 3.2'
37
+ gem 'bootstrap-sass', '~> 3'
38
38
  gem 'factory_girl_rails', '~> 4.5'
39
+ gem 'forgery', '~> 0.6'
40
+ gem 'rails-controller-testing', '~> 1'
41
+ gem 'rspec-rails', '~> 3'
42
+ gem 'sass-rails', '~> 5'
43
+ gem 'sqlite3', '~> 1.3'
39
44
  end
40
45
 
41
46
  group :test do
42
- gem 'capybara', '~> 2.4'
43
- gem 'database_cleaner', '~> 1.4'
44
- gem 'rspec-collection_matchers', '~> 1.1'
45
- gem 'shoulda-matchers', '~> 2.8'
47
+ gem 'capybara', '~> 2'
48
+ gem 'coveralls', '>= 0.8', '< 2', require: false
49
+ gem 'database_cleaner', '~> 1'
46
50
  gem 'launchy', '~> 2.4', require: false
47
- gem 'coveralls', '~> 0.8', require: false
51
+ gem 'rspec-collection_matchers', '~> 1.1'
52
+ gem 'shoulda-matchers', '>=2', '< 4'
48
53
  end
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  Paid Up is a start-to-finish Stripe subscription engine. You set up the plans and coupons you want on Stripe, and the gem gives you a way to tie those plans and coupons to authenticated users, granting them abilities based on the features outlined for their plan.
8
8
 
9
- * Ruby 2, Rails 4
9
+ * Ruby 2, Rails 4 and 5
10
10
  * Authentication by Devise
11
11
  * Authorization by CanCanCan
12
12
  * Subscription by Stripe
@@ -14,6 +14,12 @@ Paid Up is a start-to-finish Stripe subscription engine. You set up the plans an
14
14
  * Uses Google Tag Manager for Google Analytics `dataLayer` object to provide e-commerce analytics.
15
15
  * Assumes you will be using some variety of Bootstrap, and designed to be quite responsive out of the box. Included views can be overridden with custom views.
16
16
 
17
+ ### Plans Index Page
18
+ ![Plans Index Page Screenshot](http://gemvein.com/assets/screenshots/paid_up-plans-index.png)
19
+
20
+ ### New Subscription Page
21
+ ![New Subscription Page Screenshot](http://gemvein.com/assets/screenshots/paid_up-subscriptions-new.png)
22
+
17
23
  ## Installation
18
24
 
19
25
  First, add paid_up to your `Gemfile`:
@@ -128,6 +134,21 @@ Doing this will populate the e-commerce data in Google Analytics, but you must a
128
134
 
129
135
  ### Upgrading
130
136
 
137
+ #### Version 0.12.1
138
+ Renamed `subscription` to `paid_up_subscription` and `subscriptions` to `paid_up_subscriptions` to avoid naming conflicts with other gems.
139
+
140
+ #### Version 0.12.0
141
+
142
+ Version 0.12.0 requires Ruby 2.3 or higher because of the use of the `&.` operator.
143
+
144
+ ##### paid_for Mixin
145
+
146
+ The methods `table_rows` and `rolify_rows` were renamed to `table_setting(table_name).rows_count` and `rolify_setting(table_name).rows_count`, replaced by methods that fetch the rows themselves.
147
+
148
+ All previous methods beginning with `table_rows_` and `rolify_rows_` have also been moved into `table_setting()` and `rolify_setting()`
149
+
150
+ The method `enabled` was renamed to `enabled?`.
151
+
131
152
  #### Version 0.9.0
132
153
 
133
154
  Version 0.9.0 enabled coupon codes, which are saved on the user's record. Be sure to run `rake paid_up:install:migrations` and migrate your database after upgrading.
data/Rakefile CHANGED
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require 'bundler/setup'
3
5
  rescue LoadError
4
6
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
7
  end
6
8
 
7
- require 'jeweler'
8
- Jeweler::Tasks.new do |gem|
9
+ require 'juwelier'
10
+ Juwelier::Tasks.new do |gem|
9
11
  # gem is a Gem::Specification...
10
- # see http://docs.rubygems.org/read/chapter/20 for more options
12
+ # see http://guides.rubygems.org/specification-reference/ for more options
11
13
  gem.name = 'paid_up'
12
14
  gem.homepage = 'http://www.gemvein.com/museum/cases/paid_up'
13
15
  gem.license = 'MIT'
@@ -17,9 +19,8 @@ Jeweler::Tasks.new do |gem|
17
19
  'subscribe to a plan, which enables features.'
18
20
  gem.email = 'karen.e.lundgren@gmail.com'
19
21
  gem.authors = ['Karen Lundgren']
20
- # dependencies defined in Gemfile
21
22
  end
22
- Jeweler::RubygemsDotOrgTasks.new
23
+ Juwelier::RubygemsDotOrgTasks.new
23
24
 
24
25
  require 'rspec/core'
25
26
  require 'rspec/core/rake_task'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.11.7
1
+ 0.12.3
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PaidUp
2
4
  # PaidUp Controller
3
5
  class PaidUpController < ApplicationController
4
6
  helper :all
5
7
 
6
8
  before_action :set_locale
7
- before_filter :warn_if_delinquent
9
+ before_action :warn_if_delinquent
8
10
 
9
11
  private
10
12
 
@@ -13,14 +15,19 @@ module PaidUp
13
15
  end
14
16
 
15
17
  def warn_if_delinquent
16
- if user_signed_in? && params[:controller] != 'paid_up/subscriptions'
17
- if current_user.plan.nil? || current_user.stripe_data.delinquent
18
- flash[:error] = :account_is_delinquent.l +
19
- :to_disable_this_message_subscribe.l(
20
- subscribe_link: paid_up.plans_path
21
- )
22
- end
23
- end
18
+ return unless delinquent? &&
19
+ params[:controller] != 'paid_up/subscriptions'
20
+ flash[:error] = :account_is_delinquent.l +
21
+ :to_disable_this_message_subscribe.l(
22
+ subscribe_link: paid_up.plans_path
23
+ )
24
+ end
25
+
26
+ def delinquent?
27
+ user_signed_in? && (
28
+ current_user.plan.nil? ||
29
+ current_user.stripe_data.delinquent
30
+ )
24
31
  end
25
32
  end
26
33
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PaidUp
2
4
  # PaidUp Plans Controller
3
5
  class PlansController < PaidUpController
@@ -1,73 +1,82 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PaidUp
2
4
  # Subscriptions Controller
3
5
  class SubscriptionsController < PaidUpController
4
- before_filter :authenticate_user!
5
- before_filter :set_plan, only: [:new, :create]
6
+ before_action :authenticate_user!
7
+ before_action :load_plan, only: %i(new create)
8
+
9
+ rescue_from Stripe::InvalidRequestError do |error|
10
+ invalid_request_error(error)
11
+ end
12
+ rescue_from Stripe::CardError do |error|
13
+ invalid_card_error(error)
14
+ end
6
15
 
7
16
  def index
8
17
  # nothing to do, everything we need is in current_user
9
18
  end
10
19
 
11
20
  def new
12
- # nothing to do, @plan set by #set_plan
13
- (current_user.can_downgrade_to?(@plan) || @plan.amount == 0) && create
21
+ # nothing to do, @plan load by #load_plan
22
+ (current_user.can_downgrade_to?(@plan) || @plan.amount.zero?) && create
14
23
  end
15
24
 
16
25
  def create
17
- # @plan set by #set_plan
18
- current_user.update_attribute(:coupon_code, params[:coupon_code])
19
- if current_user.subscribe_to_plan(@plan, params[:stripeToken])
20
- subscription_id = current_user.stripe_data.subscriptions.first.id
21
- discount = current_user.stripe_data.discount
22
- if !discount.nil? && !discount.coupon.nil? && @plan.amount != 0
23
- orig_amount = @plan.amount
24
- amount = orig_amount
25
- amount -= (discount.coupon.percent_off || 0) * 0.01 * amount
26
- amount -= (discount.coupon.amount_off || 0)
27
- amount = amount > 0 ? amount : 0
28
- money = Money.new(amount, @plan.currency)
29
- else
30
- money = @plan.money
31
- end
32
- flash[:paid_up_google_analytics_data] = {
33
- transactionId: subscription_id,
34
- transactionTotal: money.dollars,
35
- transactionProducts: [
36
- sku: @plan.stripe_id,
37
- name: @plan.title,
38
- price: @plan.money.dollars,
39
- quantity: '1'
40
- ]
41
- }
42
- redirect_to(
43
- subscriptions_path,
44
- flash: {
45
- notice: :you_are_now_subscribed_to_the_plan.l(
46
- plan_name: current_user.plan.title
47
- )
48
- }
49
- )
26
+ # @plan load by #load_plan
27
+ result = current_user.subscribe_to_plan(
28
+ @plan,
29
+ params[:stripeToken],
30
+ params[:coupon_code]
31
+ )
32
+ if result
33
+ create_success
50
34
  else
51
- redirect_to(
52
- new_plan_subscription_path(@plan),
53
- flash: {
54
- error: current_user.errors.full_messages ||
55
- :could_not_subscribe_to_plan.l(plan: @plan.title)
56
- }
57
- )
35
+ create_error
58
36
  end
59
- rescue Stripe::InvalidRequestError => e
37
+ end
38
+
39
+ private
40
+
41
+ def create_success
42
+ google_analytics_flash
43
+ flash[:notice] = :you_are_now_subscribed_to_the_plan.l(
44
+ plan_name: current_user.plan.title
45
+ )
46
+ redirect_to subscriptions_url
47
+ end
48
+
49
+ def create_error
50
+ flash[:error] = current_user.errors.full_messages ||
51
+ :could_not_subscribe_to_plan.l(plan: @plan.title)
52
+ redirect_to new_plan_subscription_url(@plan)
53
+ end
54
+
55
+ def invalid_request_error(e)
60
56
  flash[:error] = e.message
61
57
  redirect_to subscriptions_path
62
- rescue Stripe::CardError => e
58
+ end
59
+
60
+ def invalid_card_error(e)
63
61
  flash[:error] = e.message
64
62
  redirect_to new_plan_subscription_path
65
63
  end
66
64
 
67
- private
68
-
69
- def set_plan
65
+ def load_plan
70
66
  @plan = PaidUp::Plan.find(params[:plan_id])
71
67
  end
68
+
69
+ def google_analytics_flash
70
+ stripe_data = current_user.stripe_data
71
+ discount = stripe_data.discount
72
+ flash[:paid_up_google_analytics_data] = {
73
+ transactionId: stripe_data.subscriptions.first.id,
74
+ transactionTotal: @plan.adjusted_money(discount).dollars,
75
+ transactionProducts: [
76
+ sku: @plan.stripe_id, name: @plan.title, price: @plan.money.dollars,
77
+ quantity: '1'
78
+ ]
79
+ }
80
+ end
72
81
  end
73
82
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PaidUp
2
4
  # PaidUp Features Helper
3
5
  module FeaturesHelper
@@ -16,11 +18,7 @@ module PaidUp
16
18
 
17
19
  def feature_display(feature, plan)
18
20
  if feature.setting_type == 'boolean'
19
- if plan.feature_setting(feature.slug)
20
- icon 'ok'
21
- else
22
- icon 'remove'
23
- end
21
+ icon plan.feature_setting(feature.slug) ? 'ok' : 'remove'
24
22
  elsif plan.feature_unlimited?(feature.slug)
25
23
  :unlimited.l
26
24
  else
@@ -28,41 +26,28 @@ module PaidUp
28
26
  end
29
27
  end
30
28
 
31
- def features_table(options = {})
32
- features = PaidUp::Feature.all
33
-
34
- if !options[:should_add_buttons].nil?
35
- should_add_buttons = options[:should_add_buttons]
36
- options.delete(:should_add_buttons)
29
+ def feature_state(feature)
30
+ case feature.setting_type
31
+ when 'boolean'
32
+ boolean_state(feature)
33
+ when 'table_rows'
34
+ setting_state feature, current_user.table_setting(feature.slug)
35
+ when 'rolify_rows'
36
+ setting_state feature, current_user.rolify_setting(feature.slug)
37
37
  else
38
- should_add_buttons = true
39
- end
40
-
41
- plans = PaidUp::Plan.subscribable
42
- if options[:only].present?
43
- plans = plans.where(id: options[:only])
44
- options.delete(:only)
45
- end
46
- if options[:except].present?
47
- plans = plans.where.not(id: options[:except])
48
- options.delete(:except)
49
- end
50
-
51
- if options[:highlight].present?
52
- highlight_plan = options[:highlight]
53
- options.delete(:highlight)
54
- else
55
- highlight_plan = nil
38
+ :error.l
56
39
  end
40
+ end
57
41
 
42
+ def features_table(options = {})
43
+ plans = PaidUp::Plan.display options.delete(:only),
44
+ options.delete(:except)
58
45
  render(
59
46
  partial: 'paid_up/features/table',
60
47
  locals: {
61
- should_add_buttons: should_add_buttons,
62
- plans: plans,
63
- features: features,
64
- highlight_plan: highlight_plan,
65
- html_options: options
48
+ highlight_plan: options.delete(:highlight), plans: plans,
49
+ should_add_buttons: options.delete(:should_add_buttons) || true,
50
+ features: PaidUp::Feature.all, html_options: options
66
51
  }
67
52
  )
68
53
  end
@@ -74,5 +59,21 @@ module PaidUp
74
59
  locals: { features: features, html_options: options }
75
60
  )
76
61
  end
62
+
63
+ private
64
+
65
+ def boolean_state(feature)
66
+ render partial: 'paid_up/features/boolean_state', locals: {
67
+ feature: feature
68
+ }
69
+ end
70
+
71
+ def setting_state(feature, setting)
72
+ render partial: 'paid_up/features/setting_state', locals: {
73
+ remaining: setting.rows_remaining, used: setting.rows_count,
74
+ allowed: setting.rows_allowed, model: feature.feature_model,
75
+ unlimited: setting.rows_unlimited?
76
+ }
77
+ end
77
78
  end
78
79
  end
@@ -1,21 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PaidUp
2
4
  # PaidUp PaidUp Helper
3
5
  module PaidUpHelper
4
6
  def date_range(start_date, end_date)
5
7
  dates = []
6
- if start_date.present? &&
7
- (start_date.is_a?(Date) || start_date.is_a?(Integer))
8
- dates << start_date.to_date
9
- end
10
- if end_date.present? &&
11
- (end_date.is_a?(Date) || end_date.is_a?(Integer))
12
- dates << end_date.to_date
13
- end
8
+ dates << start_date.to_date if date_valid?(start_date)
9
+ dates << end_date.to_date if date_valid?(end_date)
14
10
  dates.join('&mdash;').html_safe
15
11
  end
16
12
 
17
13
  def paid_up_google_analytics_data_layer
18
14
  render partial: 'paid_up/layouts/google_analytics_data_layer'
19
15
  end
16
+
17
+ private
18
+
19
+ def date_valid?(date)
20
+ date.present? && (date.is_a?(Date) || date.is_a?(Integer))
21
+ end
20
22
  end
21
23
  end