-
Notifications
You must be signed in to change notification settings - Fork 166
ProgressiveProofer refactor 2/N: AAMVA #11427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
app/services/proofing/resolution/plugins/aamva_plugin.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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:, | ||
| 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) | ||
|
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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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: falseandvendor_name: ResolutionCannotPass, so no AAMVA call will be made.