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
133 changes: 133 additions & 0 deletions app/services/proofing/resolution/plugins/aamva_plugin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# frozen_string_literal: true

module Proofing
module Resolution
module Plugins
class AamvaPlugin
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_result:,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that in the IPP + different addresses case, if the residential address failed verification, then instant_verify_result will have success: false and vendor_name: ResolutionCannotPass, so no AAMVA call will be made.

ipp_enrollment_in_progress:,
timer:
)
should_proof = should_proof_state_id_with_aamva?(
applicant_pii:,
instant_verify_result:,
ipp_enrollment_in_progress:,
)

if !should_proof
return out_of_aamva_jurisdiction_result
end

applicant_pii_with_state_id_address =
if ipp_enrollment_in_progress
with_state_id_address(applicant_pii)
else
applicant_pii
end

timer.time('state_id') do
proofer.proof(applicant_pii_with_state_id_address)
end.tap do |result|
if result.exception.blank?
Db::SpCost::AddSpCost.call(
current_sp,
:aamva,
transaction_id: result.transaction_id,
)
end
end
end

def aamva_supports_state_id_jurisdiction?(applicant_pii)
state_id_jurisdiction = applicant_pii[:state_id_jurisdiction]
IdentityConfig.store.aamva_supported_jurisdictions.include?(state_id_jurisdiction)
Comment thread
matthinz marked this conversation as resolved.
Outdated
end

def out_of_aamva_jurisdiction_result
Proofing::StateIdResult.new(
errors: {},
exception: nil,
success: true,
vendor_name: 'UnsupportedJurisdiction',
)
end

def proofer
@proofer ||=
if IdentityConfig.store.proofer_mock_fallback
Proofing::Mock::StateIdMockClient.new
else
Proofing::Aamva::Proofer.new(
auth_request_timeout: IdentityConfig.store.aamva_auth_request_timeout,
auth_url: IdentityConfig.store.aamva_auth_url,
cert_enabled: IdentityConfig.store.aamva_cert_enabled,
private_key: IdentityConfig.store.aamva_private_key,
public_key: IdentityConfig.store.aamva_public_key,
verification_request_timeout:
IdentityConfig.store.aamva_verification_request_timeout,
verification_url: IdentityConfig.store.aamva_verification_url,
)
end
end

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

def should_proof_state_id_with_aamva?(
applicant_pii:,
instant_verify_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:)
else
instant_verify_result.success?
end
end

def user_can_pass_after_state_id_check?(
instant_verify_result:
)
return true if instant_verify_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?
return false
end

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

results_that_cannot_pass_aamva.blank?
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
87 changes: 12 additions & 75 deletions app/services/proofing/resolution/progressive_proofer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ module Resolution
# address or separate residential and identity document addresses
class ProgressiveProofer
attr_reader :applicant_pii, :timer, :current_sp
attr_reader :threatmetrix_plugin
attr_reader :aamva_plugin, :threatmetrix_plugin

def initialize
@aamva_plugin = Plugins::AamvaPlugin.new
@threatmetrix_plugin = Plugins::ThreatMetrixPlugin.new
end

Expand Down Expand Up @@ -48,13 +49,20 @@ def proof(

@residential_instant_verify_result = proof_residential_address_if_needed
@instant_verify_result = proof_id_address_with_lexis_nexis_if_needed
@state_id_result = proof_id_with_aamva_if_needed

state_id_result = aamva_plugin.call(
applicant_pii:,
current_sp:,
instant_verify_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,
should_proof_state_id: aamva_supports_state_id_jurisdiction?,
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,
same_address_as_id: applicant_pii[:same_address_as_id],
Expand All @@ -66,8 +74,7 @@ def proof(

attr_reader :device_profiling_result,
:residential_instant_verify_result,
:instant_verify_result,
:state_id_result
:instant_verify_result

def proof_residential_address_if_needed
return residential_address_unnecessary_result unless ipp_enrollment_in_progress?
Expand Down Expand Up @@ -104,50 +111,6 @@ def proof_id_address_with_lexis_nexis_if_needed
end
end

def should_proof_state_id_with_aamva?
return false unless aamva_supports_state_id_jurisdiction?
# 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?
user_can_pass_after_state_id_check?
else
residential_instant_verify_result.success?
end
end

def aamva_supports_state_id_jurisdiction?
state_id_jurisdiction = applicant_pii[:state_id_jurisdiction]
IdentityConfig.store.aamva_supported_jurisdictions.include?(state_id_jurisdiction)
end

def proof_id_with_aamva_if_needed
return out_of_aamva_jurisdiction_result unless should_proof_state_id_with_aamva?

timer.time('state_id') do
state_id_proofer.proof(applicant_pii_with_state_id_address)
end.tap do |result|
add_sp_cost(:aamva, result.transaction_id) if result.exception.blank?
end
end

def user_can_pass_after_state_id_check?
return true if instant_verify_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?
return false
end

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

results_that_cannot_pass_aamva.blank?
end

def same_address_as_id?
applicant_pii[:same_address_as_id].to_s == 'true'
end
Expand All @@ -156,15 +119,6 @@ def ipp_enrollment_in_progress?
@ipp_enrollment_in_progress
end

def out_of_aamva_jurisdiction_result
Proofing::StateIdResult.new(
errors: {},
exception: nil,
success: true,
vendor_name: 'UnsupportedJurisdiction',
)
end

def resolution_proofer
@resolution_proofer ||=
if IdentityConfig.store.proofer_mock_fallback
Expand All @@ -183,23 +137,6 @@ def resolution_proofer
end
end

def state_id_proofer
@state_id_proofer ||=
if IdentityConfig.store.proofer_mock_fallback
Proofing::Mock::StateIdMockClient.new
else
Proofing::Aamva::Proofer.new(
auth_request_timeout: IdentityConfig.store.aamva_auth_request_timeout,
auth_url: IdentityConfig.store.aamva_auth_url,
cert_enabled: IdentityConfig.store.aamva_cert_enabled,
private_key: IdentityConfig.store.aamva_private_key,
public_key: IdentityConfig.store.aamva_public_key,
verification_request_timeout: IdentityConfig.store.aamva_verification_request_timeout,
verification_url: IdentityConfig.store.aamva_verification_url,
)
end
end

def applicant_pii_with_state_id_address
if ipp_enrollment_in_progress?
with_state_id_address(applicant_pii)
Expand Down
2 changes: 1 addition & 1 deletion lib/aamva_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ def with_cleared_auth_token_cache
end

def build_proofer
Proofing::Resolution::ProgressiveProofer.new.send(:state_id_proofer)
Proofing::Resolution::Plugins::AamvaPlugin.new.send(:proofer)
end
end
Loading