-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[API-34448] VA Notify - Send declined notification (#19362)
* rename VANotifyJob → VANotifyAcceptedJob * add declined notify job * add email content and templates * add tests * add poa code and participant id * add test; fixup controller * claimantFirstName → vetFirstName * add claimantFirstName back * remove VSOUserFirstName * add representative id * ptcpnt_id → participantId for user-facing * procId → procID * add base64 encoding for sidekiq params * use slack_alert_on_failure * use ordered arguments * Update modules/claims_api/app/sidekiq/claims_api/va_notify_declined_job.rb Co-authored-by: Rockwell Windsor Rice <129893414+rockwellwindsor-va@users.noreply.github.com> * fall back to representative --------- Co-authored-by: Rockwell Windsor Rice <129893414+rockwellwindsor-va@users.noreply.github.com>
- Loading branch information
1 parent
6f56649
commit f4758c6
Showing
12 changed files
with
291 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
90 changes: 90 additions & 0 deletions
90
modules/claims_api/app/sidekiq/claims_api/va_notify_declined_job.rb
This file contains 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,90 @@ | ||
# frozen_string_literal: true | ||
|
||
module ClaimsApi | ||
class VANotifyDeclinedJob < ClaimsApi::ServiceBase | ||
LOG_TAG = 'va_notify_declined_job' | ||
|
||
def perform(encrypted_ptcpnt_id, encrypted_first_name, representative_id) | ||
lockbox = Lockbox.new(key: Settings.lockbox.master_key) | ||
ptcpnt_id = lockbox.decrypt(Base64.strict_decode64(encrypted_ptcpnt_id)) | ||
first_name = lockbox.decrypt(Base64.strict_decode64(encrypted_first_name)) | ||
representative = ::Veteran::Service::Representative.find_by(representative_id:) | ||
|
||
if representative.blank? | ||
raise ClaimsApi::Common::Exceptions::Lighthouse::ResourceNotFound.new( | ||
detail: "Could not find veteran representative with id: #{representative_id}" | ||
) | ||
end | ||
|
||
res = send_declined_notification(ptcpnt_id:, first_name:, representative:) | ||
|
||
ClaimsApi::VANotifyFollowUpJob.perform_async(res.id) if res.present? | ||
rescue => e | ||
msg = "VA Notify email notification failed to send with error #{e}" | ||
slack_alert_on_failure('ClaimsApi::VANotifyDeclinedJob', msg) | ||
|
||
ClaimsApi::Logger.log(LOG_TAG, detail: msg) | ||
|
||
raise e | ||
end | ||
|
||
private | ||
|
||
def find_poa(poa_code:) | ||
ClaimsApi::PowerOfAttorney.find do |poa| | ||
poa.form_data.dig('serviceOrganization', 'poaCode') == poa_code || | ||
poa.form_data.dig('representative', 'poaCode') == poa_code | ||
end | ||
end | ||
|
||
def send_declined_notification(ptcpnt_id:, first_name:, representative:) | ||
representative_type = representative.user_type | ||
return send_organization_notification(ptcpnt_id:, first_name:) if representative_type == 'veteran_service_officer' | ||
|
||
send_representative_notification(ptcpnt_id:, first_name:, representative_type:) | ||
end | ||
|
||
def send_organization_notification(ptcpnt_id:, first_name:) | ||
content = { | ||
recipient_identifier: ptcpnt_id, | ||
personalisation: { | ||
first_name: first_name || '', | ||
form_type: 'Appointment of Veterans Service Organization as Claimantʼs Representative (VA Form 21-22)' | ||
}, | ||
template_id: Settings.claims_api.vanotify.declined_service_organization_template_id | ||
} | ||
|
||
vanotify_service.send_email(content) | ||
end | ||
|
||
def send_representative_notification(ptcpnt_id:, first_name:, representative_type:) | ||
representative_type_text = get_representative_type_text(representative_type:) | ||
|
||
content = { | ||
recipient_identifier: ptcpnt_id, | ||
personalisation: { | ||
first_name: first_name || '', | ||
representative_type: representative_type_text || 'representative', | ||
representative_type_abbreviated: representative_type_text || 'representative', | ||
form_type: 'Appointment of Individual as Claimantʼs Representative (VA Form 21-22a)' | ||
}, | ||
template_id: Settings.claims_api.vanotify.declined_representative_template_id | ||
} | ||
|
||
vanotify_service.send_email(content) | ||
end | ||
|
||
def get_representative_type_text(representative_type:) | ||
case representative_type | ||
when 'attorney' | ||
'attorney' | ||
when 'claim_agents' | ||
'claims agent' | ||
end | ||
end | ||
|
||
def vanotify_service | ||
VaNotify::Service.new(Settings.claims_api.vanotify.services.lighthouse.api_key) | ||
end | ||
end | ||
end |
This file contains 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 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 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.