diff --git a/app/controllers/alaveteli_pro/subscriptions_controller.rb b/app/controllers/alaveteli_pro/subscriptions_controller.rb index 60ca0d743f..e2089721f3 100644 --- a/app/controllers/alaveteli_pro/subscriptions_controller.rb +++ b/app/controllers/alaveteli_pro/subscriptions_controller.rb @@ -1,33 +1,25 @@ class AlaveteliPro::SubscriptionsController < AlaveteliPro::BaseController + before_action :check_has_current_subscription, only: [:index] + skip_before_action :html_response, only: [:create, :authorise] skip_before_action :pro_user_authenticated?, only: [:create, :authorise] - before_action :authenticate, only: [:create, :authorise] + before_action :check_allowed_to_subscribe_to_pro, only: [:create] before_action :prevent_duplicate_submission, only: [:create] before_action :load_plan, :load_coupon, only: [:create] - before_action :check_has_current_subscription, only: [:index] def index @customer = current_user.pro_account.try(:stripe_customer) @subscriptions = current_user.pro_account.subscriptions end - # TODO: remove reminder of Stripe params once shipped - # - # params => - # {"utf8"=>"✓", - # "authenticity_token"=>"Ono2YgLcl1eC1gGzyd7Vf5HJJhOek31yFpT+8z+tKoo=", - # "stripe_token"=>"tok_s3kr3t…", - # "controller"=>"alaveteli_pro/subscriptions", - # "action"=>"create", - # "plan_id"=>"WDTK-pro"} def create begin @pro_account = current_user.pro_account ||= current_user.build_pro_account # Ensure previous incomplete subscriptions are cancelled to prevent them - # from using the new card + # from using the new token/card @pro_account.subscriptions.incomplete.map(&:delete) @token = Stripe::Token.retrieve(params[:stripe_token]) @@ -114,10 +106,10 @@ def authorise end rescue Stripe::RateLimitError, - Stripe::InvalidRequestError, - Stripe::AuthenticationError, - Stripe::APIConnectionError, - Stripe::StripeError => e + Stripe::InvalidRequestError, + Stripe::AuthenticationError, + Stripe::APIConnectionError, + Stripe::StripeError => e if send_exception_notifications? ExceptionNotifier.notify_exception(e, env: request.env) end diff --git a/app/helpers/alaveteli_pro/plan_helper.rb b/app/helpers/alaveteli_pro/plan_helper.rb index 7bc3fb5065..af002445e8 100644 --- a/app/helpers/alaveteli_pro/plan_helper.rb +++ b/app/helpers/alaveteli_pro/plan_helper.rb @@ -13,13 +13,13 @@ def billing_frequency(plan) elsif interval(plan) == 'year' && interval_count(plan) == 1 _('Billed: Annually') else - _('Billed: every {{interval}}', interval: interval(plan)) + _('Billed: every {{interval}}', interval: pluralize_interval(plan)) end end def billing_interval(plan) if interval_count(plan) == 1 - _('per user, per {{interval}}', interval: pluralize_interval(plan)) + _('per user, per {{interval}}', interval: interval(plan)) else _('per user, every {{interval}}', interval: pluralize_interval(plan)) end diff --git a/app/models/alaveteli_pro/subscription/discount.rb b/app/models/alaveteli_pro/subscription/discount.rb index d7234518db..ab96e5000a 100644 --- a/app/models/alaveteli_pro/subscription/discount.rb +++ b/app/models/alaveteli_pro/subscription/discount.rb @@ -24,7 +24,7 @@ def discounted_amount end def discounted? - discounted_amount < plan.amount + reduction > 0 end def discount_name diff --git a/spec/helpers/alaveteli_pro/plan_helper_spec.rb b/spec/helpers/alaveteli_pro/plan_helper_spec.rb index bdcab955b1..ae85075529 100644 --- a/spec/helpers/alaveteli_pro/plan_helper_spec.rb +++ b/spec/helpers/alaveteli_pro/plan_helper_spec.rb @@ -33,6 +33,12 @@ allow(plan).to receive(:interval_count).and_return(1) expect(helper.billing_frequency(plan)).to eq('Billed: every quarter') end + + it 'returns custom message for intervals with count greater then 1' do + allow(plan).to receive(:interval).and_return('week') + allow(plan).to receive(:interval_count).and_return(2) + expect(helper.billing_frequency(plan)).to eq('Billed: every 2 weeks') + end end describe '#billing_interval' do