Skip to content

Commit

Permalink
20037 - Fix NSF unlock receipt (#2742)
Browse files Browse the repository at this point in the history
* Small changes to pass in all the params to generate a receipt

* lint + tests

* remove unused import

* Add in decent test data

* remove comments

* Update unit test
  • Loading branch information
seeker25 authored Feb 28, 2024
1 parent 20484dd commit a11555b
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"""A Template for the Account Unlocked Email."""

import base64
import datetime

from auth_api.services.rest_service import RestService
from auth_api.utils.enums import AuthHeaderType, ContentType
Expand All @@ -25,15 +24,15 @@
from account_mailer.email_processors import generate_template


def process(email_msg: dict, token: str) -> dict:
def process(data: dict, token: str) -> dict:
"""Build the email for Account Unlocked notification."""
logger.debug('email_msg notification: %s', email_msg)
pdf_attachment = _get_account_unlock_pdf(email_msg, token)
html_body = _get_account_unlock_email(email_msg)
logger.debug('email_msg notification: %s', data)
pdf_attachment = _get_account_unlock_pdf(data, token)
html_body = _get_account_unlock_email(data)
return {
'recipients': email_msg.get('admin_coordinator_emails'),
'recipients': data.get('admin_coordinator_emails'),
'content': {
'subject': email_msg.get('subject'),
'subject': data.get('subject'),
'body': f'{html_body}',
'attachments': [
{
Expand All @@ -51,29 +50,16 @@ def _get_account_unlock_email(email_msg):
filled_template = generate_template(current_app.config.get('TEMPLATE_PATH'), email_msg.get('template_name'))
jnja_template = Template(filled_template, autoescape=True)
html_out = jnja_template.render(
account_name=email_msg.get('account_name'),
account_name=email_msg.get('accountName'),
logo_url=email_msg.get('logo_url')
)
return html_out


def _get_account_unlock_pdf(email_msg, token):
current_time = datetime.datetime.now()
template_vars = {
**email_msg,
'corpName': email_msg.get('account_name'),
'receiptNumber': email_msg.get('receipt_number'),
'filingDate': current_time.strftime('%Y-%m-%d'),
'effectiveDateTime': current_time.strftime('%Y-%m-%d %H:%M:%S'),
'filingIdentifier': email_msg.get('filing_identifier'),
'paymentMethodDescription': email_msg.get('payment_method_description'),
'invoiceNumber': email_msg.get('invoice_number'),
'invoice': email_msg.get('invoice')
}

def _get_account_unlock_pdf(data, token):
pdf_payload = {
'reportName': 'NSF_Fee_Receipt',
'templateVars': template_vars,
'templateVars': data['template_vars'],
'populatePageNumber': True,
'templateName': 'payment_receipt',
}
Expand Down
5 changes: 2 additions & 3 deletions queue_services/account-mailer/src/account_mailer/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,15 @@ async def process_event(event_message: dict, flask_app):
logo_url = email_msg.get('logo_url')

email_dict = {
'account_name': email_msg.get('toOrgName'),
'template_vars': email_msg,
'logo_url': logo_url,
'template_name': template_name,
'subject': subject,
'org_id': org_id,
'admin_coordinator_emails': admin_coordinator_emails,
'filing_identifier': email_msg.get('filing_identifier'),
}

email_dict = account_unlock.process(email_msg=email_dict, token=token)
email_dict = account_unlock.process(data=email_dict, token=token)

elif message_type == MessageType.ACCOUNT_CONFIRMATION_PERIOD_OVER.value:
template_name = TemplateType.ACCOUNT_CONF_OVER_TEMPLATE_NAME.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,88 @@ async def test_unlock_account_mailer_queue(app, session, stan_server, event_loop
response = types.SimpleNamespace()
response.status_code = 200
response.content = bytes('foo', 'utf-8')
# patch RestService.post
with patch.object(notification_service, 'send_email', return_value=None) as mock_send:
# register the handler to test it
with patch.object(RestService, 'post', return_value=response):
await subscribe_to_queue(events_stan,
events_subject,
events_queue,
events_durable_name,
cb_subscription_handler)

# add an event to queue
# Note: This payload should work with report-api.
mail_details = {
'accountId': id,
'accountName': org.name
'accountName': org.name,
'invoiceNumber': 'REG0123456',
'receiptNumber': '99123',
'paymentMethodDescription': 'Credit Card',
'invoice': {
'_links': {
'self': 'http://auth-web.dev.com/api/v1/payment-requests/2',
'collection': 'http://auth-web.dev.com/api/v1/payment-requests?invoice_id=2'
},
'bcolAccount': 'TEST',
'corpTypeCode': 'CP',
'createdName':
'test name',
'id': 2,
'createdBy': 'test',
'paymentAccount': {
'accountId': '1234',
'billable': True
},
'paymentDate': '2024-02-27T09:52:03+00:00',
'total': 130.0,
'paymentMethod': 'CC',
'overdueDate': '2024-03-01T09:52:02+00:00',
'paid': 30.0,
'details': [{'label': 'label', 'value': 'value'}],
'serviceFees': 0.0,
'updatedOn': '2024-02-27T09:52:03+00:00',
'lineItems': [{
'waivedFees': None,
'waivedBy': None,
'gst': 0.0,
'pst': 0.0,
'filingFees': 10.0,
'id': 2,
'serviceFees': 0.0,
'priorityFees': 0.0,
'futureEffectiveFees': 0.0,
'quantity': 1,
'statusCode': 'ACTIVE',
'total': 10.0,
'description': 'NSF Fee'
}, {
'waivedFees': None,
'waivedBy': None,
'gst': 0.0,
'pst': 0.0,
'filingFees': 10.0,
'id': 1,
'serviceFees': 0.0,
'priorityFees': 0.0,
'futureEffectiveFees': 0.0,
'quantity': 1,
'statusCode': 'ACTIVE',
'total': 10.0,
'description': 'Name Request'
}],
'createdOn': '2024-02-27T09:51:55+00:00',
'references': [{
'invoiceNumber': 'REG00001',
'id': 2,
'statusCode': 'COMPLETED'
}],
'receipts': [{
'receiptAmount': 100.0,
'id': 2,
'receiptDate': '2024-02-27T09:52:03.018524',
'receiptNumber': '1234567890'
}],
'statusCode': 'COMPLETED',
'folioNumber': '1234567890'
}
}
await helper_add_event_to_queue(events_stan, events_subject, org_id=id,
msg_type=MessageType.NSF_UNLOCK_ACCOUNT.value, mail_details=mail_details)
Expand Down

0 comments on commit a11555b

Please sign in to comment.