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

17507 - Receipt Creation when NSF Account Paid and Unlocked #1319

Closed
wants to merge 12 commits into from
30 changes: 23 additions & 7 deletions pay-api/src/pay_api/services/payment_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from pay_api.utils.util import (
current_local_time, get_local_formatted_date, get_outstanding_txns_from_date, get_str_by_path, mask)

from .payment import Payment
from .flags import flags


Expand Down Expand Up @@ -772,7 +773,8 @@ def _publish_queue_message(self, payload):
f'Notification to Queue failed for the Account Mailer : {payload}.',
level='error')

def _create_account_event_payload(self, event_type: str, include_pay_info: bool = False):
def create_account_event_payload(self, event_type: str, nsf_object: dict = None,
include_pay_info: bool = False):
"""Return event payload for account."""
payload: Dict[str, any] = {
'specversion': '1.x-wip',
Expand All @@ -787,6 +789,11 @@ def _create_account_event_payload(self, event_type: str, include_pay_info: bool
}
}

if event_type == MessageType.NSF_UNLOCK_ACCOUNT.value:
payload['data']['invoiceNumber'] = nsf_object.payment.invoice_number
payload['data']['paymentMethodDescription'] = nsf_object.payment.payment_method_code
payload['data']['filingIdentifier'] = nsf_object.filing_identifier
payload['data']['receiptNumber'] = nsf_object.receipt_number
if event_type == MessageType.PAD_ACCOUNT_CREATE.value:
payload['data']['padTosAcceptedBy'] = self.pad_tos_accepted_by
if include_pay_info:
Expand All @@ -799,9 +806,9 @@ def _create_account_event_payload(self, event_type: str, include_pay_info: bool
return payload

@staticmethod
def unlock_frozen_accounts(account_id: int):
def unlock_frozen_accounts(payment: Payment, filing_identifier: str, receipt_number: str):
"""Unlock frozen accounts."""
pay_account: PaymentAccount = PaymentAccount.find_by_id(account_id)
pay_account: PaymentAccount = PaymentAccount.find_by_id(payment.payment_account_id)
if pay_account.cfs_account_status == CfsAccountStatus.FREEZE.value:
current_app.logger.info(f'Unlocking Frozen Account {pay_account.auth_account_id}')
# update CSF
Expand All @@ -811,14 +818,23 @@ def unlock_frozen_accounts(account_id: int):
cfs_account.status = CfsAccountStatus.ACTIVE.value
cfs_account.save()

payload = pay_account._create_account_event_payload( # pylint:disable=protected-access
'bc.registry.payment.unlockAccount'
# get nsf payment object associated with this payment

nsf_object = {
'payment': payment,
'filing_identifier': filing_identifier,
'receipt_number': receipt_number
}

payload = pay_account._create_account_event_payload(
MessageType.NSF_UNLOCK_ACCOUNT.value,
nsf_object=nsf_object
)

try:
publish_response(payload=payload,
client_name=current_app.config['NATS_ACCOUNT_CLIENT_NAME'],
subject=current_app.config['NATS_ACCOUNT_SUBJECT'])
client_name=current_app.config['NATS_ACCOUNT_CLIENT_NAME'],
subject=current_app.config['NATS_ACCOUNT_SUBJECT'])
except Exception as e: # NOQA pylint: disable=broad-except
current_app.logger.error(e)
current_app.logger.error(
Expand Down
2 changes: 1 addition & 1 deletion pay-api/src/pay_api/services/payment_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def update_transaction(transaction_id: uuid, # pylint: disable=too-many-locals
active_failed_payments = Payment.get_failed_payments(auth_account_id=payment_account.auth_account_id)
current_app.logger.info('active_failed_payments %s', active_failed_payments)
if not active_failed_payments:
PaymentAccount.unlock_frozen_accounts(payment.payment_account_id)
PaymentAccount.unlock_frozen_accounts(payment, invoice.filing_id, receipt_details)

transaction = PaymentTransaction.__wrap_dao(transaction_dao)

Expand Down
18 changes: 16 additions & 2 deletions report-api/report-templates/payment_receipt.html
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,17 @@
font-family: 'BCSans-Bold', sans-serif;
font-size: 18px;
color: #234075;
border-bottom: 1px solid #b3bac3;
font-weight: bold;
}

.transaction-amount {
margin-left: 24px;
padding-bottom: 12px;
font-size: 16px;
font-weight: 800;
font-family: 'BCSans-Bold', sans-serif;
}

.section-payment-title {
margin: 30px 24px 0px;
/* padding-bottom: 8px; */
Expand Down Expand Up @@ -621,11 +628,18 @@
{% else %}
<tr>
<td colspan="2">
<div class="section-title blue-border-bottom">
<div class="section-title">
Transactions
</div>
</td>
</tr>
<tr>
<td colspan="2">
<div class="transaction-amount blue-border-bottom">
Number of Transactions: {{invoice.lineItems|length}}
</div>
</td>
</tr>
<tr>
<td colspan="2">
<table class="transaction-table">
Expand Down
Loading