Skip to content
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

Refactor email sending methods in Simple Forms API #20041

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ def handle_210966_authenticated
form.track_user_identity(confirmation_number)

if confirmation_number && Flipper.enabled?(:simple_forms_email_confirmations)
send_intent_received_email(parsed_form_data, confirmation_number, expiration_date)
send_notification_email('vba_21_0966_intent_api', parsed_form_data, :received, confirmation_number,
expiration_date)
end

json_for210966(confirmation_number, expiration_date, existing_intents)
Expand All @@ -121,25 +122,28 @@ def handle264555
lgy_response = LGY::Service.new.post_grant_application(payload: form.as_payload)
reference_number = lgy_response.body['reference_number']
status = lgy_response.body['status']

Rails.logger.info(
'Simple forms api - sent to lgy',
{ form_number: params[:form_number], status:, reference_number: }
)

if Flipper.enabled?(:simple_forms_email_confirmations)
case status
when 'VALIDATED', 'ACCEPTED'
send_sahsha_email(parsed_form_data, reference_number, :confirmation)
when 'REJECTED'
send_sahsha_email(parsed_form_data, reference_number, :rejected)
when 'DUPLICATE'
send_sahsha_email(parsed_form_data, reference_number, :duplicate)
end
send_status_notification('vba_26_4555', parsed_form_data, reference_number, status)
end

{ json: { reference_number:, status: }, status: lgy_response.status }
end

def send_status_notification(form_num, form_data, reference_number, status)
notification_type = case status
when 'VALIDATED', 'ACCEPTED' then :confirmation
when 'REJECTED' then :rejected
when 'DUPLICATE' then :duplicate
end
send_notification_email(form_num, form_data, notification_type, reference_number) if notification_type
end

def submit_form_to_benefits_intake
parsed_form_data = JSON.parse(params.to_json)
file_path, metadata, form = get_file_paths_and_metadata(parsed_form_data)
Expand All @@ -155,7 +159,7 @@ def submit_form_to_benefits_intake

if status == 200
if Flipper.enabled?(:simple_forms_email_confirmations)
send_confirmation_email(parsed_form_data, confirmation_number)
send_notification_email(form_id, parsed_form_data, :confirmation, confirmation_number)
end

presigned_s3_url = if Flipper.enabled?(:submission_pdf_s3_upload)
Expand Down Expand Up @@ -308,44 +312,15 @@ def json_for210966(confirmation_number, expiration_date, existing_intents)
} }
end

def send_confirmation_email(parsed_form_data, confirmation_number)
config = {
form_data: parsed_form_data,
form_number: form_id,
confirmation_number:,
date_submitted: Time.zone.today.strftime('%B %d, %Y')
}
notification_email = SimpleFormsApi::NotificationEmail.new(
config,
notification_type: :confirmation,
user: @current_user
)
notification_email.send
end

def send_intent_received_email(parsed_form_data, confirmation_number, expiration_date)
def send_notification_email(form_number, parsed_form_data, notification_type, confirmation_number,
expiration_date = nil)
config = {
form_data: parsed_form_data,
form_number: 'vba_21_0966_intent_api',
form_number:,
confirmation_number:,
date_submitted: Time.zone.today.strftime('%B %d, %Y'),
expiration_date:
}
notification_email = SimpleFormsApi::NotificationEmail.new(
config,
notification_type: :received,
user: @current_user
)
notification_email.send
end

def send_sahsha_email(parsed_form_data, confirmation_number, notification_type)
config = {
form_data: parsed_form_data,
form_number: 'vba_26_4555',
confirmation_number:,
date_submitted: Time.zone.today.strftime('%B %d, %Y')
}
notification_email = SimpleFormsApi::NotificationEmail.new(
config,
notification_type:,
Expand Down
Loading