-
Notifications
You must be signed in to change notification settings - Fork 166
LG-8856: Account for polling delays when sending in-person proofing emails #7805
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
sheldon-b
merged 12 commits into
main
from
sbachstein/send-in-person-proofing-results-emails-sooner
Mar 1, 2023
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
49df1f5
Account for polling delays when sending emails
11c3c55
Re-run migration to get comment
5e06621
Add JSON merge helper method
1bc8433
Update how we convert to UTC timezone
64fea8f
Merge remote-tracking branch 'origin/main' into sbachstein/send-in-pe…
bc26f51
Use UTC offset instead of string name
8eb7983
Minor cleanups
a52f5e5
Add check for wait_until attribute
d90bb14
Add spec checking queue and wait_until on failure
71ee3b0
Merge remote-tracking branch 'origin/main' into sbachstein/send-in-pe…
ee6ebf7
Merge remote-tracking branch 'origin/main' into sbachstein/send-in-pe…
24fd022
Merge remote-tracking branch 'origin/main' into sbachstein/send-in-pe…
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ def email_analytics_attributes(enrollment) | |
| timestamp: Time.zone.now, | ||
| user_id: enrollment.user_id, | ||
| service_provider: enrollment.issuer, | ||
| delay_time_seconds: mail_delivery_params[:wait], | ||
| wait_until: mail_delivery_params(enrollment.proofed_at)[:wait_until], | ||
| } | ||
| end | ||
|
|
||
|
|
@@ -42,8 +42,8 @@ def response_analytics_attributes(response) | |
| primary_id_type: response['primaryIdType'], | ||
| secondary_id_type: response['secondaryIdType'], | ||
| failure_reason: response['failureReason'], | ||
| transaction_end_date_time: response['transactionEndDateTime'], | ||
| transaction_start_date_time: response['transactionStartDateTime'], | ||
| transaction_end_date_time: parse_usps_timestamp(response['transactionEndDateTime']), | ||
| transaction_start_date_time: parse_usps_timestamp(response['transactionStartDateTime']), | ||
| status: response['status'], | ||
| assurance_level: response['assuranceLevel'], | ||
| proofing_post_office: response['proofingPostOffice'], | ||
|
|
@@ -234,6 +234,7 @@ def handle_unsupported_status(enrollment, response) | |
| end | ||
|
|
||
| def handle_unsupported_id_type(enrollment, response) | ||
| proofed_at = parse_usps_timestamp(response['transactionEndDateTime']) | ||
| enrollment_outcomes[:enrollments_failed] += 1 | ||
| analytics(user: enrollment.user).idv_in_person_usps_proofing_results_job_enrollment_updated( | ||
| **enrollment_analytics_attributes(enrollment, complete: true), | ||
|
|
@@ -243,7 +244,13 @@ def handle_unsupported_id_type(enrollment, response) | |
| primary_id_type: response['primaryIdType'], | ||
| reason: 'Unsupported ID type', | ||
| ) | ||
| enrollment.update(status: :failed) | ||
| enrollment.update(status: :failed, proofed_at: proofed_at) | ||
|
|
||
| send_failed_email(enrollment.user, enrollment) | ||
| analytics(user: enrollment.user).idv_in_person_usps_proofing_results_job_email_initiated( | ||
| **email_analytics_attributes(enrollment), | ||
| email_type: 'Failed unsupported ID type', | ||
| ) | ||
|
Comment on lines
+249
to
+253
Contributor
Author
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. ℹ️ We weren't previously sending emails when a user failed to proof due to an unsupported type of ID |
||
| end | ||
|
|
||
| def handle_expired_status_update(enrollment, response, response_message) | ||
|
|
@@ -301,6 +308,7 @@ def handle_unexpected_response(enrollment, response_message, reason:, cancel: tr | |
| end | ||
|
|
||
| def handle_failed_status(enrollment, response) | ||
| proofed_at = parse_usps_timestamp(response['transactionEndDateTime']) | ||
| enrollment_outcomes[:enrollments_failed] += 1 | ||
| analytics(user: enrollment.user).idv_in_person_usps_proofing_results_job_enrollment_updated( | ||
| **enrollment_analytics_attributes(enrollment, complete: true), | ||
|
|
@@ -309,7 +317,7 @@ def handle_failed_status(enrollment, response) | |
| reason: 'Failed status', | ||
| ) | ||
|
|
||
| enrollment.update(status: :failed) | ||
| enrollment.update(status: :failed, proofed_at: proofed_at) | ||
| if response['fraudSuspected'] | ||
| send_failed_fraud_email(enrollment.user, enrollment) | ||
| analytics(user: enrollment.user).idv_in_person_usps_proofing_results_job_email_initiated( | ||
|
|
@@ -326,6 +334,7 @@ def handle_failed_status(enrollment, response) | |
| end | ||
|
|
||
| def handle_successful_status_update(enrollment, response) | ||
| proofed_at = parse_usps_timestamp(response['transactionEndDateTime']) | ||
| enrollment_outcomes[:enrollments_passed] += 1 | ||
| analytics(user: enrollment.user).idv_in_person_usps_proofing_results_job_enrollment_updated( | ||
| **enrollment_analytics_attributes(enrollment, complete: true), | ||
|
|
@@ -334,12 +343,12 @@ def handle_successful_status_update(enrollment, response) | |
| passed: true, | ||
| reason: 'Successful status update', | ||
| ) | ||
| enrollment.profile.activate | ||
| enrollment.update(status: :passed, proofed_at: proofed_at) | ||
| analytics(user: enrollment.user).idv_in_person_usps_proofing_results_job_email_initiated( | ||
| **email_analytics_attributes(enrollment), | ||
| email_type: 'Success', | ||
| ) | ||
| enrollment.profile.activate | ||
| enrollment.update(status: :passed) | ||
| send_verified_email(enrollment.user, enrollment) | ||
| end | ||
|
|
||
|
|
@@ -369,7 +378,7 @@ def send_verified_email(user, enrollment) | |
| # rubocop:disable IdentityIdp/MailLaterLinter | ||
| UserMailer.with(user: user, email_address: email_address).in_person_verified( | ||
| enrollment: enrollment, | ||
| ).deliver_later(**mail_delivery_params) | ||
| ).deliver_later(**mail_delivery_params(enrollment.proofed_at)) | ||
| # rubocop:enable IdentityIdp/MailLaterLinter | ||
| end | ||
| end | ||
|
|
@@ -389,7 +398,7 @@ def send_failed_email(user, enrollment) | |
| # rubocop:disable IdentityIdp/MailLaterLinter | ||
| UserMailer.with(user: user, email_address: email_address).in_person_failed( | ||
| enrollment: enrollment, | ||
| ).deliver_later(**mail_delivery_params) | ||
| ).deliver_later(**mail_delivery_params(enrollment.proofed_at)) | ||
| # rubocop:enable IdentityIdp/MailLaterLinter | ||
| end | ||
| end | ||
|
|
@@ -399,18 +408,26 @@ def send_failed_fraud_email(user, enrollment) | |
| # rubocop:disable IdentityIdp/MailLaterLinter | ||
| UserMailer.with(user: user, email_address: email_address).in_person_failed_fraud( | ||
| enrollment: enrollment, | ||
| ).deliver_later(**mail_delivery_params) | ||
| ).deliver_later(**mail_delivery_params(enrollment.proofed_at)) | ||
| # rubocop:enable IdentityIdp/MailLaterLinter | ||
| end | ||
| end | ||
|
|
||
| def mail_delivery_params | ||
| config_delay = IdentityConfig.store.in_person_results_delay_in_hours | ||
| if config_delay > 0 | ||
| return { wait: config_delay.hours, queue: :intentionally_delayed } | ||
| elsif (config_delay == 0) | ||
| return {} | ||
| end | ||
| { wait: DEFAULT_EMAIL_DELAY_IN_HOURS.hours, queue: :intentionally_delayed } | ||
| def mail_delivery_params(proofed_at) | ||
| mail_delay_hours = IdentityConfig.store.in_person_results_delay_in_hours || | ||
| DEFAULT_EMAIL_DELAY_IN_HOURS | ||
| wait_until = proofed_at + mail_delay_hours.hours | ||
| return {} if mail_delay_hours == 0 || wait_until < Time.zone.now | ||
| return { wait_until: wait_until, queue: :intentionally_delayed } | ||
| end | ||
|
|
||
| def parse_usps_timestamp(usps_timestamp) | ||
| return unless usps_timestamp | ||
| # Parse timestamps eg 12/17/2020 033855 => Thu, 17 Dec 2020 03:38:55 -0600 | ||
| # Note that the USPS timestamps are in Central Standard time (UTC -6:00) | ||
| ActiveSupport::TimeZone[-6].strptime( | ||
| usps_timestamp, | ||
| '%m/%d/%Y %H%M%S', | ||
| ).in_time_zone('UTC') | ||
| end | ||
| end | ||
5 changes: 5 additions & 0 deletions
5
db/primary_migrate/20230206184647_add_proofed_at_to_in_person_enrollments.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,5 @@ | ||
| class AddProofedAtToInPersonEnrollments < ActiveRecord::Migration[7.0] | ||
| def change | ||
| add_column :in_person_enrollments, :proofed_at, :timestamp, comment: 'timestamp when user attempted to proof at a Post Office' | ||
| 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.
Uh oh!
There was an error while loading. Please reload this page.