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
19 changes: 10 additions & 9 deletions app/services/proofing/resolution/plugins/aamva_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class AamvaPlugin
def call(
applicant_pii:,
current_sp:,
instant_verify_result:,
instant_verify_state_id_address_result:,
ipp_enrollment_in_progress:,
timer:
)
should_proof = should_proof_state_id_with_aamva?(
applicant_pii:,
instant_verify_result:,
instant_verify_state_id_address_result:,
ipp_enrollment_in_progress:,
)

Expand Down Expand Up @@ -87,34 +87,35 @@ def same_address_as_id?(applicant_pii)

def should_proof_state_id_with_aamva?(
applicant_pii:,
instant_verify_result:,
instant_verify_state_id_address_result:,
ipp_enrollment_in_progress:
)
return false unless aamva_supports_state_id_jurisdiction?(applicant_pii)
# If the user is in in-person-proofing and they have changed their address then
# they are not eligible for get-to-yes
if !ipp_enrollment_in_progress || same_address_as_id?(applicant_pii)
user_can_pass_after_state_id_check?(instant_verify_result:)
user_can_pass_after_state_id_check?(instant_verify_state_id_address_result:)
else
instant_verify_result.success?
instant_verify_state_id_address_result.success?
end
end

def user_can_pass_after_state_id_check?(
instant_verify_result:
instant_verify_state_id_address_result:
)
return true if instant_verify_result.success?
return true if instant_verify_state_id_address_result.success?

# For failed IV results, this method validates that the user is eligible to pass if the
# failed attributes are covered by the same attributes in a successful AAMVA response
# aka the Get-to-Yes w/ AAMVA feature.
if !instant_verify_result.failed_result_can_pass_with_additional_verification?
if !instant_verify_state_id_address_result.
failed_result_can_pass_with_additional_verification?
return false
end

attributes_aamva_can_pass = [:address, :dob, :state_id_number]
attributes_requiring_additional_verification =
instant_verify_result.attributes_requiring_additional_verification
instant_verify_state_id_address_result.attributes_requiring_additional_verification
results_that_cannot_pass_aamva =
attributes_requiring_additional_verification - attributes_aamva_can_pass

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# frozen_string_literal: true

module Proofing
module Resolution
module Plugins
class InstantVerifyStateIdAddressPlugin
SECONDARY_ID_ADDRESS_MAP = {
identity_doc_address1: :address1,
identity_doc_address2: :address2,
identity_doc_city: :city,
identity_doc_address_state: :state,
identity_doc_zipcode: :zipcode,
}.freeze

def call(
applicant_pii:,
current_sp:,
instant_verify_residential_address_result:,
ipp_enrollment_in_progress:,
timer:
)
if same_address_as_id?(applicant_pii) && ipp_enrollment_in_progress
return instant_verify_residential_address_result
end

return resolution_cannot_pass unless instant_verify_residential_address_result.success?

applicant_pii_with_state_id_address =
if ipp_enrollment_in_progress
with_state_id_address(applicant_pii)
else
applicant_pii
end

timer.time('resolution') do
proofer.proof(applicant_pii_with_state_id_address)
end.tap do |result|
Db::SpCost::AddSpCost.call(
current_sp,
:lexis_nexis_resolution,
transaction_id: result.transaction_id,
)
end
end

def proofer
@proofer ||=
if IdentityConfig.store.proofer_mock_fallback
Proofing::Mock::ResolutionMockClient.new
else
Proofing::LexisNexis::InstantVerify::Proofer.new(
instant_verify_workflow: IdentityConfig.store.lexisnexis_instant_verify_workflow,
account_id: IdentityConfig.store.lexisnexis_account_id,
base_url: IdentityConfig.store.lexisnexis_base_url,
username: IdentityConfig.store.lexisnexis_username,
password: IdentityConfig.store.lexisnexis_password,
hmac_key_id: IdentityConfig.store.lexisnexis_hmac_key_id,
hmac_secret_key: IdentityConfig.store.lexisnexis_hmac_secret_key,
request_mode: IdentityConfig.store.lexisnexis_request_mode,
)
end
end

def resolution_cannot_pass
Proofing::Resolution::Result.new(
success: false, errors: {}, exception: nil, vendor_name: 'ResolutionCannotPass',
)
end

def same_address_as_id?(applicant_pii)
applicant_pii[:same_address_as_id].to_s == 'true'
end

# Make a copy of pii with the user's state ID address overwriting the address keys
# Need to first remove the address keys to avoid key/value collision
def with_state_id_address(pii)
pii.except(*SECONDARY_ID_ADDRESS_MAP.values).
transform_keys(SECONDARY_ID_ADDRESS_MAP)
end
end
end
end
end
103 changes: 15 additions & 88 deletions app/services/proofing/resolution/progressive_proofer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ module Resolution
# 2. The user has only provided one address for their residential and identity document
# address or separate residential and identity document addresses
class ProgressiveProofer
attr_reader :applicant_pii, :timer, :current_sp
attr_reader :aamva_plugin,
:instant_verify_residential_address_plugin,
:instant_verify_state_id_address_plugin,
:threatmetrix_plugin

def initialize
@aamva_plugin = Plugins::AamvaPlugin.new
@instant_verify_residential_address_plugin =
Plugins::InstantVerifyResidentialAddressPlugin.new
@instant_verify_state_id_address_plugin =
Plugins::InstantVerifyStateIdAddressPlugin.new
@threatmetrix_plugin = Plugins::ThreatMetrixPlugin.new
end

Expand All @@ -37,10 +39,7 @@ def proof(
ipp_enrollment_in_progress:,
current_sp:
)
@applicant_pii = applicant_pii.except(:best_effort_phone_number_for_socure)
@timer = timer
@ipp_enrollment_in_progress = ipp_enrollment_in_progress
@current_sp = current_sp
applicant_pii = applicant_pii.except(:best_effort_phone_number_for_socure)

device_profiling_result = threatmetrix_plugin.call(
applicant_pii:,
Expand All @@ -51,112 +50,40 @@ def proof(
user_email:,
)

@residential_instant_verify_result = instant_verify_residential_address_plugin.call(
instant_verify_residential_address_result = instant_verify_residential_address_plugin.call(
applicant_pii:,
current_sp:,
ipp_enrollment_in_progress:,
timer:,
)

@instant_verify_result = proof_id_address_with_lexis_nexis_if_needed
instant_verify_state_id_address_result = instant_verify_state_id_address_plugin.call(
applicant_pii:,
current_sp:,
instant_verify_residential_address_result:,
ipp_enrollment_in_progress:,
timer:,
)

state_id_result = aamva_plugin.call(
applicant_pii:,
current_sp:,
instant_verify_result:,
instant_verify_state_id_address_result:,
ipp_enrollment_in_progress:,
timer:,
)

ResultAdjudicator.new(
device_profiling_result: device_profiling_result,
ipp_enrollment_in_progress: ipp_enrollment_in_progress,
resolution_result: instant_verify_result,
resolution_result: instant_verify_state_id_address_result,
should_proof_state_id: aamva_plugin.aamva_supports_state_id_jurisdiction?(applicant_pii),
state_id_result: state_id_result,
residential_resolution_result: residential_instant_verify_result,
residential_resolution_result: instant_verify_residential_address_result,
same_address_as_id: applicant_pii[:same_address_as_id],
applicant_pii: applicant_pii,
)
end

private

attr_reader :device_profiling_result,
:residential_instant_verify_result,
:instant_verify_result

def resolution_cannot_pass
Proofing::Resolution::Result.new(
success: false, errors: {}, exception: nil, vendor_name: 'ResolutionCannotPass',
)
end

def proof_id_address_with_lexis_nexis_if_needed
if same_address_as_id? && ipp_enrollment_in_progress?
return residential_instant_verify_result
end
return resolution_cannot_pass unless residential_instant_verify_result.success?

timer.time('resolution') do
resolution_proofer.proof(applicant_pii_with_state_id_address)
end.tap do |result|
add_sp_cost(:lexis_nexis_resolution, result.transaction_id)
end
end

def same_address_as_id?
applicant_pii[:same_address_as_id].to_s == 'true'
end

def ipp_enrollment_in_progress?
@ipp_enrollment_in_progress
end

def resolution_proofer
@resolution_proofer ||=
if IdentityConfig.store.proofer_mock_fallback
Proofing::Mock::ResolutionMockClient.new
else
Proofing::LexisNexis::InstantVerify::Proofer.new(
instant_verify_workflow: IdentityConfig.store.lexisnexis_instant_verify_workflow,
account_id: IdentityConfig.store.lexisnexis_account_id,
base_url: IdentityConfig.store.lexisnexis_base_url,
username: IdentityConfig.store.lexisnexis_username,
password: IdentityConfig.store.lexisnexis_password,
hmac_key_id: IdentityConfig.store.lexisnexis_hmac_key_id,
hmac_secret_key: IdentityConfig.store.lexisnexis_hmac_secret_key,
request_mode: IdentityConfig.store.lexisnexis_request_mode,
)
end
end

def applicant_pii_with_state_id_address
if ipp_enrollment_in_progress?
with_state_id_address(applicant_pii)
else
applicant_pii
end
end

def add_sp_cost(token, transaction_id)
Db::SpCost::AddSpCost.call(current_sp, token, transaction_id: transaction_id)
end

# Make a copy of pii with the user's state ID address overwriting the address keys
# Need to first remove the address keys to avoid key/value collision
def with_state_id_address(pii)
pii.except(*SECONDARY_ID_ADDRESS_MAP.values).
transform_keys(SECONDARY_ID_ADDRESS_MAP)
end

SECONDARY_ID_ADDRESS_MAP = {
identity_doc_address1: :address1,
identity_doc_address2: :address2,
identity_doc_city: :city,
identity_doc_address_state: :state,
identity_doc_zipcode: :zipcode,
}.freeze
end
end
end
22 changes: 11 additions & 11 deletions spec/services/proofing/resolution/plugins/aamva_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe Proofing::Resolution::Plugins::AamvaPlugin do
let(:applicant_pii) { Idp::Constants::MOCK_IDV_APPLICANT_WITH_SSN }
let(:current_sp) { build(:service_provider) }
let(:instant_verify_result) { nil }
let(:instant_verify_state_id_address_result) { nil }
let(:ipp_enrollment_in_progress) { false }
let(:proofer) { instance_double(Proofing::Aamva::Proofer, proof: proofer_result) }
let(:proofer_result) do
Expand Down Expand Up @@ -40,7 +40,7 @@ def sp_cost_count_with_transaction_id
plugin.call(
applicant_pii:,
current_sp:,
instant_verify_result:,
instant_verify_state_id_address_result:,
ipp_enrollment_in_progress:,
timer: JobHelpers::Timer.new,
)
Expand All @@ -60,7 +60,7 @@ def sp_cost_count_with_transaction_id
end

context 'InstantVerify succeeded' do
let(:instant_verify_result) do
let(:instant_verify_state_id_address_result) do
Proofing::Resolution::Result.new(
success: true,
vendor_name: 'lexisnexis:instant_verify',
Expand Down Expand Up @@ -96,7 +96,7 @@ def sp_cost_count_with_transaction_id

context 'InstantVerify failed' do
context 'and the failure can possibly be covered by AAMVA' do
let(:instant_verify_result) do
let(:instant_verify_state_id_address_result) do
Proofing::Resolution::Result.new(
success: false,
vendor_name: 'lexisnexis:instant_verify',
Expand All @@ -120,7 +120,7 @@ def sp_cost_count_with_transaction_id
end

context 'but the failure cannot be covered by AAMVA' do
let(:instant_verify_result) do
let(:instant_verify_state_id_address_result) do
Proofing::Resolution::Result.new(
success: false,
vendor_name: 'lexisnexis:instant_verify',
Expand Down Expand Up @@ -164,7 +164,7 @@ def sp_cost_count_with_transaction_id
context 'residential address same as id address' do
let(:applicant_pii) { Idp::Constants::MOCK_IDV_APPLICANT_SAME_ADDRESS_AS_ID }

let(:instant_verify_result) do
let(:instant_verify_state_id_address_result) do
Proofing::Resolution::Result.new(
success: true,
vendor_name: 'lexisnexis:instant_verify',
Expand All @@ -184,7 +184,7 @@ def sp_cost_count_with_transaction_id

context 'InstantVerify failed' do
context 'and the failure can possibly be covered by AAMVA' do
let(:instant_verify_result) do
let(:instant_verify_state_id_address_result) do
Proofing::Resolution::Result.new(
success: false,
vendor_name: 'lexisnexis:instant_verify',
Expand All @@ -204,7 +204,7 @@ def sp_cost_count_with_transaction_id
end

context 'but the failure cannot be covered by AAMVA' do
let(:instant_verify_result) do
let(:instant_verify_state_id_address_result) do
Proofing::Resolution::Result.new(
success: false,
vendor_name: 'lexisnexis:instant_verify',
Expand Down Expand Up @@ -236,7 +236,7 @@ def sp_cost_count_with_transaction_id

context 'InstantVerify succeeded for residential address' do
context 'and InstantVerify passed for id address' do
let(:instant_verify_result) do
let(:instant_verify_state_id_address_result) do
Proofing::Resolution::Result.new(
success: true,
vendor_name: 'lexisnexis:instant_verify',
Expand All @@ -255,7 +255,7 @@ def sp_cost_count_with_transaction_id

context 'and InstantVerify failed for state id address' do
context 'but the failure can possibly be covered by AAMVA' do
let(:instant_verify_result) do
let(:instant_verify_state_id_address_result) do
Proofing::Resolution::Result.new(
success: false,
vendor_name: 'lexisnexis:instant_verify',
Expand All @@ -275,7 +275,7 @@ def sp_cost_count_with_transaction_id
end

context 'and the failure cannot be covered by AAMVA' do
let(:instant_verify_result) do
let(:instant_verify_state_id_address_result) do
Proofing::Resolution::Result.new(
success: false,
vendor_name: 'lexisnexis:instant_verify',
Expand Down
Loading