-
Notifications
You must be signed in to change notification settings - Fork 167
LG-15456: Source AAMVA requested attributes from request #11826
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
Show all changes
5 commits
Select commit
Hold shift + click to select a range
10d9cdf
LG-15456: Source AAMVA requested attributes from request
lmgeorge 41fa2bd
Apply @zachmargolis code quality suggestions
lmgeorge 349d236
Remove dead code
lmgeorge 085cca4
Remove redundant safe navigation
lmgeorge 06c117a
PR feedback: use symbols instead of integers for requested attributes…
lmgeorge 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
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
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 |
|---|---|---|
|
|
@@ -10,27 +10,53 @@ | |
| module Proofing | ||
| module Aamva | ||
| module Request | ||
| RequestAttribute = Data.define(:xpath, :required).freeze | ||
| class VerificationRequest | ||
| CONTENT_TYPE = 'application/soap+xml;charset=UTF-8' | ||
| DEFAULT_VERIFICATION_URL = | ||
| 'https://verificationservices-cert.aamva.org:18449/dldv/2.1/online' | ||
| SOAP_ACTION = | ||
| '"http://aamva.org/dldv/wsdl/2.1/IDLDVService21/VerifyDriverLicenseData"' | ||
|
|
||
| VERIFICATION_REQUESTED_ATTRS = { | ||
| first_name: RequestAttribute.new(xpath: '//nc:PersonGivenName', required: true), | ||
| middle_name: RequestAttribute.new(xpath: '//nc:PersonMiddleName', required: false), | ||
| last_name: RequestAttribute.new('//nc:PersonSurName', true), | ||
| name_suffix: RequestAttribute.new('//nc:PersonNameSuffixText', false), | ||
| dob: RequestAttribute.new('//aa:PersonBirthDate', true), | ||
| address1: RequestAttribute.new('//nc:AddressDeliveryPointText', true), | ||
| address2: RequestAttribute.new('//nc:AddressDeliveryPointText[2]', false), | ||
| city: RequestAttribute.new('//nc:LocationCityName', true), | ||
| state: RequestAttribute.new('//nc:LocationStateUsPostalServiceCode', true), | ||
| zipcode: RequestAttribute.new('//nc:LocationPostalCode', true), | ||
| state_id_number: RequestAttribute.new('//nc:IdentificationID', true), | ||
| state_id_type: RequestAttribute.new('//aa:DocumentCategoryCode', false), | ||
| state_id_expiration: RequestAttribute.new('//aa:DriverLicenseExpirationDate', false), | ||
| state_id_jurisdiction: RequestAttribute.new('//aa:MessageDestinationId', true), | ||
| state_id_issued: RequestAttribute.new('//aa:DriverLicenseIssueDate', false), | ||
| eye_color: RequestAttribute.new('//aa:PersonEyeColorCode', false), | ||
| height: RequestAttribute.new('//aa:PersonHeightMeasure', false), | ||
| sex: RequestAttribute.new('//aa:PersonSexCode', false), | ||
| weight: RequestAttribute.new('//aa:PersonWeightMeasure', false), | ||
| }.freeze | ||
|
|
||
| extend Forwardable | ||
|
|
||
| attr_reader :config, :body, :headers, :url | ||
|
|
||
| # @param applicant [Proofing::Aamva::Applicant] | ||
| def initialize(config:, applicant:, session_id:, auth_token:) | ||
| @config = config | ||
| @applicant = applicant | ||
| @transaction_id = session_id | ||
| @auth_token = auth_token | ||
| @requested_attributes = {} | ||
| @url = verification_url | ||
| @body = build_request_body | ||
| @headers = build_request_headers | ||
| end | ||
|
|
||
| # @return [Proofing::Aamva::Response::VerificationResponse] | ||
| def send | ||
| Response::VerificationResponse.new( | ||
| http_client.post(url, body, headers) do |req| | ||
|
|
@@ -46,9 +72,21 @@ def verification_url | |
| config.verification_url || DEFAULT_VERIFICATION_URL | ||
| end | ||
|
|
||
| # The requested attributes in the applicant PII hash. Values are: | ||
| # - +:present+ - value present | ||
| # - +:missing+ - field is required, but value was blank | ||
| # | ||
| # @see Proofing::Aamva::Applicant#from_proofer_applicant for fields | ||
| # @return [Hash{Symbol => Symbol}] | ||
| def requested_attributes | ||
| { **@requested_attributes } | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_reader :applicant, :transaction_id, :auth_token | ||
| # @return [Proofing::Aamva::Applicant] | ||
| attr_reader :applicant | ||
| attr_reader :transaction_id, :auth_token | ||
|
|
||
| def http_client | ||
| Faraday.new(request: { open_timeout: timeout, timeout: timeout }) do |faraday| | ||
|
|
@@ -57,9 +95,10 @@ def http_client | |
| end | ||
| end | ||
|
|
||
| def add_user_provided_data_to_body | ||
| def add_user_provided_data_to_body(body) | ||
| document = REXML::Document.new(body) | ||
| user_provided_data_map.each do |xpath, data| | ||
| user_provided_data_map.each do |attribute, data| | ||
| xpath = VERIFICATION_REQUESTED_ATTRS[attribute].xpath | ||
| REXML::XPath.first(document, xpath).add_text(data) | ||
| end | ||
|
|
||
|
|
@@ -126,17 +165,18 @@ def add_user_provided_data_to_body | |
| document, | ||
| ) | ||
|
|
||
| @body = document.to_s | ||
| update_requested_attributes(document) | ||
| document.to_s | ||
| end | ||
|
|
||
| def add_state_id_type(id_type, document) | ||
| category_code = case id_type | ||
| when 'drivers_license' | ||
| 1 | ||
| when 'drivers_permit' | ||
| 2 | ||
| when 'state_id_card' | ||
| 3 | ||
| when 'drivers_license' | ||
| 1 | ||
| when 'drivers_permit' | ||
| 2 | ||
| when 'state_id_card' | ||
| 3 | ||
| end | ||
|
|
||
| if category_code | ||
|
|
@@ -151,10 +191,10 @@ def add_state_id_type(id_type, document) | |
|
|
||
| def add_sex_code(sex_value, document) | ||
| sex_code = case sex_value | ||
| when 'male' | ||
| 1 | ||
| when 'female' | ||
| 2 | ||
| when 'male' | ||
| 1 | ||
| when 'female' | ||
| 2 | ||
| end | ||
|
|
||
| if sex_code | ||
|
|
@@ -181,10 +221,22 @@ def add_optional_element(name, value:, document:, inside: nil, after: nil) | |
| end | ||
| end | ||
|
|
||
| # @param document [REXML::Document] | ||
| def update_requested_attributes(document) | ||
| VERIFICATION_REQUESTED_ATTRS.each do |attribute, rule| | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is good, I like that we are sourcing this from the actual XML we are building. |
||
| value = REXML::XPath.first(document, rule.xpath)&.text | ||
| if value.present? | ||
| @requested_attributes[attribute] = :present | ||
| elsif rule.required | ||
| @requested_attributes[attribute] = :missing | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def build_request_body | ||
| renderer = ERB.new(request_body_template) | ||
| @body = renderer.result(binding) | ||
| add_user_provided_data_to_body | ||
| tmp_body = renderer.result(binding) | ||
| add_user_provided_data_to_body(tmp_body) | ||
| end | ||
|
|
||
| def build_request_headers | ||
|
|
@@ -222,24 +274,24 @@ def transaction_locator_id | |
|
|
||
| def user_provided_data_map | ||
| { | ||
| '//nc:IdentificationID' => state_id_number, | ||
| '//aa:MessageDestinationId' => message_destination_id, | ||
| '//nc:PersonGivenName' => applicant.first_name, | ||
| '//nc:PersonSurName' => applicant.last_name, | ||
| '//aa:PersonBirthDate' => applicant.dob, | ||
| '//nc:AddressDeliveryPointText' => applicant.address1, | ||
| '//nc:LocationCityName' => applicant.city, | ||
| '//nc:LocationStateUsPostalServiceCode' => applicant.state, | ||
| '//nc:LocationPostalCode' => applicant.zipcode, | ||
| state_id_number: state_id_number, | ||
| state_id_jurisdiction: message_destination_id, | ||
| first_name: applicant.first_name, | ||
| last_name: applicant.last_name, | ||
| dob: applicant.dob, | ||
| address1: applicant.address1, | ||
| city: applicant.city, | ||
| state: applicant.state, | ||
| zipcode: applicant.zipcode, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👏 Moving xpath selectors out makes this so much more pleasant. 😄 |
||
| } | ||
| end | ||
|
|
||
| def state_id_number | ||
| case applicant.state_id_data.state_id_jurisdiction | ||
| when 'SC' | ||
| applicant.state_id_data.state_id_number.rjust(8, '0') | ||
| else | ||
| applicant.state_id_data.state_id_number | ||
| when 'SC' | ||
| applicant.state_id_data.state_id_number.rjust(8, '0') | ||
| else | ||
| applicant.state_id_data.state_id_number | ||
| 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
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.
Uh oh!
There was an error while loading. Please reload this page.