Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions app/forms/idv/inherited_proofing/base_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,22 @@ def model_name
def namespaced_model_name
self.to_s.gsub('::', '')
end

def fields
@fields ||= required_fields + optional_fields
end

def required_fields
raise NotImplementedError,
'Override this method and return an Array of required field names as Symbols'
end

def optional_fields
raise NotImplementedError,
'Override this method and return an Array of optional field names as Symbols'
end
end

private_class_method :namespaced_model_name, :required_fields, :optional_fields
private_class_method :namespaced_model_name

attr_reader :payload_hash

def initialize(payload_hash:)
raise ArgumentError, 'payload_hash is blank?' if payload_hash.blank?
raise ArgumentError, 'payload_hash is not a Hash' unless payload_hash.is_a? Hash

self.class.attr_accessor(*self.class.fields)

@payload_hash = payload_hash.dup

populate_field_data
end

def submit
validate

FormResponse.new(
success: valid?,
errors: errors,
Expand Down
54 changes: 43 additions & 11 deletions app/forms/idv/inherited_proofing/va/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,34 @@ module Idv
module InheritedProofing
module Va
class Form < Idv::InheritedProofing::BaseForm
class << self
def required_fields
@required_fields ||= %i[first_name last_name birth_date ssn address_street address_zip]
end

def optional_fields
@optional_fields ||= %i[phone address_street2 address_city address_state
address_country]
end
end
REQUIRED_FIELDS = %i[first_name
last_name
birth_date
ssn
address_street
address_zip].freeze
OPTIONAL_FIELDS = %i[phone
address_street2
address_city
address_state
address_country
service_error].freeze
FIELDS = (REQUIRED_FIELDS + OPTIONAL_FIELDS).freeze

attr_accessor(*FIELDS)
validate :add_service_error, if: :service_error?
validates(*REQUIRED_FIELDS, presence: true, unless: :service_error?)

validates(*required_fields, presence: true)
def submit
extra = {}
extra = { service_error: service_error } if service_error?

FormResponse.new(
success: validate,
errors: errors,
extra: extra,
)
end

def user_pii
raise 'User PII is invalid' unless valid?
Expand All @@ -30,6 +46,22 @@ def user_pii
user_pii[:zipcode] = address_zip
user_pii
end

def service_error?
service_error.present?
end

private

def add_service_error
errors.add(
:service_provider,
# Use a "safe" error message for the model in case it's displayed
# to the user at any point.
I18n.t('inherited_proofing.errors.service_provider.communication'),
type: :service_error,
)
end
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions app/services/analytics_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,12 @@ def idv_inherited_proofing_get_started_visited(flow_path:, step:, **extra)
)
end

# Retry retrieving the user PII in the case where the first attempt fails
# in the agreement step, and the user initiates a "retry".
def idv_inherited_proofing_redo_retrieve_user_info_submitted(**extra)
track_event('IdV: inherited proofing retry retrieve user information submitted', **extra)
end

# @param [String] flow_path Document capture path ("hybrid" or "standard")
# The user visited the in person proofing location step
def idv_in_person_location_visited(flow_path:, **extra)
Expand Down
2 changes: 2 additions & 0 deletions app/services/flow/base_flow.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Flow
class BaseFlow
include Failure

attr_accessor :flow_session
attr_reader :steps, :actions, :current_user, :current_sp, :params, :request, :json,
:http_status, :controller
Expand Down
8 changes: 1 addition & 7 deletions app/services/flow/base_step.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Flow
class BaseStep
include Rails.application.routes.url_helpers
include Failure

def initialize(flow, name)
@flow = flow
Expand Down Expand Up @@ -51,13 +52,6 @@ def form_submit
FormResponse.new(success: true)
end

def failure(message, extra = nil)
flow_session[:error_message] = message
form_response_params = { success: false, errors: { message: message } }
form_response_params[:extra] = extra unless extra.nil?
FormResponse.new(**form_response_params)
end

def flow_params
params[@name]
end
Expand Down
12 changes: 12 additions & 0 deletions app/services/flow/failure.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Flow
module Failure
private

def failure(message, extra = nil)
flow_session[:error_message] = message
form_response_params = { success: false, errors: { message: message } }
form_response_params[:extra] = extra unless extra.nil?
FormResponse.new(**form_response_params)
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Idv
module Actions
module InheritedProofing
class RedoRetrieveUserInfoAction < Idv::Steps::InheritedProofing::VerifyWaitStepShow
class << self
def analytics_submitted_event
:idv_inherited_proofing_redo_retrieve_user_info_submitted
end
end

def call
enqueue_job unless api_call_already_in_progress?

super
end
end
end
end
end
4 changes: 3 additions & 1 deletion app/services/idv/flows/inherited_proofing_flow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class InheritedProofingFlow < Flow::BaseFlow
{ name: :secure_account },
].freeze

ACTIONS = {}.freeze
ACTIONS = {
redo_retrieve_user_info: Idv::Actions::InheritedProofing::RedoRetrieveUserInfoAction,
}.freeze

attr_reader :idv_session

Expand Down
2 changes: 1 addition & 1 deletion app/services/idv/inherited_proofing/va/mocks/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Service
}.freeze

ERROR_HASH = {
errors: 'InheritedProofing::Errors::MHVIdentityDataNotFoundError',
service_error: 'the server responded with status 401',
}.freeze

def initialize(service_provider_data)
Expand Down
27 changes: 25 additions & 2 deletions app/services/idv/inherited_proofing/va/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,35 @@ def initialize(service_provider_data)
def execute
raise 'The provided auth_code is blank?' if auth_code.blank?

response = request
payload_to_hash decrypt_payload(response)
begin
response = request
return payload_to_hash decrypt_payload(response) if response.status == 200

service_error(not_200_service_error(response.status))
rescue => error
service_error(error.message)
end
end

private

def service_error(message)
{ service_error: message }
end

def not_200_service_error(http_status)
# Under certain circumstances, Faraday may return a nil http status.
# https://lostisland.github.io/faraday/middleware/raise-error
if http_status.blank?
http_status = 'unavailable'
http_status_description = 'unavailable'
else
http_status_description = Rack::Utils::HTTP_STATUS_CODES[http_status]
end
"The service provider API returned an http status other than 200: " \
"#{http_status} (#{http_status_description})"
end

def request
connection.get(request_uri) { |req| req.headers = request_headers }
end
Expand Down
24 changes: 2 additions & 22 deletions app/services/idv/steps/inherited_proofing/agreement_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module Idv
module Steps
module InheritedProofing
class AgreementStep < VerifyBaseStep
include UserPiiJobInitiator

delegate :controller, :idv_session, to: :@flow
STEP_INDICATOR_STEP = :getting_started

Expand All @@ -24,28 +26,6 @@ def form_submit
def consent_form_params
params.require(:inherited_proofing).permit(:ial2_consent_given)
end

def enqueue_job
return if api_call_already_in_progress?

doc_capture_session = create_document_capture_session(
inherited_proofing_verify_step_document_capture_session_uuid_key,
)

doc_capture_session.create_proofing_session

InheritedProofingJob.perform_later(
controller.inherited_proofing_service_provider,
controller.inherited_proofing_service_provider_data,
doc_capture_session.uuid,
)
end

def api_call_already_in_progress?
DocumentCaptureSession.find_by(
uuid: flow_session['inherited_proofing_verify_step_document_capture_session_uuid'],
)&.in_progress?
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Idv
module Steps
module InheritedProofing
module UserPiiJobInitiator
private

def enqueue_job
return if api_call_already_in_progress?

create_document_capture_session(
inherited_proofing_verify_step_document_capture_session_uuid_key,
).tap do |doc_capture_session|
doc_capture_session.create_proofing_session

InheritedProofingJob.perform_later(
controller.inherited_proofing_service_provider,
controller.inherited_proofing_service_provider_data,
doc_capture_session.uuid,
)
end
end

def api_call_already_in_progress?
DocumentCaptureSession.find_by(
uuid: flow_session[inherited_proofing_verify_step_document_capture_session_uuid_key],
).present?
end

def delete_async
flow_session.delete(inherited_proofing_verify_step_document_capture_session_uuid_key)
end
end
end
end
end
Loading