-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
17507 - Receipt Creation when NSF Account Paid and Unlocked (#2632)
* Adding account_restored_nsf email processor * Fixing typo * Cleaning up linting * Lint fixes * lint fixes * Import order * Linting fixes * Cleanup * Cleanup * Cleanup * change enum, add in mock for report-api * add in additional logging * More logging * Fix logging for unit tests * Linting fixes * Bypass service token * Fix linting --------- Co-authored-by: Travis Semple <travis8814@gmail.com>
- Loading branch information
1 parent
afcdc32
commit 78cdb1a
Showing
8 changed files
with
179 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
queue_services/account-mailer/src/account_mailer/email_processors/account_unlock.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Copyright © 2019 Province of British Columbia | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""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 | ||
from entity_queue_common.service_utils import logger | ||
from flask import current_app | ||
from jinja2 import Template | ||
|
||
from account_mailer.email_processors import generate_template | ||
|
||
|
||
def process(email_msg: 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) | ||
return { | ||
'recipients': email_msg.get('admin_coordinator_emails'), | ||
'content': { | ||
'subject': email_msg.get('subject'), | ||
'body': f'{html_body}', | ||
'attachments': [ | ||
{ | ||
'fileName': 'Account_Unlock_Receipt.pdf', | ||
'fileBytes': pdf_attachment.decode('utf-8'), | ||
'fileUrl': '', | ||
'attachOrder': '1' | ||
} | ||
] | ||
} | ||
} | ||
|
||
|
||
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'), | ||
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') | ||
} | ||
|
||
pdf_payload = { | ||
'reportName': 'NSF_Fee_Receipt', | ||
'templateVars': template_vars, | ||
'populatePageNumber': True, | ||
'templateName': 'payment_receipt', | ||
} | ||
|
||
report_response = RestService.post(endpoint=current_app.config.get('REPORT_API_BASE_URL'), | ||
token=token, | ||
auth_header_type=AuthHeaderType.BEARER, | ||
content_type=ContentType.JSON, | ||
data=pdf_payload, | ||
raise_for_status=True, | ||
additional_headers={'Accept': 'application/pdf'}) | ||
pdf_attachment = None | ||
if report_response.status_code != 200: | ||
logger.error('Failed to get pdf') | ||
else: | ||
pdf_attachment = base64.b64encode(report_response.content) | ||
|
||
return pdf_attachment |
9 changes: 0 additions & 9 deletions
9
queue_services/account-mailer/src/account_mailer/email_templates/account_restored_email.html
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
queue_services/account-mailer/src/account_mailer/email_templates/account_unlocked_email.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Account Unlocked | ||
|
||
Your account **{{ account_name }}** has been unlocked. Team members can now log in and access this account. | ||
|
||
Your receipt is attached to this email: | ||
|
||
**Business Registry** | ||
BC Registries and Online Services | ||
Toll Free: [1-877-370-1033](1-877-370-1033) | ||
Victoria Office: [250-370-1033](250-370-1033) | ||
Email: [BCRegistries@gov.bc.ca](BCRegistries@gov.bc.ca) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters