From de5eaa066f3e42188138d6919e3bb257885a596c Mon Sep 17 00:00:00 2001 From: Travis Semple Date: Thu, 1 Aug 2024 14:48:33 -0700 Subject: [PATCH] 20087 - Add in additional emails (#1654) --- jobs/payment-jobs/poetry.lock | 8 ++++---- jobs/payment-jobs/pyproject.toml | 2 +- jobs/payment-jobs/tasks/statement_due_task.py | 12 +++++------- jobs/payment-jobs/utils/auth_event.py | 9 +++++---- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/jobs/payment-jobs/poetry.lock b/jobs/payment-jobs/poetry.lock index 009ecbab3..b6c2078c8 100644 --- a/jobs/payment-jobs/poetry.lock +++ b/jobs/payment-jobs/poetry.lock @@ -1999,9 +1999,9 @@ werkzeug = "3.0.1" [package.source] type = "git" -url = "https://github.com/seeker25/sbc-pay.git" -reference = "20087_p2" -resolved_reference = "7ff93b7aebeadaf37041ad05b9b787f3030694b1" +url = "https://github.com/bcgov/sbc-pay.git" +reference = "HEAD" +resolved_reference = "012af273fe5ea47368f9c3ff9f0fe7e253e211dc" subdirectory = "pay-api" [[package]] @@ -3141,4 +3141,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "12a259aefea10244b14769369b1107bf847f91f9b4166ace87332ee9fde5e725" +content-hash = "3ec0b51675efd0cf2d4bb86d2c636f4b147d554e6dd34d02195adbe7e1874acf" diff --git a/jobs/payment-jobs/pyproject.toml b/jobs/payment-jobs/pyproject.toml index ffc4136bf..3a97d095e 100644 --- a/jobs/payment-jobs/pyproject.toml +++ b/jobs/payment-jobs/pyproject.toml @@ -7,7 +7,7 @@ readme = "README.md" [tool.poetry.dependencies] python = "^3.12" -pay-api = {git = "https://github.com/seeker25/sbc-pay.git", subdirectory = "pay-api", branch = "20087_p2"} +pay-api = {git = "https://github.com/bcgov/sbc-pay.git", subdirectory = "pay-api"} gunicorn = "^21.2.0" flask = "^3.0.2" flask-sqlalchemy = "^3.1.1" diff --git a/jobs/payment-jobs/tasks/statement_due_task.py b/jobs/payment-jobs/tasks/statement_due_task.py index 18ae0f2eb..bc3751f19 100644 --- a/jobs/payment-jobs/tasks/statement_due_task.py +++ b/jobs/payment-jobs/tasks/statement_due_task.py @@ -105,12 +105,13 @@ def _notify_for_monthly(cls): current_app.logger.info('Freezing payment account id: %s locking auth account id: %s', payment_account.id, payment_account.auth_account_id) # The locking email is sufficient for overdue, no seperate email required. - AuthEvent.publish_lock_account_event(payment_account) + additional_emails = current_app.config.get('EFT_OVERDUE_NOTIFY_EMAILS') + AuthEvent.publish_lock_account_event(payment_account, additional_emails) cls.add_to_non_sufficient_funds(payment_account) statement.overdue_notification_date = datetime.now(tz=timezone.utc) statement.save() continue - if emails := cls._determine_recipient_emails(statement, action): + if emails := cls._determine_recipient_emails(statement): publish_payment_notification( StatementNotificationInfo(auth_account_id=payment_account.auth_account_id, statement=statement, @@ -165,13 +166,10 @@ def _determine_action_and_due_date_by_invoice(cls, statement_id: int): return None, day_before_invoice_overdue @classmethod - def _determine_recipient_emails(cls, - statement: StatementRecipientsModel, action: StatementNotificationAction) -> str: + def _determine_recipient_emails(cls, statement: StatementRecipientsModel) -> str: if (recipients := StatementRecipientsModel.find_all_recipients_for_payment_id(statement.payment_account_id)): recipients = ','.join([str(recipient.email) for recipient in recipients]) - if action == StatementNotificationAction.OVERDUE: - if overdue_notify_emails := current_app.config.get('EFT_OVERDUE_NOTIFY_EMAILS'): - recipients += ',' + overdue_notify_emails + return recipients current_app.logger.error(f'No recipients found for statement: {statement.payment_account_id}. Skipping.') diff --git a/jobs/payment-jobs/utils/auth_event.py b/jobs/payment-jobs/utils/auth_event.py index 22d603e78..0d776fd16 100644 --- a/jobs/payment-jobs/utils/auth_event.py +++ b/jobs/payment-jobs/utils/auth_event.py @@ -12,10 +12,10 @@ class AuthEvent: """Publishes to the auth-queue as an auth event though PUBSUB, this message gets sent to account-mailer after.""" @staticmethod - def publish_lock_account_event(pay_account: PaymentAccountModel): + def publish_lock_account_event(pay_account: PaymentAccountModel, additional_emails=''): """Publish NSF lock account event to the auth queue.""" try: - payload = AuthEvent._create_event_payload(pay_account) + payload = AuthEvent._create_event_payload(pay_account, additional_emails) gcp_queue_publisher.publish_to_queue( QueueMessage( source=QueueSources.PAY_JOBS.value, @@ -55,9 +55,10 @@ def publish_unlock_account_event(payment_account: PaymentAccountModel): payment_account.auth_account_id}, {unlock_payload}.', level='error') @staticmethod - def _create_event_payload(pay_account): + def _create_event_payload(pay_account, additional_emails=''): return { 'accountId': pay_account.auth_account_id, 'paymentMethod': PaymentMethod.EFT.value, - 'suspensionReasonCode': SuspensionReasonCodes.OVERDUE_EFT.value + 'suspensionReasonCode': SuspensionReasonCodes.OVERDUE_EFT.value, + 'additionalEmails': additional_emails }