Commit 8d870a74 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'growth-87-payment-method-backend' into 'master'

API endpoints for payment method component for paid signup flow

See merge request gitlab-org/gitlab!21641
parents 114fcce9 8281e91e
...@@ -6,4 +6,20 @@ class SubscriptionsController < ApplicationController ...@@ -6,4 +6,20 @@ class SubscriptionsController < ApplicationController
def new def new
return redirect_to dashboard_projects_path unless Feature.enabled?(:paid_signup_flow) return redirect_to dashboard_projects_path unless Feature.enabled?(:paid_signup_flow)
end end
def payment_form
response = client.payment_form_params(params[:id])
render json: response[:data]
end
def payment_method
response = client.payment_method(params[:id])
render json: response[:data]
end
private
def client
Gitlab::SubscriptionPortal::Client
end
end end
# frozen_string_literal: true # frozen_string_literal: true
resource :subscriptions, only: [:new] resource :subscriptions, only: [:new] do
get :payment_form
get :payment_method
end
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
require 'spec_helper' require 'spec_helper'
describe SubscriptionsController do describe SubscriptionsController do
describe 'GET #new' do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
describe 'GET #new' do
subject { get :new, params: { plan_id: 'bronze_id' } } subject { get :new, params: { plan_id: 'bronze_id' } }
context 'with unauthorized user' do context 'with unauthorized user' do
...@@ -37,4 +37,52 @@ describe SubscriptionsController do ...@@ -37,4 +37,52 @@ describe SubscriptionsController do
end end
end end
end end
describe 'GET #payment_form' do
subject { get :payment_form, params: { id: 'cc' } }
context 'with unauthorized user' do
it { is_expected.to have_gitlab_http_status 302 }
it { is_expected.to redirect_to new_user_session_path }
end
context 'with authorized user' do
before do
sign_in(user)
client_response = { success: true, data: { signature: 'x', token: 'y' } }
allow(Gitlab::SubscriptionPortal::Client).to receive(:payment_form_params).with('cc').and_return(client_response)
end
it { is_expected.to have_gitlab_http_status 200 }
it 'returns the data attribute of the client response in JSON format' do
subject
expect(response.body).to eq('{"signature":"x","token":"y"}')
end
end
end
describe 'GET #payment_method' do
subject { get :payment_method, params: { id: 'xx' } }
context 'with unauthorized user' do
it { is_expected.to have_gitlab_http_status 302 }
it { is_expected.to redirect_to new_user_session_path }
end
context 'with authorized user' do
before do
sign_in(user)
client_response = { success: true, data: { credit_card_type: 'Visa' } }
allow(Gitlab::SubscriptionPortal::Client).to receive(:payment_method).with('xx').and_return(client_response)
end
it { is_expected.to have_gitlab_http_status 200 }
it 'returns the data attribute of the client response in JSON format' do
subject
expect(response.body).to eq('{"credit_card_type":"Visa"}')
end
end
end
end end
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