Commit f6215fbb authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'nicolasdular/subscription-plan-redirect' into 'master'

Redirect to customer portal or registration

See merge request gitlab-org/gitlab!22978
parents f0dd6daf 05b45235
......@@ -2,9 +2,17 @@
class SubscriptionsController < ApplicationController
layout 'checkout'
skip_before_action :authenticate_user!, only: :new
def new
return redirect_to dashboard_projects_path unless Feature.enabled?(:paid_signup_flow)
if experiment_enabled?(:paid_signup_flow)
return if current_user
store_location_for :user, request.fullpath
redirect_to new_user_registration_path
else
redirect_to customer_portal_new_subscription_url
end
end
def payment_form
......@@ -22,4 +30,8 @@ class SubscriptionsController < ApplicationController
def client
Gitlab::SubscriptionPortal::Client
end
def customer_portal_new_subscription_url
"#{EE::SUBSCRIPTIONS_URL}/subscriptions/new?plan_id=#{params[:plan_id]}&transaction=create_subscription"
end
end
......@@ -8,9 +8,21 @@ describe SubscriptionsController do
describe 'GET #new' do
subject { get :new, params: { plan_id: 'bronze_id' } }
context 'with experiment enabled' do
before do
stub_experiment(paid_signup_flow: true)
stub_experiment_for_user(paid_signup_flow: true)
end
context 'with unauthorized user' do
it { is_expected.to have_gitlab_http_status 302 }
it { is_expected.to redirect_to new_user_session_path }
it { is_expected.to redirect_to new_user_registration_path }
it 'stores subscription URL for later' do
subject
expect(controller.stored_location_for(:user)).to eq(new_subscriptions_path(plan_id: 'bronze_id'))
end
end
context 'with authorized user' do
......@@ -18,23 +30,18 @@ describe SubscriptionsController do
sign_in(user)
end
context 'with feature flag enabled' do
before do
stub_feature_flags(paid_signup_flow: true)
end
it { is_expected.to render_template 'layouts/checkout' }
it { is_expected.to render_template :new }
end
end
context 'with feature flag disabled' do
context 'with experiment disabled' do
before do
stub_feature_flags(paid_signup_flow: false)
stub_experiment(paid_signup_flow: false)
stub_experiment_for_user(paid_signup_flow: false)
end
it { is_expected.to have_gitlab_http_status 302 }
it { is_expected.to redirect_to dashboard_projects_path }
end
it { is_expected.to redirect_to "#{EE::SUBSCRIPTIONS_URL}/subscriptions/new?plan_id=bronze_id&transaction=create_subscription" }
end
end
......
......@@ -16,6 +16,12 @@ module Gitlab
environment: ::Gitlab.dev_env_or_com?,
enabled_ratio: 1,
tracking_category: 'Growth::Acquisition::Experiment::SignUpFlow'
},
paid_signup_flow: {
feature_toggle: :paid_signup_flow,
environment: ::Gitlab.dev_env_or_com?,
enabled_ratio: 0.1,
tracking_category: 'Growth::Acquisition::Experiment::PaidSignUpFlow'
}
}.freeze
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment