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
14 changes: 6 additions & 8 deletions app/controllers/idv/phone_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ class PhoneController < ApplicationController
def new
async_state = step.async_state

case async_state.status
when :none
if async_state.none?
analytics.track_event(Analytics::IDV_PHONE_RECORD_VISIT)
render :new
when :in_progress
elsif async_state.in_progress?
render :wait
when :timed_out
elsif async_state.timed_out?
flash[:info] = I18n.t('idv.failure.timeout')
render :new
when :done
elsif async_state.done?
async_state_done(async_state)
end
end
Expand Down Expand Up @@ -51,8 +50,7 @@ def submit_proofing_attempt
step.submit(step_params.to_h)
end

def handle_proofing_failure(pii)
idv_session.previous_phone_step_params = { 'phone' => pii[:phone] }
def handle_proofing_failure
redirect_to failure_url(step.failure_reason)
end

Expand Down Expand Up @@ -96,7 +94,7 @@ def async_state_done(async_state)
form_result = step.async_state_done(async_state)
analytics.track_event(Analytics::IDV_PHONE_CONFIRMATION_VENDOR, form_result.to_h)
redirect_to_next_step and return if async_state.result[:success]
handle_proofing_failure(async_state.pii)
handle_proofing_failure
end
end
end
55 changes: 22 additions & 33 deletions app/controllers/idv/usps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ class UspsController < ApplicationController

def index
@presenter = UspsPresenter.new(current_user)
current_async_state = async_state

case async_state.status
when :none
if current_async_state.none?
analytics.track_event(Analytics::IDV_USPS_ADDRESS_VISITED)
render :index
when :in_progress
elsif current_async_state.in_progress?
render :wait
when :timed_out
elsif current_async_state.timed_out?
render :index
when :done
async_state_done(async_state)
elsif current_async_state.done?
async_state_done(current_async_state)
end
end

Expand Down Expand Up @@ -58,24 +58,14 @@ def failure
redirect_to idv_usps_url unless performed?
end

def pii
hash = {}
update_hash_with_address(hash)
update_hash_with_non_address_pii(hash)
hash
def pii(address_pii)
address_pii.dup.merge(non_address_pii)
end

def update_hash_with_address(hash)
profile_params.each { |key, value| hash[key] = value }
end

def update_hash_with_non_address_pii(hash)
pii_h = pii_to_h
%w[first_name middle_name last_name dob phone ssn].each do |key|
hash[key] = pii_h[key]
end

hash[:uuid_prefix] = ServiceProvider.from_issuer(sp_session[:issuer]).app_id
def non_address_pii
pii_to_h.
slice('first_name', 'middle_name', 'last_name', 'dob', 'phone', 'ssn').
merge(uuid_prefix: ServiceProvider.from_issuer(sp_session[:issuer]).app_id)
end

def pii_to_h
Expand Down Expand Up @@ -183,16 +173,19 @@ def send_reminder

def enqueue_job
return if idv_session.idv_usps_document_capture_session_uuid
idv_session.previous_usps_step_params = profile_params.to_h

document_capture_session = DocumentCaptureSession.create(
user_id: current_user.id,
issuer: sp_session[:issuer],
ial2_strict: sp_session[:ial2_strict],
requested_at: Time.zone.now,
)

document_capture_session.store_proofing_pii_from_doc(pii)
document_capture_session.create_proofing_session
idv_session.idv_usps_document_capture_session_uuid = document_capture_session.uuid
Idv::Agent.new(pii).proof_resolution(
applicant = pii(profile_params.to_h)
Idv::Agent.new(applicant).proof_resolution(
document_capture_session,
should_proof_state_id: false,
trace_id: amzn_trace_id,
Expand All @@ -202,17 +195,13 @@ def enqueue_job
def async_state
dcs_uuid = idv_session.idv_usps_document_capture_session_uuid
dcs = DocumentCaptureSession.find_by(uuid: dcs_uuid)
return ProofingDocumentCaptureSessionResult.none if dcs_uuid.nil?
return ProofingSessionAsyncResult.none if dcs_uuid.nil?
return timed_out if dcs.nil?

proofing_job_result = dcs.load_proofing_result
return timed_out if proofing_job_result.nil?

if proofing_job_result.result
proofing_job_result.done
elsif proofing_job_result.pii
ProofingDocumentCaptureSessionResult.in_progress
end
proofing_job_result
end

def async_state_done(async_state)
Expand All @@ -222,11 +211,11 @@ def async_state_done(async_state)
throttle_failure unless success
result = form_response(idv_result, success)

pii = async_state.pii
delete_async

async_state_done_analytics(result)
result.success? ? resolution_success(pii) : failure
applicant = pii(idv_session.previous_usps_step_params)
result.success? ? resolution_success(applicant) : failure
end

def async_state_done_analytics(result)
Expand All @@ -242,7 +231,7 @@ def delete_async
def timed_out
flash[:info] = I18n.t('idv.failure.timeout')
delete_async
ProofingDocumentCaptureSessionResult.timed_out
ProofingSessionAsyncResult.timed_out
end
end
end
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
module LambdaCallback
class AddressProofResultController < AuthTokenController
def create
dcs = DocumentCaptureSession.new
dcs.result_id = result_id_parameter
dcs.store_proofing_result(address_result_parameter.to_h)
dcs = DocumentCaptureSession.find_by(result_id: result_id_parameter)

track_exception_in_result(address_result_parameter)
if dcs
dcs.store_proofing_result(address_result_parameter.to_h)

track_exception_in_result(address_result_parameter)
else
NewRelic::Agent.notice_error('AddressProofResult result_id not found')
head :not_found
end
end

private
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
module LambdaCallback
class ResolutionProofResultController < AuthTokenController
def create
dcs = DocumentCaptureSession.new
dcs.result_id = result_id_parameter
dcs.store_proofing_result(resolution_result_parameter)
dcs = DocumentCaptureSession.find_by(result_id: result_id_parameter)

track_exception_in_result(resolution_result_parameter)
if dcs
dcs.store_proofing_result(resolution_result_parameter)

track_exception_in_result(resolution_result_parameter)
else
NewRelic::Agent.notice_error('ResolutionProofResult result_id not found')
head :not_found
end
end

private
Expand Down
21 changes: 9 additions & 12 deletions app/models/document_capture_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ def load_result
EncryptedRedisStructStorage.load(result_id, type: DocumentCaptureSessionResult)
end

def load_proofing_result
EncryptedRedisStructStorage.load(result_id, type: ProofingDocumentCaptureSessionResult)
end

def store_result_from_response(doc_auth_response)
EncryptedRedisStructStorage.store(
DocumentCaptureSessionResult.new(
Expand Down Expand Up @@ -51,11 +47,15 @@ def store_doc_auth_result(result:, pii:)
save!
end

def store_proofing_pii_from_doc(pii_from_doc)
def load_proofing_result
EncryptedRedisStructStorage.load(result_id, type: ProofingSessionAsyncResult)
end

def create_proofing_session
EncryptedRedisStructStorage.store(
ProofingDocumentCaptureSessionResult.new(
ProofingSessionAsyncResult.new(
id: generate_result_id,
pii: pii_from_doc,
status: ProofingSessionAsyncResult::IN_PROGRESS,
result: nil,
),
expires_in: AppConfig.env.async_wait_timeout_seconds.to_i,
Expand All @@ -64,14 +64,11 @@ def store_proofing_pii_from_doc(pii_from_doc)
end

def store_proofing_result(proofing_result)
existing = EncryptedRedisStructStorage.load(result_id,
type: ProofingDocumentCaptureSessionResult)
pii = existing&.pii
EncryptedRedisStructStorage.store(
ProofingDocumentCaptureSessionResult.new(
ProofingSessionAsyncResult.new(
id: result_id,
pii: pii,
result: proofing_result,
status: ProofingSessionAsyncResult::DONE,
),
expires_in: AppConfig.env.async_wait_timeout_seconds.to_i,
)
Expand Down
1 change: 1 addition & 0 deletions app/services/document_capture_session_result.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

# This is used by hybrid doc auth capture
DocumentCaptureSessionResult = Struct.new(:id, :success, :pii, keyword_init: true) do
def self.redis_key_prefix
'dcs:result'
Expand Down
2 changes: 1 addition & 1 deletion app/services/idv/actions/verify_document_status_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def process_async_state(current_async_state)
form_response
end

# @param [ProofingDocumentCaptureSessionResult] async_result
# @param [ProofingSessionAsyncResult] async_result
def async_state_done(async_result)
doc_pii_form_result = Idv::DocPiiForm.new(async_result.pii).submit

Expand Down
41 changes: 19 additions & 22 deletions app/services/idv/phone_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def initialize(idv_session:, trace_id:)

def submit(step_params)
self.step_params = step_params
idv_session.previous_phone_step_params = step_params.slice(:phone)
proof_address
end

Expand All @@ -20,26 +21,21 @@ def failure_reason
def async_state
dcs_uuid = idv_session.idv_phone_step_document_capture_session_uuid
dcs = DocumentCaptureSession.find_by(uuid: dcs_uuid)
return ProofingDocumentCaptureSessionResult.none if dcs_uuid.nil?
return ProofingSessionAsyncResult.none if dcs_uuid.nil?
return timed_out if dcs.nil?

proofing_job_result = dcs.load_proofing_result
return timed_out if proofing_job_result.nil?

if proofing_job_result.result
proofing_job_result.done
elsif proofing_job_result.pii
ProofingDocumentCaptureSessionResult.in_progress
end
proofing_job_result
end

def async_state_done(async_state)
@idv_result = async_state.result
pii = async_state.pii

increment_attempts_count unless failed_due_to_timeout_or_exception?
success = idv_result[:success]
handle_successful_proofing_attempt(pii) if success
handle_successful_proofing_attempt if success
delete_async
FormResponse.new(
success: success, errors: idv_result[:errors],
Expand All @@ -61,16 +57,16 @@ def proof_address
document_capture_session = DocumentCaptureSession.create(user_id: idv_session.current_user.id,
requested_at: Time.zone.now)

document_capture_session.store_proofing_pii_from_doc(applicant)
document_capture_session.create_proofing_session
idv_session.idv_phone_step_document_capture_session_uuid = document_capture_session.uuid

run_job(document_capture_session)
add_proofing_cost
end

def handle_successful_proofing_attempt(successful_applicant)
update_idv_session(successful_applicant)
start_phone_confirmation_session(successful_applicant)
def handle_successful_proofing_attempt
update_idv_session
start_phone_confirmation_session
end

def add_proofing_cost
Expand All @@ -97,9 +93,10 @@ def normalized_phone
end

def phone_param
step_phone = step_params[:phone]
params = step_params || idv_session.previous_phone_step_params
step_phone = params[:phone]
if step_phone == 'other'
step_params[:other_phone]
params[:other_phone]
else
step_phone
end
Expand All @@ -113,24 +110,24 @@ def failed_due_to_timeout_or_exception?
idv_result[:timed_out] || idv_result[:exception]
end

def update_idv_session(successful_applicant)
def update_idv_session
idv_session.address_verification_mechanism = :phone
idv_session.applicant = successful_applicant
idv_session.applicant = applicant
idv_session.vendor_phone_confirmation = true
idv_session.user_phone_confirmation = phone_matches_user_phone?(successful_applicant[:phone])
idv_session.user_phone_confirmation = phone_matches_user_phone?
Db::ProofingComponent::Add.call(idv_session.current_user.id, :address_check,
'lexis_nexis_address')
end

def start_phone_confirmation_session(successful_applicant)
def start_phone_confirmation_session
idv_session.user_phone_confirmation_session = PhoneConfirmation::ConfirmationSession.start(
phone: PhoneFormatter.format(successful_applicant[:phone]),
phone: PhoneFormatter.format(applicant[:phone]),
delivery_method: :sms,
)
end

def phone_matches_user_phone?(phone)
applicant_phone = PhoneFormatter.format(phone)
def phone_matches_user_phone?
applicant_phone = PhoneFormatter.format(applicant[:phone])
return false if applicant_phone.blank?
user_phones.include?(applicant_phone)
end
Expand All @@ -155,7 +152,7 @@ def run_job(document_capture_session)

def timed_out
delete_async
ProofingDocumentCaptureSessionResult.timed_out
ProofingSessionAsyncResult.timed_out
end

def delete_async
Expand Down
1 change: 1 addition & 0 deletions app/services/idv/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Session
pii
previous_phone_step_params
previous_profile_step_params
previous_usps_step_params
profile_confirmation
profile_id
profile_step_params
Expand Down
2 changes: 1 addition & 1 deletion app/services/idv/steps/cac/verify_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def enqueue_job
)

document_capture_session.requested_at = Time.zone.now
document_capture_session.store_proofing_pii_from_doc(pii_from_doc)
document_capture_session.create_proofing_session

Idv::Agent.new(pii_from_doc).proof_resolution(
document_capture_session,
Expand Down
Loading