Skip to content

Commit

Permalink
EFT Reconciliation
Browse files Browse the repository at this point in the history
  • Loading branch information
ochiu committed Nov 6, 2023
1 parent 1a1cb0c commit f6efd09
Show file tree
Hide file tree
Showing 12 changed files with 1,247 additions and 12 deletions.
2 changes: 1 addition & 1 deletion queue_services/payment-reconciliations/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-e git+https://github.com/bcgov/lear.git@30dba30463c99aaedfdcfd463213e71ba0d35b51#egg=entity_queue_common&subdirectory=queue_services/common
-e git+https://github.com/bcgov/sbc-common-components.git@b93585ea3ac273b9e51c4dd5ddbc8190fd95da6a#egg=sbc_common_components&subdirectory=python
-e git+https://github.com/bcgov/sbc-pay.git@2e4373b8a9280d64737f7b6ed172831ba4e541d2#egg=pay_api&subdirectory=pay-api
-e git+https://github.com/bcgov/sbc-pay.git@1a1cb0c7b00978a36aed7c0e9d7bcd7148e0401a#egg=pay_api&subdirectory=pay-api
Flask-Caching==2.0.2
Flask-Migrate==2.7.0
Flask-Moment==1.0.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class _Config(): # pylint: disable=too-few-public-methods

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
PAY_LD_SDK_KEY = os.getenv('PAY_LD_SDK_KEY', None)
LEGISLATIVE_TIMEZONE = os.getenv('LEGISLATIVE_TIMEZONE', 'America/Vancouver')

SENTRY_ENABLE = os.getenv('SENTRY_ENABLE', 'False')
SENTRY_DSN = os.getenv('SENTRY_DSN', None)
Expand Down Expand Up @@ -113,6 +114,9 @@ class _Config(): # pylint: disable=too-few-public-methods
CFS_CLIENT_SECRET = os.getenv('CFS_CLIENT_SECRET')
CONNECT_TIMEOUT = int(os.getenv('CONNECT_TIMEOUT', '10'))

# EFT Config
EFT_INVOICE_PREFIX = os.getenv('EFT_INVOICE_PREFIX', 'REG')

# Secret key for encrypting bank account
ACCOUNT_SECRET_KEY = os.getenv('ACCOUNT_SECRET_KEY')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ class EFTError(Enum):
INVALID_DEPOSIT_AMOUNT_CAD = 'Invalid transaction deposit amount CAD.'
INVALID_TRANSACTION_DATE = 'Invalid transaction date.'
INVALID_DEPOSIT_DATETIME = 'Invalid transaction deposit date time'
BCROS_ACCOUNT_NUMBER_REQUIRED = 'BCROS Account number is missing from the transaction description.'
ACCOUNT_SHORTNAME_REQUIRED = 'Account shortname is missing from the transaction description.'

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ def _process(self):
self.location_id = self.extract_value(15, 20)
self.transaction_sequence = self.extract_value(24, 27)

# We are expecting a BCROS account number here, it is required
# We are expecting a SHORTNAME for matching here, it is required
self.transaction_description = self.extract_value(27, 67)
if len(self.transaction_description) == 0:
self.add_error(EFTParseError(EFTError.BCROS_ACCOUNT_NUMBER_REQUIRED))
self.add_error(EFTParseError(EFTError.ACCOUNT_SHORTNAME_REQUIRED))

self.deposit_amount = self.parse_decimal(self.extract_value(67, 80), EFTError.INVALID_DEPOSIT_AMOUNT)
self.currency = self.get_currency(self.extract_value(80, 82))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,12 @@ class TargetTransaction(Enum):
DEBIT_MEMO = 'DM'
CREDIT_MEMO = 'CM'
RECEIPT = 'RECEIPT'


class MessageType(Enum):
"""Event message types."""

CAS_UPLOADED = 'bc.registry.payment.casSettlementUploaded'
CGI_ACK_RECEIVED = 'bc.registry.payment.cgi.ACKReceived'
CGI_FEEDBACK_RECEIVED = 'bc.registry.payment.cgi.FEEDBACKReceived'
EFT_FILE_UPLOADED = 'bc.registry.payment.eft.fileUploaded'
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
Development release segment: .devN
"""

__version__ = '1.1.1' # pylint: disable=invalid-name
__version__ = '1.1.2' # pylint: disable=invalid-name
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

from reconciliations import config
from reconciliations.cgi_reconciliations import reconcile_distributions
from reconciliations.eft.eft_reconciliation import reconcile_eft_payments
from reconciliations.enums import MessageType
from reconciliations.payment_reconciliations import reconcile_payments


Expand All @@ -54,12 +56,14 @@ async def process_event(event_message, flask_app):
raise QueueException('Flask App not available.')

with flask_app.app_context():
if (message_type := event_message.get('type', None)) == 'bc.registry.payment.casSettlementUploaded':
if (message_type := event_message.get('type', None)) == MessageType.CAS_UPLOADED.value:
await reconcile_payments(event_message)
elif message_type == 'bc.registry.payment.cgi.ACKReceived':
elif message_type == MessageType.CGI_ACK_RECEIVED.value:
await reconcile_distributions(event_message)
elif message_type == 'bc.registry.payment.cgi.FEEDBACKReceived':
elif message_type == MessageType.CGI_FEEDBACK_RECEIVED.value:
await reconcile_distributions(event_message, is_feedback=True)
elif message_type == MessageType.EFT_FILE_UPLOADED.value:
await reconcile_eft_payments(event_message)
else:
raise Exception('Invalid type') # pylint: disable=broad-exception-raised

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def factory_invoice(payment_account: PaymentAccount, status_code: str = InvoiceS
invoice_status_code=status_code,
payment_account_id=payment_account.id,
total=total,
paid=0,
created_by='test',
created_on=created_on,
business_identifier=business_identifier,
Expand Down Expand Up @@ -125,6 +126,16 @@ def factory_payment_transaction(payment_id: int):
transaction_start_time=datetime.now()).save()


def factory_create_eft_account(auth_account_id='1234', status=CfsAccountStatus.ACTIVE.value,
cfs_account='1234'):
"""Return Factory."""
account = PaymentAccount(auth_account_id=auth_account_id,
payment_method=PaymentMethod.EFT.value,
name=f'Test EFT {auth_account_id}').save()
CfsAccount(status=status, account_id=account.id, cfs_account=cfs_account).save()
return account


def factory_create_online_banking_account(auth_account_id='1234', status=CfsAccountStatus.PENDING.value,
cfs_account='1234'):
"""Return Factory."""
Expand Down
Loading

0 comments on commit f6efd09

Please sign in to comment.