diff --git a/app/controllers/idv/hybrid_mobile/socure/document_capture_controller.rb b/app/controllers/idv/hybrid_mobile/socure/document_capture_controller.rb index 6dfd7980241..243c4e5d598 100644 --- a/app/controllers/idv/hybrid_mobile/socure/document_capture_controller.rb +++ b/app/controllers/idv/hybrid_mobile/socure/document_capture_controller.rb @@ -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] @@ -50,10 +49,16 @@ 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 @@ -61,6 +66,47 @@ def update 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 diff --git a/app/controllers/idv/socure/document_capture_controller.rb b/app/controllers/idv/socure/document_capture_controller.rb index b93ec65334c..1f764f64856 100644 --- a/app/controllers/idv/socure/document_capture_controller.rb +++ b/app/controllers/idv/socure/document_capture_controller.rb @@ -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)) @@ -121,6 +107,24 @@ 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 @@ -128,7 +132,7 @@ def wait_timed_out? 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 diff --git a/app/services/analytics_events.rb b/app/services/analytics_events.rb index f5ace1ca583..2cbeac6bd13 100644 --- a/app/services/analytics_events.rb +++ b/app/services/analytics_events.rb @@ -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 diff --git a/spec/controllers/idv/hybrid_mobile/socure/document_capture_controller_spec.rb b/spec/controllers/idv/hybrid_mobile/socure/document_capture_controller_spec.rb index 60b77e84bdb..ba96dbcfbb4 100644 --- a/spec/controllers/idv/hybrid_mobile/socure/document_capture_controller_spec.rb +++ b/spec/controllers/idv/hybrid_mobile/socure/document_capture_controller_spec.rb @@ -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 @@ -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 @@ -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