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

17224 - Payment reminder notifications for EFT #2607

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
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
@@ -0,0 +1,15 @@
# Payment Due Today

There's an amount owing on your recent statement due on {{ due_date }}.

To avoid any disruptions to your services, please make your payment as soon as possible.

[Log in to view your {{ statement_frequency }} statement]({{ payment_statement_url }})

If you've recently made a payment, please disregard this message.

**Business Registry**
BC Registries and Online Services
Toll Free: 1-877-370-1033
Victoria Office: 250-370-1033
Email: [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Payment Reminder

There's an amount owing on your recent statement due on {{ due_date }}.

[Log in to view your {{ statement_frequency }} statement]({{ payment_statement_url }})

If you've recently made a payment, please disregard this message.

**Business Registry**
BC Registries and Online Services
Toll Free: 1-877-370-1033
Victoria Office: 250-370-1033
Email: [email protected]
6 changes: 6 additions & 0 deletions queue_services/account-mailer/src/account_mailer/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class MessageType(Enum):
AFFILIATION_INVITATION_REQUEST = 'bc.registry.auth.affiliationInvitationRequest'
AFFILIATION_INVITATION_REQUEST_AUTHORIZATION = 'bc.registry.auth.affiliationInvitationRequestAuthorization'
STATEMENT_NOTIFICATION = 'bc.registry.payment.statementNotification'
PAYMENT_REMINDER_NOTIFICATION = 'bc.registry.payment.statementReminderNotification'
PAYMENT_DUE_NOTIFICATION = 'bc.registry.payment.statementDueNotification'


class SubjectType(Enum):
Expand Down Expand Up @@ -118,6 +120,8 @@ class SubjectType(Enum):
AFFILIATION_INVITATION_REQUEST_AUTHORIZATION = '[BC Registries and Online Services] ' \
'Request to manage {business_name}'
STATEMENT_NOTIFICATION = 'Your BC Registries statement is available'
PAYMENT_REMINDER_NOTIFICATION = 'Your BC Registries payment reminder'
PAYMENT_DUE_NOTIFICATION = 'Your BC Registries payment is due'


class TitleType(Enum):
Expand Down Expand Up @@ -192,6 +196,8 @@ class TemplateType(Enum):
AFFILIATION_INVITATION_REQUEST_TEMPLATE_NAME = 'affiliation_invitation_request'
AFFILIATION_INVITATION_REQUEST_AUTHORIZATION_TEMPLATE_NAME = 'affiliation_invitation_request_authorization'
STATEMENT_NOTIFICATION_TEMPLATE_NAME = 'statement_notification'
PAYMENT_REMINDER_NOTIFICATION_TEMPLATE_NAME = 'payment_reminder_notification'
PAYMENT_DUE_NOTIFICATION_TEMPLATE_NAME = 'payment_due_notification'


class Constants(Enum):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
Development release segment: .devN
"""

__version__ = '2.18.1' # pylint: disable=invalid-name
__version__ = '2.18.2' # pylint: disable=invalid-name
15 changes: 15 additions & 0 deletions queue_services/account-mailer/src/account_mailer/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,21 @@ async def process_event(event_message: dict, flask_app):
'total_amount_owing': format_currency(email_msg.get('totalAmountOwing')),
'statement_frequency': email_msg.get('statementFrequency').lower()
})
elif message_type in {MessageType.PAYMENT_REMINDER_NOTIFICATION.value,
MessageType.PAYMENT_DUE_NOTIFICATION.value}:
due_date = datetime.fromisoformat(email_msg.get('dueDate'))

email_dict = common_mailer.process(
**{
'org_id': email_msg.get('accountId'),
'recipients': email_msg.get('emailAddresses'),
'template_name': TemplateType[f'{MessageType(message_type).name}_TEMPLATE_NAME'].value,
'subject': SubjectType[MessageType(message_type).name].value,
'logo_url': logo_url,
'due_date': due_date.strftime('%B ') + format_day_with_suffix(due_date.day) + f' {due_date.year}',
'total_amount_owing': format_currency(email_msg.get('totalAmountOwing')),
'statement_frequency': email_msg.get('statementFrequency').lower()
})

else:
if any(x for x in MessageType if x.value == message_type):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,3 +620,85 @@ async def test_statement_notification_email(app, session, stan_server, event_loo
mock_send.assert_called
assert mock_send.call_args.args[0].get('recipients') == '[email protected]'
assert mock_send.call_args.args[0].get('content').get('subject') == SubjectType.STATEMENT_NOTIFICATION.value


@pytest.mark.asyncio
async def test_payment_reminder_notification_email(app, session, stan_server, event_loop, client_id, events_stan,
future):
"""Assert that payment reminder notification events can be retrieved and decoded from the Queue."""
# Call back for the subscription
from account_mailer.worker import cb_subscription_handler

# set up org
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
msg_payload = {
'accountId': id,
'dueDate': '2023-09-15 00:00:00',
'emailAddresses': '[email protected]',
'statementFrequency': 'MONTHLY',
'totalAmountOwing': 351.5
}
await helper_add_event_to_queue(events_stan, events_subject, org_id=id,
msg_type=MessageType.PAYMENT_REMINDER_NOTIFICATION.value,
mail_details=msg_payload)

mock_send.assert_called
assert mock_send.call_args.args[0].get('recipients') == '[email protected]'
assert mock_send.call_args.args[0].\
get('content').get('subject') == SubjectType.PAYMENT_REMINDER_NOTIFICATION.value


@pytest.mark.asyncio
async def test_payment_due_notification_email(app, session, stan_server, event_loop, client_id, events_stan, future):
"""Assert that payment due notification events can be retrieved and decoded from the Queue."""
# Call back for the subscription
from account_mailer.worker import cb_subscription_handler

# set up org
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
msg_payload = {
'accountId': id,
'dueDate': '2023-09-15 00:00:00',
'emailAddresses': '[email protected]',
'statementFrequency': 'MONTHLY',
'totalAmountOwing': 351.5
}
await helper_add_event_to_queue(events_stan, events_subject, org_id=id,
msg_type=MessageType.PAYMENT_DUE_NOTIFICATION.value,
mail_details=msg_payload)

mock_send.assert_called
assert mock_send.call_args.args[0].get('recipients') == '[email protected]'
assert mock_send.call_args.args[0].get('content').get('subject') == SubjectType.PAYMENT_DUE_NOTIFICATION.value