paid_up 0.11.7 → 0.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7c1ccc499e297cd644e9ccc070f7f6119fb5a2b1
|
|
4
|
+
data.tar.gz: 6034b27662459169830dc94407dea76f8041df25
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
data/Gemfile
CHANGED
|
@@ -1,48 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
source 'https://rubygems.org'
|
|
2
4
|
|
|
3
|
-
|
|
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 '
|
|
11
|
+
gem 'rails', '>= 4', '< 6'
|
|
12
|
+
gem 'rails-i18n', '>= 4', '< 6'
|
|
13
|
+
gem 'uglifier', '>= 2.7', '< 4'
|
|
10
14
|
|
|
11
|
-
gem 'bootstrap_leather', '~> 0.
|
|
15
|
+
gem 'bootstrap_leather', '~> 0.9'
|
|
12
16
|
|
|
13
17
|
gem 'chronic', '~> 0.10'
|
|
14
18
|
gem 'money', '~> 6.5'
|
|
15
19
|
|
|
16
|
-
gem '
|
|
17
|
-
gem '
|
|
20
|
+
gem 'cancancan', '~> 1'
|
|
21
|
+
gem 'devise', '>= 3.4', '< 5'
|
|
18
22
|
gem 'rolify', '~> 5'
|
|
19
|
-
gem 'stripe', '
|
|
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 '
|
|
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 '
|
|
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
|
|
43
|
-
gem '
|
|
44
|
-
gem '
|
|
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 '
|
|
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
|
+

|
|
19
|
+
|
|
20
|
+
### New Subscription Page
|
|
21
|
+

|
|
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 '
|
|
8
|
-
|
|
9
|
+
require 'juwelier'
|
|
10
|
+
Juwelier::Tasks.new do |gem|
|
|
9
11
|
# gem is a Gem::Specification...
|
|
10
|
-
# see http://
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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,73 +1,82 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module PaidUp
|
|
2
4
|
# Subscriptions Controller
|
|
3
5
|
class SubscriptionsController < PaidUpController
|
|
4
|
-
|
|
5
|
-
|
|
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
|
|
13
|
-
(current_user.can_downgrade_to?(@plan) || @plan.amount
|
|
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
|
|
18
|
-
current_user.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
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
|
-
|
|
7
|
-
|
|
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('—').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
|