Skip to content

Commit

Permalink
18756 - Raise business exception on invoice creation if cfs account i…
Browse files Browse the repository at this point in the history
…s frozen. (#1329)

* Raise business exception on invoice creation if cfs account is frozen.

* missing character

* Add in condition that should fix unit tests.

* Fix
  • Loading branch information
seeker25 authored Nov 27, 2023
1 parent c671f95 commit 5150fc0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pay-api/src/pay_api/services/pad_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

from flask import current_app

from pay_api.exceptions import BusinessException
from pay_api.models import CfsAccount as CfsAccountModel
from pay_api.models import Invoice as InvoiceModel
from pay_api.services.base_payment_system import PaymentSystemService
from pay_api.services.cfs_service import CFSService
from pay_api.services.invoice import Invoice
from pay_api.services.invoice_reference import InvoiceReference
from pay_api.services.payment_account import PaymentAccount
from pay_api.utils.errors import Error
from pay_api.utils.enums import CfsAccountStatus, InvoiceStatus, PaymentMethod, PaymentSystem
from pay_api.utils.user_context import user_context

Expand Down Expand Up @@ -100,6 +102,11 @@ def update_account(self, name: str, cfs_account: CfsAccountModel, payment_info:
def create_invoice(self, payment_account: PaymentAccount, line_items: [PaymentLineItem], invoice: Invoice,
**kwargs) -> InvoiceReference: # pylint: disable=unused-argument
"""Return a static invoice number for direct pay."""
if payment_account.cfs_account_status == CfsAccountStatus.FREEZE.value:
# Note NSF (Account Unlocking) is paid using DIRECT_PAY - CC flow, not PAD.
current_app.logger.info(f'Account {payment_account.id} is frozen, rejecting invoice creation')
raise BusinessException(Error.PAD_CURRENTLY_NSF)

# Do nothing here as the invoice references are created later.
# If the account have credit, deduct the credit amount which will be synced when reconciliation runs.
account_credit = payment_account.credit or 0
Expand Down
2 changes: 2 additions & 0 deletions pay-api/src/pay_api/utils/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Error(Enum):

ACCOUNT_IN_PAD_CONFIRMATION_PERIOD = 'ACCOUNT_IN_PAD_CONFIRMATION_PERIOD', HTTPStatus.BAD_REQUEST

PAD_CURRENTLY_NSF = 'PAD_CURRENTLY_NSF', HTTPStatus.BAD_REQUEST

CANCELLED_PAYMENT = 'CANCELLED_PAYMENT', HTTPStatus.BAD_REQUEST

INVALID_INVOICE_ID = 'INVALID_INVOICE_ID', HTTPStatus.BAD_REQUEST
Expand Down

0 comments on commit 5150fc0

Please sign in to comment.