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
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ module Idv
module HybridMobile
module Socure
class DocumentCaptureController < ApplicationController
include Idv::AvailabilityConcern
include AvailabilityConcern
include DocumentCaptureConcern
include Idv::HybridMobile::HybridMobileConcern
include RenderConditionConcern
include DocumentCaptureConcern

check_or_render_not_found -> { IdentityConfig.store.socure_docv_enabled }
before_action :check_valid_document_capture_session, except: [:update]
Expand Down Expand Up @@ -50,17 +49,64 @@ def show
end

def update
return if wait_for_result?

result = handle_stored_result(
user: document_capture_session.user,
store_in_session: false,
)
# TODO: new analytics event?
analytics.idv_doc_auth_document_capture_submitted(
**result.to_h.merge(analytics_arguments),
)

if result.success?
redirect_to idv_hybrid_mobile_capture_complete_url
else
redirect_to idv_hybrid_mobile_socure_document_capture_url
end
end

private

def wait_for_result?
return false if stored_result.present?

# If the stored_result is nil, the job fetching the results has not completed.
analytics.idv_doc_auth_document_capture_polling_wait_visited(**analytics_arguments)
if wait_timed_out?
# flash[:error] = I18n.t('errors.doc_auth.polling_timeout')
# TODO: redirect to try again page LG-14873/14952/15059
render plain: 'Technical difficulties!!!', status: :ok
else
@refresh_interval =
IdentityConfig.store.doc_auth_socure_wait_polling_refresh_max_seconds
render 'idv/socure/document_capture/wait'
end

true
end

def wait_timed_out?
if session[:socure_docv_wait_polling_started_at].nil?
session[:socure_docv_wait_polling_started_at] = Time.zone.now.to_s
return false
end
start = DateTime.parse(session[:socure_docv_wait_polling_started_at])
timeout_period =
IdentityConfig.store.doc_auth_socure_wait_polling_timeout_minutes.minutes || 2.minutes
start + timeout_period < Time.zone.now
end

def analytics_arguments
{
flow_path: 'hybrid',
step: 'socure_document_capture',
analytics_id: 'Doc Auth',
liveness_checking_required: false,
selfie_check_required: false,
}
end
end
end
end
Expand Down
38 changes: 21 additions & 17 deletions app/controllers/idv/socure/document_capture_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,13 @@ def show
end

def update
return if wait_for_result?

clear_future_steps!
idv_session.redo_document_capture = nil # done with this redo
# Not used in standard flow, here for data consistency with hybrid flow.
document_capture_session.confirm_ocr

# If the stored_result is nil, the job fetching the results has not completed.
if stored_result.nil?
analytics.idv_doc_auth_document_capture_polling_wait_visited(**analytics_arguments)
if wait_timed_out?
# flash[:error] = I18n.t('errors.doc_auth.polling_timeout')
# TODO: redirect to try again page LG-14873/14952/15059
render plain: 'Technical difficulties!!!', status: :ok
else
@refresh_interval =
IdentityConfig.store.doc_auth_socure_wait_polling_refresh_max_seconds
render 'idv/socure/document_capture/wait'
end

return
end

result = handle_stored_result
# TODO: new analytics event?
analytics.idv_doc_auth_document_capture_submitted(**result.to_h.merge(analytics_arguments))
Expand Down Expand Up @@ -121,14 +107,32 @@ def self.step_info

private

def wait_for_result?
return false if stored_result.present?

# If the stored_result is nil, the job fetching the results has not completed.
analytics.idv_doc_auth_document_capture_polling_wait_visited(**analytics_arguments)
if wait_timed_out?
# flash[:error] = I18n.t('errors.doc_auth.polling_timeout')
# TODO: redirect to try again page LG-14873/14952/15059
render plain: 'Technical difficulties!!!', status: :ok
else
@refresh_interval =
IdentityConfig.store.doc_auth_socure_wait_polling_refresh_max_seconds
render 'idv/socure/document_capture/wait'
end

true
end

def wait_timed_out?
if idv_session.socure_docv_wait_polling_started_at.nil?
idv_session.socure_docv_wait_polling_started_at = Time.zone.now.to_s
return false
end
start = DateTime.parse(idv_session.socure_docv_wait_polling_started_at)
timeout_period =
IdentityConfig.store.doc_auth_socure_wait_polling_timeout_minutes.minutes || 5.minutes
IdentityConfig.store.doc_auth_socure_wait_polling_timeout_minutes.minutes || 2.minutes
start + timeout_period < Time.zone.now
end

Expand Down
4 changes: 2 additions & 2 deletions app/services/analytics_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1255,10 +1255,10 @@ def idv_doc_auth_document_capture_polling_wait_visited(
flow_path:,
step:,
analytics_id:,
redo_document_capture:,
skip_hybrid_handoff:,
liveness_checking_required:,
selfie_check_required:,
redo_document_capture: nil,
skip_hybrid_handoff: nil,
opted_in_to_in_person_proofing: nil,
acuant_sdk_upgrade_ab_test_bucket: nil,
**extra
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

session[:doc_capture_user_id] = user&.id
session[:document_capture_session_uuid] = document_capture_session_uuid

stub_analytics
end

describe 'before_actions' do
Expand Down Expand Up @@ -273,6 +275,7 @@
get(:update)

expect(response).to redirect_to(idv_hybrid_mobile_capture_complete_url)
expect(@analytics).to have_logged_event('IdV: doc auth document_capture submitted')
end

context 'when socure is disabled' do
Expand All @@ -298,6 +301,30 @@
get(:update)

expect(response).to redirect_to(idv_hybrid_mobile_socure_document_capture_url)
expect(@analytics).to have_logged_event('IdV: doc auth document_capture submitted')
end
end

context 'when stored result is nil' do
let(:stored_result) { nil }

it 'renders the wait view' do
get(:update)

expect(response).to render_template('idv/socure/document_capture/wait')
expect(@analytics).to have_logged_event(:idv_doc_auth_document_capture_polling_wait_visited)
end

context 'when the wait times out' do
before do
allow(subject).to receive(:wait_timed_out?).and_return(true)
end

it 'renders a technical difficulties message' do
get(:update)
expect(response).to have_http_status(:ok)
expect(response.body).to eq('Technical difficulties!!!')
end
end
end
end
Expand Down