diff --git a/app/controllers/cbv_flows_controller.rb b/app/controllers/cbv_flows_controller.rb new file mode 100644 index 000000000..289199562 --- /dev/null +++ b/app/controllers/cbv_flows_controller.rb @@ -0,0 +1,69 @@ +class CbvFlowsController < ApplicationController + USER_TOKEN_ENDPOINT = 'https://api-sandbox.argyle.com/v2/users'; + + before_action :set_cbv_flow + + def entry + end + + def employer_search + @argyle_user_token = fetch_and_store_argyle_token + end + + def summary + @employer = summary_employer_params[:employer] + @payments = [ + { amount: 810, start: 'March 25', end: 'June 15', hours: 54, rate: 15 }, + { amount: 195, start: 'January 1', end: 'February 23', hours: 13, rate: 15 } + ] + end + + def reset + session[:cbv_flow_id] = nil + session[:argyle_user_token] = nil + redirect_to root_url + end + + private + + def set_cbv_flow + if session[:cbv_flow_id] + @cbv_flow = CbvFlow.find(session[:cbv_flow_id]) + else + # TODO: This case_number would be provided by the case worker when they send the initial invite + @cbv_flow = CbvFlow.create(case_number: 'ABC1234') + session[:cbv_flow_id] = @cbv_flow.id + end + end + + def next_path + case params[:action] + when 'entry' + cbv_flow_employer_search_path + when 'employer_search' + cbv_flow_summary_path + when 'summary' + root_url + end + end + helper_method :next_path + + def fetch_and_store_argyle_token + return session[:argyle_user_token] if session[:argyle_user_token].present? + + raise "ARGYLE_API_TOKEN environment variable is blank. Make sure you have the .env.local from 1Password." if ENV['ARGYLE_API_TOKEN'].blank? + + res = Net::HTTP.post(URI.parse(USER_TOKEN_ENDPOINT), "", {"Authorization" => "Basic #{ENV['ARGYLE_API_TOKEN']}"}) + parsed = JSON.parse(res.body) + raise "Argyle API error: #{parsed['detail']}" if res.code.to_i >= 400 + + @cbv_flow.update(argyle_user_id: parsed['id']) + session[:argyle_user_token] = parsed['user_token'] + + parsed['user_token'] + end + + def summary_employer_params + params.permit(:employer) + end +end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index a90b6d357..45f463e4c 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -1,4 +1,4 @@ class PagesController < ApplicationController - def welcome + def home end end diff --git a/app/controllers/providers_controller.rb b/app/controllers/providers_controller.rb index 095531cdf..f3a7e50e0 100644 --- a/app/controllers/providers_controller.rb +++ b/app/controllers/providers_controller.rb @@ -1,26 +1,4 @@ class ProvidersController < ApplicationController - USER_TOKEN_ENDPOINT = 'https://api-sandbox.argyle.com/v2/users'; - - def index - res = Net::HTTP.post(URI.parse(USER_TOKEN_ENDPOINT), "", {"Authorization" => "Basic #{ENV['ARGYLE_API_TOKEN']}"}) - - @user_token = JSON.parse(res.body)["user_token"] - end - def search end - - def confirm - @employer = employer_params[:employer] - @payments = [ - { amount: 810, start: 'March 25', end: 'June 15', hours: 54, rate: 15 }, - { amount: 195, start: 'January 1', end: 'February 23', hours: 13, rate: 15 } - ] - end - - private - - def employer_params - params.permit(:employer) - end end diff --git a/app/models/cbv_flow.rb b/app/models/cbv_flow.rb new file mode 100644 index 000000000..a1afb6662 --- /dev/null +++ b/app/models/cbv_flow.rb @@ -0,0 +1,2 @@ +class CbvFlow < ApplicationRecord +end diff --git a/app/views/providers/index.html.erb b/app/views/cbv_flows/employer_search.html.erb similarity index 82% rename from app/views/providers/index.html.erb rename to app/views/cbv_flows/employer_search.html.erb index 2590f25f7..1104b4bfc 100644 --- a/app/views/providers/index.html.erb +++ b/app/views/cbv_flows/employer_search.html.erb @@ -1,11 +1,11 @@ <% content_for :head do %> - <%= tag :meta, name: :argyle_user_token, content: @user_token %> + <%= tag :meta, name: :argyle_user_token, content: @argyle_user_token %> <%= tag :meta, name: :argyle_sandbox, content: ENV['ARGYLE_SANDBOX'] %> <% end %>

Get payment info from your employer.

-
+