diff --git a/queue_services/account-mailer/q_cli.py b/queue_services/account-mailer/q_cli.py index 3c4a1a3e93..44f7287e49 100755 --- a/queue_services/account-mailer/q_cli.py +++ b/queue_services/account-mailer/q_cli.py @@ -183,6 +183,18 @@ def subscription_options(): 'recipientEmail': 'foo@bar.com' } } + elif mode == 'pad_setup_failed': + payload = { + 'specversion': '1.x-wip', + 'type': f'{MessageType.PAD_SETUP_FAILED.value}', + 'source': 'https://api.auth.bcregistry.gov.bc.ca/v1/invoices/{invoice.id}', + 'id': auth_account_id, + 'datacontenttype': 'application/json', + 'data': { + 'accountId': auth_account_id, + # 'recipientEmail': 'foo@bar.com' + } + } await sc.publish(subject=subscription_options().get('subject'), payload=json.dumps(payload).encode('utf-8')) diff --git a/queue_services/account-mailer/src/account_mailer/email_templates/pad_setup_failed.html b/queue_services/account-mailer/src/account_mailer/email_templates/pad_setup_failed.html new file mode 100644 index 0000000000..eb42ffc9c6 --- /dev/null +++ b/queue_services/account-mailer/src/account_mailer/email_templates/pad_setup_failed.html @@ -0,0 +1,26 @@ + + + + + + + + + Your Account is Temporarily Suspended + [[style.html]] + + +
+
+ [[logo.html]] +
+

+ When you setup pre-authorized debit, the bank information you entered was invalid.

+

To unlock your account, please review and update your bank information. +

+ Log in + +
+ + \ No newline at end of file diff --git a/queue_services/account-mailer/src/account_mailer/enums.py b/queue_services/account-mailer/src/account_mailer/enums.py index 80a53d2ad9..45078e8a4e 100644 --- a/queue_services/account-mailer/src/account_mailer/enums.py +++ b/queue_services/account-mailer/src/account_mailer/enums.py @@ -30,6 +30,7 @@ class MessageType(Enum): ONLINE_BANKING_OVER_PAYMENT = 'bc.registry.payment.OverPaid' ONLINE_BANKING_UNDER_PAYMENT = 'bc.registry.payment.UnderPaid' ONLINE_BANKING_PAYMENT = 'bc.registry.payment.Payment' + PAD_SETUP_FAILED = 'bc.registry.payment.PadSetupFailed' class SubjectType(Enum): @@ -42,6 +43,7 @@ class SubjectType(Enum): ADMIN_REMOVED_SUBJECT = '[BC Registries and Online Services] You have been removed as an administrator' TEAM_MODIFIED_SUBJECT = '[BC Registries and Online Services] Change in Team members' ONLINE_BANKING_PAYMENT_SUBJECT = '[BC Registries and Online Services] Online Banking payment has been received' + PAD_SETUP_FAILED = '[BC Registries and Online Services] Your Account is Temporarily Suspended' class TemplateType(Enum): @@ -56,3 +58,4 @@ class TemplateType(Enum): ONLINE_BANKING_PAYMENT_TEMPLATE_NAME = 'online_banking_payment' ONLINE_BANKING_OVER_PAYMENT_TEMPLATE_NAME = 'online_banking_over_payment' ONLINE_BANKING_UNDER_PAYMENT_TEMPLATE_NAME = 'online_banking_under_payment' + PAD_SETUP_FAILED_TEMPLATE_NAME = 'pad_setup_failed' diff --git a/queue_services/account-mailer/src/account_mailer/worker.py b/queue_services/account-mailer/src/account_mailer/worker.py index c9f5a3d69a..ba4558380a 100644 --- a/queue_services/account-mailer/src/account_mailer/worker.py +++ b/queue_services/account-mailer/src/account_mailer/worker.py @@ -147,6 +147,17 @@ async def process_event(event_message: dict, flask_app): 'credit_amount': email_msg.get('creditAmount'), } email_dict = common_mailer.process(org_id, admin_emails, template_name, subject, **args) + elif message_type == MessageType.PAD_SETUP_FAILED.value: + email_msg = event_message.get('data') + template_name = TemplateType.PAD_SETUP_FAILED_TEMPLATE_NAME.value + org_id = email_msg.get('accountId') + admin_coordinator_emails = get_member_emails(org_id, (ADMIN,)) + subject = SubjectType.PAD_SETUP_FAILED.value + args = { + 'accountId': email_msg.get('accountId'), + } + email_dict = common_mailer.process(org_id, admin_coordinator_emails, template_name, subject, + **args) if email_dict: logger.debug('Extracted email msg Recipient: %s ', email_dict.get('recipients', '')) process_email(email_dict, FLASK_APP, token) diff --git a/queue_services/account-mailer/tests/integration/test_worker_queue.py b/queue_services/account-mailer/tests/integration/test_worker_queue.py index 946a4d4f34..b15e8d79a7 100644 --- a/queue_services/account-mailer/tests/integration/test_worker_queue.py +++ b/queue_services/account-mailer/tests/integration/test_worker_queue.py @@ -380,3 +380,46 @@ async def test_online_banking_emails(app, session, stan_server, event_loop, clie 'subject') == SubjectType.ONLINE_BANKING_PAYMENT_SUBJECT.value assert mock_send.call_args.args[0].get('attachments') is None assert mock_send.call_args.args[0].get('content').get('body') is not None + + +@pytest.mark.asyncio +async def test_pad_failed_emails(app, session, stan_server, event_loop, client_id, events_stan, future): + """Assert that events can be retrieved and decoded from the Queue.""" + # Call back for the subscription + from account_mailer.worker import cb_subscription_handler + + # vars + user = factory_user_model_with_contact() + org = factory_org_model() + factory_membership_model(user.id, org.id) + id = org.id + + events_subject = 'test_subject' + events_queue = 'test_queue' + events_durable_name = 'test_durable' + with patch.object(notification_service, 'send_email', return_value=None) as mock_send: + # register the handler to test it + await subscribe_to_queue(events_stan, + events_subject, + events_queue, + events_durable_name, + cb_subscription_handler) + + # add an event to queue + mail_details = { + 'accountId': id + } + await helper_add_event_to_queue(events_stan, events_subject, org_id=id, + msg_type=MessageType.PAD_SETUP_FAILED.value, + mail_details=mail_details) + + mock_send.assert_called + assert mock_send.call_args.args[0].get('recipients') == 'foo@bar.com' + assert mock_send.call_args.args[0].get('content').get( + 'subject') == SubjectType.PAD_SETUP_FAILED.value + assert mock_send.call_args.args[0].get('attachments') is None + assert mock_send.call_args.args[0].get('content').get('body') is not None + + await helper_add_event_to_queue(events_stan, events_subject, org_id=id, + msg_type=MessageType.PAD_SETUP_FAILED.value, + mail_details=mail_details)