From 2256147163611cd009ecbfe4563150c3ca45c569 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Mon, 12 Feb 2018 00:51:12 -0600 Subject: [PATCH 01/11] anon users always have all unread --- app/views/thredded/messageboards/_messageboard.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/thredded/messageboards/_messageboard.html.erb b/app/views/thredded/messageboards/_messageboard.html.erb index 8516e7990..3707e3827 100644 --- a/app/views/thredded/messageboards/_messageboard.html.erb +++ b/app/views/thredded/messageboards/_messageboard.html.erb @@ -10,7 +10,7 @@ unread_posts_count = if user_signed_in? messageboard.topics.unread(current_user).count else - 0 + messageboard.topics_count end %> <%= t 'thredded.messageboard.topics_and_posts_counts', From 68f99b42469da79fef90a578a5c7a6e9be85b14a Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 14 Feb 2018 15:24:21 -0600 Subject: [PATCH 02/11] restart heroku --- README.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rdoc b/README.rdoc index 09bdc6b7f..0eb1d1b7f 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,4 +1,4 @@ -= Notebook.ai += Notebook.ai {Build Status}[https://travis-ci.org/indentlabs/notebook] {}[https://codeclimate.com/github/indentlabs/notebook] {}[https://codeclimate.com/github/indentlabs/notebook/coverage] From 6b0f950b82a47b54f5ebd2fe2fbca1e552778760 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 21 Feb 2018 11:58:50 -0600 Subject: [PATCH 03/11] restart --- README.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rdoc b/README.rdoc index 0eb1d1b7f..603d7ebf7 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,4 +1,4 @@ -= Notebook.ai += Notebook.ai {Build Status}[https://travis-ci.org/indentlabs/notebook] {}[https://codeclimate.com/github/indentlabs/notebook] {}[https://codeclimate.com/github/indentlabs/notebook/coverage] From e09c47de7292e4bf27ef29fb12e7a80163caf567 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 21 Feb 2018 23:51:39 -0600 Subject: [PATCH 04/11] include ads js for testing adsense --- app/views/layouts/_common_head.html.erb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/views/layouts/_common_head.html.erb b/app/views/layouts/_common_head.html.erb index ea5a95f67..e9a754935 100644 --- a/app/views/layouts/_common_head.html.erb +++ b/app/views/layouts/_common_head.html.erb @@ -25,3 +25,13 @@ for(h=0;h"); +<%# AdSense %> +<% unless user_signed_in? %> + + +<% end %> From ffa7724b116215b7004c58921c135534a3be74d5 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 21 Feb 2018 23:59:11 -0600 Subject: [PATCH 05/11] Update onebox --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 4d6c57f08..3e21083a3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -245,7 +245,7 @@ GEM notiffany (0.1.1) nenv (~> 0.1) shellany (~> 0.0) - onebox (1.8.36) + onebox (1.8.40) fast_blank (>= 1.0.0) htmlentities (~> 4.3) moneta (~> 1.0) From af1bcf05ea19e4e6bb6e7cae92e54f050cc4af67 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Thu, 22 Feb 2018 14:58:54 -0600 Subject: [PATCH 06/11] initialize stripe sub for returning subs --- app/controllers/subscriptions_controller.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index c972112d7..75f3cb0f7 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -68,6 +68,11 @@ def change stripe_customer = Stripe::Customer.retrieve current_user.stripe_customer_id stripe_subscription = stripe_customer.subscriptions.data[0] + if stripe_subscription.nil? + Stripe::Subscription.create(customer: current_user.stripe_customer_id, plan: 'starter') + stripe_subscription = stripe_customer.subscriptions.data[0] + end + # If the user already has a payment method on file, change their plan and add a new subscription if stripe_customer.sources.total_count > 0 # Cancel any active subscriptions, since we're changing plans From faa3e0b1b406713ee09954fc579ac2e25ef4b371 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Sat, 3 Mar 2018 14:08:58 -0600 Subject: [PATCH 07/11] Authenticate users in subscription controller --- app/controllers/main_controller.rb | 5 +++++ app/controllers/subscriptions_controller.rb | 7 +------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 419bed6bf..298b95898 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -22,6 +22,11 @@ def comingsoon def dashboard return redirect_to new_user_session_path unless user_signed_in? + if user_signed_in? && current_user.universes.count > 1 && @universe_scope.nil? + redirect_to universes_path + return + end + @content_types = ( Rails.application.config.content_types[:all].map(&:name) & # Use config to dictate order current_user.user_content_type_activators.pluck(:content_type) diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index 75f3cb0f7..7e2be580f 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -1,9 +1,8 @@ class SubscriptionsController < ApplicationController + before_action :authenticate_user! protect_from_forgery except: :stripe_webhook def new - return redirect_to new_user_session_path, notice: t(:no_do_permission) unless user_signed_in? - Mixpanel::Tracker.new(Rails.application.config.mixpanel_token).track(current_user.id, 'viewed billing page', { 'current billing plan': current_user.selected_billing_plan_id, 'content count': current_user.content_count @@ -178,10 +177,6 @@ def information end def information_change - # No idea why current_user is nil for this endpoint (maybe CSRF isn't passing through correctly?) but - # calling authenticate_user! here reauths the user and sets current_user - authenticate_user! - valid_token = params[:stripeToken] raise "Invalid token" if valid_token.nil? From ee06aa29d271b746a685a277167037125dfd3254 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Sat, 3 Mar 2018 16:35:35 -0600 Subject: [PATCH 08/11] subscriptions refactor --- app/controllers/subscriptions_controller.rb | 272 +++----------------- app/controllers/users_controller.rb | 2 +- app/models/user.rb | 1 - app/services/subscription_service.rb | 122 +++++++++ 4 files changed, 157 insertions(+), 240 deletions(-) create mode 100644 app/services/subscription_service.rb diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index 7e2be580f..9938cac73 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -2,6 +2,7 @@ class SubscriptionsController < ApplicationController before_action :authenticate_user! protect_from_forgery except: :stripe_webhook + # General billing page def new Mixpanel::Tracker.new(Rails.application.config.mixpanel_token).track(current_user.id, 'viewed billing page', { 'current billing plan': current_user.selected_billing_plan_id, @@ -21,137 +22,20 @@ def show def change new_plan_id = params[:stripe_plan_id] - possible_plan_ids = BillingPlan.where(available: true).map(&:stripe_plan_id) + possible_plan_ids = SubscriptionService.available_plans.pluck(:stripe_plan_id) - raise "Invalid billing plan ID: #{new_plan_id}" unless possible_plan_ids.include? new_plan_id - - # If the user is changing to Starter, go ahead and cancel any active subscriptions and do it - if new_plan_id == 'starter' - current_user.active_subscriptions.each do |subscription| - subscription.update(end_date: Time.now) - end - - if current_user.selected_billing_plan_id.nil? - old_billing_plan = BillingPlan.new(name: 'No billing plan', monthly_cents: 0) - else - old_billing_plan = BillingPlan.find(current_user.selected_billing_plan_id) - end - new_billing_plan = BillingPlan.find_by(stripe_plan_id: new_plan_id, available: true) - current_user.selected_billing_plan_id = new_billing_plan.id - - # Remove any bonus bandwidth our old plan granted - current_user.upload_bandwidth_kb -= old_billing_plan.bonus_bandwidth_kb - - current_user.save - - Subscription.create( - user: current_user, - billing_plan: new_billing_plan, - start_date: Time.now, - end_date: Time.now.end_of_day + 5.years - ) - - unless Rails.env.test? - stripe_customer = Stripe::Customer.retrieve current_user.stripe_customer_id - stripe_subscription = stripe_customer.subscriptions.data[0] - stripe_subscription.save - end - - report_subscription_change_to_slack current_user, old_billing_plan, new_billing_plan - - flash[:notice] = "You have been successfully downgraded to Starter." #todo proration/credit - return redirect_to subscription_path - end - - # Fetch current subscription - stripe_customer = Stripe::Customer.retrieve current_user.stripe_customer_id - stripe_subscription = stripe_customer.subscriptions.data[0] - - if stripe_subscription.nil? - Stripe::Subscription.create(customer: current_user.stripe_customer_id, plan: 'starter') - stripe_subscription = stripe_customer.subscriptions.data[0] + unless possible_plan_ids.include?(new_plan_id) + raise "Invalid billing plan ID: #{new_plan_id}" end - # If the user already has a payment method on file, change their plan and add a new subscription - if stripe_customer.sources.total_count > 0 - # Cancel any active subscriptions, since we're changing plans - current_user.active_subscriptions.each do |subscription| - subscription.update(end_date: Time.now) - end - - # Change subscription plan if they already have a payment method on file - stripe_subscription.plan = new_plan_id - begin - stripe_subscription.save unless Rails.env.test? - rescue Stripe::CardError => e - flash[:alert] = "We couldn't upgrade you to Premium because #{e.message.downcase} Please double check that your information is correct." - return redirect_to :back - end - - # If this is the first time this user is subscribing to Premium, gift them (and their referrer, if applicable) feature votes and space - existing_premium_subscriptions = current_user.subscriptions.where(billing_plan_id: BillingPlan::PREMIUM_IDS) - unless existing_premium_subscriptions.any? - referring_user = current_user.referrer || current_user - - # First-time premium! - # +100 MB - current_user.update upload_bandwidth_kb: current_user.upload_bandwidth_kb + 100_000 - current_user.reload - - # +1 vote - current_user.votes.create - # +1 vote if referred - current_user.votes.create if referring_user.present? - - # +1 raffle entry - current_user.raffle_entries.create - # +1 raffle entry if referred - current_user.raffle_entries.create if referring_user.present? - - if referring_user - # +100MB - referring_user.update upload_bandwidth_kb: referring_user.upload_bandwidth_kb + 100_000 - - # +2 votes - referring_user.votes.create - referring_user.votes.create - - # +2 raffle entries - referring_user.raffle_entries.create - referring_user.raffle_entries.create - end - end - - if current_user.selected_billing_plan_id.nil? - old_billing_plan = BillingPlan.new(name: 'No billing plan', monthly_cents: 0) - else - old_billing_plan = BillingPlan.find(current_user.selected_billing_plan_id) - end - new_billing_plan = BillingPlan.find_by(stripe_plan_id: new_plan_id, available: true) - current_user.selected_billing_plan_id = new_billing_plan.id - - # Add any bonus bandwidth our new plan grants, unless we're moving from Premium to Premium - premium_ids = [3, 4, 5, 6] - if !premium_ids.include?(current_user.selected_billing_plan_id) && premium_ids.include?(new_plan_id) - current_user.upload_bandwidth_kb += new_billing_plan.bonus_bandwidth_kb - end - - current_user.save - - Subscription.create( - user: current_user, - billing_plan: new_billing_plan, - start_date: Time.now, - end_date: Time.now.end_of_day + 5.years - ) - - report_subscription_change_to_slack current_user, old_billing_plan, new_billing_plan + result = move_user_to_plan_requested(new_plan_id) - flash[:notice] = "You have been successfully upgraded to #{new_billing_plan.name}!" - redirect_to subscription_path - else - # If they don't have a payment method on file, redirect them to collect one + if result == :payment_method_needed redirect_to payment_info_path(plan: new_plan_id) + elsif result == :failed_card + return + else + redirect_to(subscription_path, notice: "Your plan was successfully changed.") end end @@ -166,6 +50,7 @@ def change # stripe_subscription.delete(at_period_end: true) # end + # Billing information page def information @selected_plan = BillingPlan.find_by(stripe_plan_id: params['plan'], available: true) @stripe_customer = Stripe::Customer.retrieve(current_user.stripe_customer_id) @@ -176,6 +61,7 @@ def information }) if Rails.env.production? end + # Save a payment method def information_change valid_token = params[:stripeToken] raise "Invalid token" if valid_token.nil? @@ -195,90 +81,9 @@ def information_change return redirect_to :back end - notice = [] - - # After saving the user's payment method, move them over to the associated billing plan - new_billing_plan = BillingPlan.find_by(stripe_plan_id: params[:plan], available: true) - if new_billing_plan - if current_user.selected_billing_plan_id.nil? - old_billing_plan = BillingPlan.new(name: 'No billing plan', monthly_cents: 0) - else - old_billing_plan = BillingPlan.find(current_user.selected_billing_plan_id) - end - current_user.selected_billing_plan_id = new_billing_plan.id - - # Remove any bonus bandwidth our old plan granted - current_user.upload_bandwidth_kb -= old_billing_plan.bonus_bandwidth_kb - - # Add any bonus bandwidth our new plan grants - current_user.upload_bandwidth_kb += new_billing_plan.bonus_bandwidth_kb - - current_user.save - - stripe_subscription.plan = new_billing_plan.stripe_plan_id - begin - stripe_subscription.save - rescue Stripe::CardError => e - flash[:alert] = "We couldn't upgrade you to Premium because #{e.message.downcase} Please double check that your information is correct." - return redirect_to :back - end - - # End all currently-active subscriptions - current_user.active_subscriptions.each do |subscription| - subscription.update(end_date: Time.now) - end - - # If this is the first time this user is subscribing to Premium, gift them (and their referrer, if applicable) feature votes and space - existing_premium_subscriptions = current_user.subscriptions.where(billing_plan_id: BillingPlan::PREMIUM_IDS) - unless existing_premium_subscriptions.any? - referring_user = current_user.referrer || current_user - - # First-time premium! - # +100 MB - current_user.update upload_bandwidth_kb: current_user.upload_bandwidth_kb + 100_000 - current_user.reload + move_user_to_plan_requested(params[:plan]) - # +1 vote - current_user.votes.create - # +1 vote if referred - current_user.votes.create if referring_user.present? - - # +1 raffle entry - current_user.raffle_entries.create - # +1 raffle entry if referred - current_user.raffle_entries.create if referring_user.present? - - if referring_user - # +100MB - referring_user.update upload_bandwidth_kb: referring_user.upload_bandwidth_kb + 100_000 - - # +2 votes - referring_user.votes.create - referring_user.votes.create - - # +2 raffle entries - referring_user.raffle_entries.create - referring_user.raffle_entries.create - end - end - - # And create a subscription for them for the current plan - Subscription.create( - user: current_user, - billing_plan: new_billing_plan, - start_date: Time.now, - end_date: Time.now.end_of_day + 31.days - ) - - report_subscription_change_to_slack current_user, old_billing_plan, new_billing_plan - - notice << "you have been successfully upgraded to #{new_billing_plan.name}" - end - - notice << "Your payment method has been successfully saved" - - flash[:notice] = "#{notice.reverse.to_sentence}." - redirect_to subscription_path + redirect_to(subscription_path, notice: 'Your payment method has been successfully changed.') end def delete_payment_method @@ -310,40 +115,31 @@ def stripe_webhook #todo handle webhooks end - def report_subscription_change_to_slack user, from, to - return unless Rails.env == 'production' - slack_hook = ENV['SLACK_HOOK'] - return unless slack_hook - - notifier = Slack::Notifier.new slack_hook, - channel: '#subscriptions', - username: 'tristan' + private - if from.nil? || to.nil? - delta = ":tada: LOL :tada:" - elsif from.monthly_cents < to.monthly_cents - delta = ":tada: *UPGRADE* :tada:" - elsif from.monthly_cents == to.monthly_cents - delta = ":tada: ... sidegrade ... :tada:" + def move_user_to_plan_requested(plan_id) + if plan_id == 'starter' + process_plan_change(current_user, plan_id) else - delta = ":wave: Downgrade" - end + stripe_customer = Stripe::Customer.retrieve current_user.stripe_customer_id - total_subscriptions = 0 - monthly_rev_cents = 0 - billing_plans_with_prices = BillingPlan.where.not(monthly_cents: 0).pluck(:id, :monthly_cents) - billing_plans_with_prices.each do |plan_id, monthly_cents| - users_on_this_plan = User.where(selected_billing_plan_id: plan_id).count - total_subscriptions += users_on_this_plan - monthly_rev_cents += monthly_cents * users_on_this_plan + # If we're upgrading to premium, we want to check that a payment method + # is already on file. If it is, we process the plan change. If it's not, + # we redirect to the payment method page. + if stripe_customer.sources.total_count > 0 + process_plan_change(current_user, plan_id) + else + return :payment_method_needed + end end + end - notifier.ping [ - "#{delta} for #{user.email.split('@').first}@ (##{user.id})", - "From: *#{from.name}* ($#{from.monthly_cents / 100.0}/month)", - "To: *#{to.name}* (#{to.stripe_plan_id}) ($#{to.monthly_cents / 100.0}/month)", - "#{total_subscriptions} subscriptions total $#{'%.2f' % (monthly_rev_cents / 100)}/mo" - ].join("\n") + def process_plan_change(user, new_plan_id) + # General flow we're going to take here: + # 1. Cancel all existing plans, reversing their benefits + SubscriptionService.cancel_all_existing_subscriptions(user) + # 2. Add a new plan, adding its benefits + SubscriptionService.add_subscription(user, new_plan_id) end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5a452c7a5..df9384d5d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -38,7 +38,7 @@ def delete_my_account # :( stripe_subscription.plan = 'starter' stripe_subscription.save - report_user_deletion_to_slack current_user + report_user_deletion_to_slack(current_user) current_user.really_destroy! redirect_to root_path, notice: 'Your account has been deleted. We will miss you greatly!' diff --git a/app/models/user.rb b/app/models/user.rb index 75a84c919..893b6d5d0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -36,7 +36,6 @@ def referrer has_many :user_content_type_activators, dependent: :destroy def contributable_universes - @user_contributable_universes ||= begin # todo email confirmation needs to happy for data safety / privacy (only verified emails) contributor_by_email = Contributor.where(email: self.email).pluck(:universe_id) diff --git a/app/services/subscription_service.rb b/app/services/subscription_service.rb new file mode 100644 index 000000000..b774a2825 --- /dev/null +++ b/app/services/subscription_service.rb @@ -0,0 +1,122 @@ +class SubscriptionService < Service + #todo: support multiple simultaneous plans + + def self.add_subscription(user, plan_id) + related_plan = BillingPlan.find_by(stripe_plan_id: plan_id, available: true) + + # Add any bonus bandwidth granted by the plan + user.update( + upload_bandwidth_kb: user.upload_bandwidth_kb + related_plan.bonus_bandwidth_kb + ) + + # Add any one-time referral bonuses + add_any_referral_bonuses(user, plan_id) + + user.update(selected_billing_plan_id: plan_id) + user.subscriptions.create( + billing_plan: related_plan, + start_date: DateTime.now, + end_date: DateTime.now.end_of_day + 5.years + ) + + # Sync with Stripe (todo pipe into StripeService) + unless Rails.env.test? + stripe_customer = Stripe::Customer.retrieve(user.stripe_customer_id) + stripe_subscription = stripe_customer.subscriptions.data[0] + + if stripe_subscription.nil? + # Create a new subscription on Stripe + Stripe::Subscription.create(customer: user.stripe_customer_id, plan: plan_id) + stripe_customer = Stripe::Customer.retrieve(user.stripe_customer_id) + stripe_subscription = stripe_customer.subscriptions.data[0] + else + # Edit an existing Stripe subscription + stripe_subscription.plan = plan_id + end + + # Save the change + begin + stripe_subscription.save unless Rails.env.test? + rescue Stripe::CardError => e + flash[:alert] = "We couldn't upgrade you to Premium because #{e.message.downcase} Please double check that your information is correct." + return :failed_card + end + end + + report_subscription_change_to_slack(user, plan_id) + end + + def self.remove_subscription(user, subscription) + related_plan = subscription.billing_plan + + # Remove any bonus bandwidth granted by the plan + user.update( + upload_bandwidth_kb: user.upload_bandwidth_kb - related_plan.bonus_bandwidth_kb + ) + subscription.update(end_date: DateTime.now) + end + + def self.cancel_all_existing_subscriptions(user) + user.active_subscriptions.each do |subscription| + remove_subscription(user, subscription) + end + end + + def self.add_any_referral_bonuses(user, plan_id) + # This only applies if we're upgrading to premium, obviously + related_billing_plan = BillingPlan.find_by(stripe_plan_id: plan_id) + return unless BillingPlan::PREMIUM_IDS.include?(related_billing_plan.id) + + # If this is the first time this user is subscribing to Premium, gift them (and their referrer, if applicable) extra space + existing_premium_subscriptions = user.subscriptions.where(billing_plan_id: BillingPlan::PREMIUM_IDS) + return if existing_premium_subscriptions.any? + + # 100MB bonus to you + user.update( + upload_bandwidth_kb: user.upload_bandwidth_kb + 100_000 + ) + + # 100MB bonus to your referrer + referring_user = user.referrer + if referring_user + referring_user.update( + upload_bandwidth_kb: referring_user.upload_bandwidth_kb + 100_000 + ) + end + end + + def self.available_plans + BillingPlan.where(available: true) + end + + def self.dummy_starter_plan + BillingPlan.new(name: 'No billing plan', monthly_cents: 0) + end + + def self.report_subscription_change_to_slack(user, plan_id) + #return unless Rails.env == 'production' + slack_hook = ENV['SLACK_HOOK'] + return unless slack_hook + + related_plan = BillingPlan.find_by(stripe_plan_id: plan_id) + + notifier = Slack::Notifier.new slack_hook, + channel: '#subscriptions', + username: 'tristan' + + total_subscriptions = 0 + monthly_rev_cents = 0 + billing_plans_with_prices = BillingPlan.where.not(monthly_cents: 0).pluck(:id, :monthly_cents) + billing_plans_with_prices.each do |plan_id, monthly_cents| + users_on_this_plan = User.where(selected_billing_plan_id: plan_id).count + total_subscriptions += users_on_this_plan + monthly_rev_cents += monthly_cents * users_on_this_plan + end + + notifier.ping [ + "Subscription change for #{user.email.split('@').first}@ (##{user.id})", + "To: *#{related_plan.name}* (#{related_plan.stripe_plan_id}) ($#{related_plan.monthly_cents / 100.0}/month)", + "#{total_subscriptions} subscriptions total $#{'%.2f' % (monthly_rev_cents / 100)}/mo" + ].join("\n") + end +end From f3dda1483c18e9404efbe5d96f044375439ae43a Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Sat, 3 Mar 2018 16:54:16 -0600 Subject: [PATCH 09/11] send some future code dormant --- app/controllers/main_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 298b95898..1ff1314e4 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -22,10 +22,10 @@ def comingsoon def dashboard return redirect_to new_user_session_path unless user_signed_in? - if user_signed_in? && current_user.universes.count > 1 && @universe_scope.nil? - redirect_to universes_path - return - end + # if user_signed_in? && current_user.universes.count > 1 && @universe_scope.nil? + # redirect_to universes_path + # return + # end @content_types = ( Rails.application.config.content_types[:all].map(&:name) & # Use config to dictate order From 2934c4493ca294702b0e54e918d1e8cd2e37db68 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Sat, 3 Mar 2018 17:03:49 -0600 Subject: [PATCH 10/11] fix redirects --- app/controllers/subscriptions_controller.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index 9938cac73..0625f5ce5 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -81,9 +81,17 @@ def information_change return redirect_to :back end - move_user_to_plan_requested(params[:plan]) + new_plan_id = params[:plan] + result = move_user_to_plan_requested(new_plan_id) + + if result == :payment_method_needed + redirect_to payment_info_path(plan: new_plan_id) + elsif result == :failed_card + return + else + redirect_to(subscription_path, notice: 'Your plan was successfully changed.') + end - redirect_to(subscription_path, notice: 'Your payment method has been successfully changed.') end def delete_payment_method From fa93ad0777b227f18bc1ab37e1a5e9baf5f82cfe Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Sat, 3 Mar 2018 17:15:24 -0600 Subject: [PATCH 11/11] fix bug (thanks, tests) --- app/services/subscription_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/subscription_service.rb b/app/services/subscription_service.rb index b774a2825..b3da8ce0e 100644 --- a/app/services/subscription_service.rb +++ b/app/services/subscription_service.rb @@ -12,7 +12,7 @@ def self.add_subscription(user, plan_id) # Add any one-time referral bonuses add_any_referral_bonuses(user, plan_id) - user.update(selected_billing_plan_id: plan_id) + user.update(selected_billing_plan_id: related_plan.id) user.subscriptions.create( billing_plan: related_plan, start_date: DateTime.now,