Skip to content

Commit

Permalink
19724 - EFT - Create CFS account job modification (#1441)
Browse files Browse the repository at this point in the history
* update api and payment-jobs for EFT cfs_account create

* add updated requirements.txt from PR#18263

* isort fix
  • Loading branch information
Jxio authored Mar 8, 2024
1 parent e0bc697 commit 6390faa
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 76 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/payment-jobs-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ jobs:
needs: setup-job
env:
DATABASE_TEST_URL: "postgresql://postgres:postgres@localhost:5432/postgres"
NATS_QUEUE: "account-worker"
NATS_CLUSTER_ID: "test-cluster"
NATS_CLIENT_NAME: "account.events.worker"
NATS_SUBJECT: "account.events"
USE_DOCKER_MOCK: "YES"
JWT_OIDC_ISSUER: "http://localhost:8081/auth/realms/demo"
SBC_AUTH_ADMIN_CLIENT_ID: "sbc-auth-admin"
Expand Down
133 changes: 65 additions & 68 deletions jobs/payment-jobs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,96 +1,93 @@
-e git+https://github.com/bcgov/sbc-common-components.git@1aa7dc8ed3897ad4bf679c789ac6c66c88550bfe#egg=sbc_common_components&subdirectory=python
-e git+https://github.com/bcgov/sbc-pay.git@a598989a6de74206ab26024d037d0128919e540e#egg=pay_api&subdirectory=pay-api
Flask-Caching==2.0.2
-e git+https://github.com/bcgov/sbc-common-components.git@5807c201b057875f9061f60b408ab765ebaa4235#egg=sbc_common_components&subdirectory=python
-e git+https://github.com/bcgov/sbc-pay.git@e0bc6979b761347b32628a28fa1489e919e5d806#egg=pay_api&subdirectory=pay-api
-e git+https://github.com/thorwolpert/flask-jwt-oidc.git@40cc811ccf70e838c5f7522fe8d83b7e58853539#egg=flask_jwt_oidc
Flask-Caching==2.1.0
Flask-Cors==4.0.0
Flask-Migrate==2.7.0
Flask-Moment==1.0.5
Flask-OpenTracing==1.1.0
Flask-SQLAlchemy==2.5.1
Flask-OpenTracing==2.0.0
Flask-SQLAlchemy==3.1.1
Flask-Script==2.0.6
Flask==1.1.2
Jinja2==3.0.3
Mako==1.2.4
MarkupSafe==2.1.3
PyMeeus==0.5.12
Flask==3.0.2
Jinja2==3.1.3
Mako==1.3.2
MarkupSafe==2.1.5
PyNaCl==1.5.0
SQLAlchemy-Continuum==1.3.15
SQLAlchemy-Utils==0.41.1
SQLAlchemy==1.3.24
Werkzeug==1.0.1
alembic==1.11.1
aniso8601==9.0.1
asyncio-nats-client==0.11.5
asyncio-nats-streaming==0.4.0
attrs==23.1.0
bcrypt==4.0.1
blinker==1.6.2
SQLAlchemy==2.0.28
Werkzeug==3.0.1
alembic==1.13.1
argon2-cffi-bindings==21.2.0
argon2-cffi==23.1.0
attrs==23.2.0
bcrypt==4.1.2
blinker==1.7.0
cachelib==0.9.0
cachetools==5.3.1
cattrs==23.1.2
certifi==2023.7.22
cffi==1.15.1
charset-normalizer==3.1.0
click==8.1.3
convertdate==2.4.0
croniter==1.4.1
cryptography==42.0.2
cachetools==5.3.3
cattrs==23.2.3
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
click==8.1.7
croniter==2.0.2
cryptography==42.0.5
cx-Oracle==8.3.0
dataclass-wizard==0.22.2
dataclass-wizard==0.22.3
dpath==2.1.6
ecdsa==0.18.0
exceptiongroup==1.1.1
exceptiongroup==1.2.0
expiringdict==1.2.2
flask-jwt-oidc==0.3.0
flask-marshmallow==0.11.0
flask-restx==1.1.0
google-api-core==2.11.1
google-auth==2.18.1
google-cloud-pubsub==2.17.0
googleapis-common-protos==1.59.1
grpc-google-iam-v1==0.12.6
grpcio-status==1.48.2
grpcio==1.56.0
gunicorn==20.1.0
hijri-converter==2.3.1
flask-marshmallow==1.2.0
google-api-core==2.17.1
google-auth==2.28.1
google-cloud-pubsub==2.20.0
googleapis-common-protos==1.62.0
greenlet==3.0.3
grpc-google-iam-v1==0.13.0
grpcio-status==1.62.0
grpcio==1.62.0
gunicorn==21.2.0
holidays==0.37
idna==3.4
importlib-metadata==6.7.0
importlib-resources==5.12.0
itsdangerous==2.0.1
idna==3.6
importlib_metadata==7.0.2
importlib_resources==6.1.3
itsdangerous==2.1.2
jaeger-client==4.8.0
jsonschema==4.17.3
korean-lunar-calendar==0.3.1
launchdarkly-server-sdk==8.1.4
marshmallow-sqlalchemy==0.25.0
marshmallow==3.19.0
minio==7.1.15
more-itertools==9.1.0
launchdarkly-eventsource==1.1.1
launchdarkly-server-sdk==9.2.2
marshmallow-sqlalchemy==1.0.0
marshmallow==3.21.1
minio==7.2.5
more-itertools==10.2.0
opentracing==2.4.0
packaging==23.1
packaging==23.2
paramiko==3.4.0
pkgutil_resolve_name==1.3.10
proto-plus==1.22.3
protobuf==3.19.6
psycopg2-binary==2.9.6
proto-plus==1.23.0
protobuf==4.25.3
psycopg2-binary==2.9.9
pyRFC3339==1.1
pyasn1-modules==0.3.0
pyasn1==0.5.0
pyasn1==0.5.1
pycparser==2.21
pyrsistent==0.19.3
pycryptodome==3.20.0
pyrsistent==0.20.0
pysftp==0.2.9
python-dateutil==2.8.2
python-dotenv==1.0.0
python-dateutil==2.9.0.post0
python-dotenv==1.0.1
python-jose==3.3.0
pytz==2023.3
pytz==2024.1
requests==2.31.0
rsa==4.9
semver==2.13.0
sentry-sdk==1.26.0
semver==3.0.2
sentry-sdk==1.41.0
simple-cloudevent @ git+https://github.com/daxiom/simple-cloudevent.py.git@447cabb988202206ac69e71177d7cd11b6c0b002
six==1.16.0
strict-rfc3339==0.7
threadloop==1.0.2
thrift==0.16.0
tornado==6.3.3
typing_extensions==4.6.3
urllib3==1.26.17
zipp==3.15.0
tornado==6.4
typing_extensions==4.10.0
urllib3==2.2.1
zipp==3.17.0
8 changes: 6 additions & 2 deletions jobs/payment-jobs/tasks/cfs_create_account_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from pay_api.models import PaymentAccount as PaymentAccountModel
from pay_api.services.cfs_service import CFSService
from pay_api.services.oauth_service import OAuthService
from pay_api.utils.constants import RECEIPT_METHOD_PAD_DAILY
from pay_api.utils.constants import RECEIPT_METHOD_PAD_DAILY, RECEIPT_METHOD_EFT_MONTHLY
from pay_api.utils.enums import AuthHeaderType, CfsAccountStatus, ContentType, PaymentMethod
from sentry_sdk import capture_message
from services import routing_slip
Expand Down Expand Up @@ -111,8 +111,12 @@ def _create_cfs_account(cls, pending_account: CfsAccountModel, pay_account: Paym
payment_info=payment_info)
pending_account.payment_instrument_number = bank_details.get('payment_instrument_number', None)
else: # It's a new account, now create
if pay_account.payment_method == PaymentMethod.EFT.value:
cfs_account_details = CFSService.create_cfs_account(identifier=pay_account.auth_account_id,
contact_info=contact_info,
receipt_method=RECEIPT_METHOD_EFT_MONTHLY)
# If the account have banking information, then create a PAD account else a regular account.
if pending_account.bank_number and pending_account.bank_branch_number \
elif pending_account.bank_number and pending_account.bank_branch_number \
and pending_account.bank_account_number:
cfs_account_details = CFSService.create_cfs_account(identifier=pay_account.auth_account_id,
contact_info=contact_info,
Expand Down
13 changes: 12 additions & 1 deletion jobs/payment-jobs/tests/jobs/test_cfs_create_account_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from tasks.cfs_create_account_task import CreateAccountTask
from utils import mailer

from .factory import factory_create_online_banking_account, factory_create_pad_account
from .factory import factory_create_online_banking_account, factory_create_pad_account, factory_create_eft_account


def test_create_account_setup(session):
Expand All @@ -50,6 +50,17 @@ def test_create_pad_account(session):
assert cfs_account.cfs_site
assert cfs_account.cfs_account
assert cfs_account.payment_instrument_number


def test_create_eft_account(session):
"""Test create account."""
# Create a pending account first, then call the job
account = factory_create_eft_account(auth_account_id='1')
CreateAccountTask.create_accounts()
account = PaymentAccount.find_by_id(account.id)
cfs_account: CfsAccount = CfsAccount.find_effective_by_account_id(account.id)
assert cfs_account.status == CfsAccountStatus.ACTIVE.value
assert cfs_account.payment_instrument_number is None


def test_create_pad_account_user_error(session):
Expand Down
13 changes: 12 additions & 1 deletion pay-api/src/pay_api/services/eft_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
# limitations under the License.
"""Service to manage CFS EFT Payments."""
from datetime import datetime
from typing import Any, Dict

from flask import current_app

from pay_api.models import CfsAccount as CfsAccountModel
from pay_api.models import Invoice as InvoiceModel
from pay_api.models import InvoiceReference as InvoiceReferenceModel
from pay_api.models import Payment as PaymentModel
from pay_api.models import PaymentAccount as PaymentAccountModel
from pay_api.models import Receipt as ReceiptModel
from pay_api.utils.enums import InvoiceReferenceStatus, PaymentMethod, PaymentStatus
from pay_api.utils.enums import CfsAccountStatus, InvoiceReferenceStatus, PaymentMethod, PaymentStatus

from .deposit_service import DepositService
from .invoice import Invoice
Expand All @@ -37,6 +39,15 @@ def get_payment_method_code(self):
"""Return EFT as the system code."""
return PaymentMethod.EFT.value

def create_account(self, identifier: str, contact_info: Dict[str, Any], payment_info: Dict[str, Any],
**kwargs) -> CfsAccountModel:
"""Create an account for the EFT transactions."""
# Create CFS Account model instance, set the status as PENDING
current_app.logger.info(f'Creating EFT account details in PENDING status for {identifier}')
cfs_account = CfsAccountModel()
cfs_account.status = CfsAccountStatus.PENDING.value
return cfs_account

def create_invoice(self, payment_account: PaymentAccount, line_items: [PaymentLineItem], invoice: Invoice,
**kwargs) -> InvoiceReference:
"""Return a static invoice number for direct pay."""
Expand Down
1 change: 1 addition & 0 deletions pay-api/src/pay_api/services/payment_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ def _save_account(cls, account_request: Dict[str, any], payment_account: Payment
# 2. Existing payment account:
# - If the account was on DIRECT_PAY and switching to Online Banking, and active CFS account is not present.
# - If the account was on DRAWDOWN and switching to PAD, and active CFS account is not present
# - If the account was on PAD and switching to EFT, and active CFS account is not present

if payment_method:
pay_system = PaymentSystemFactory.create_from_payment_method(payment_method=payment_method)
Expand Down
2 changes: 2 additions & 0 deletions pay-api/src/pay_api/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
DEFAULT_CURRENCY = 'CAD'
RECEIPT_METHOD_PAD_DAILY = 'BCR-PAD Daily'
RECEIPT_METHOD_PAD_STOP = 'BCR-PAD Stop'
RECEIPT_METHOD_EFT_MONTHLY = 'BCR-EFT MONTHLY'
RECEIPT_METHOD_EFT_STOP = 'BCR-PAD Stop'

CFS_BATCH_SOURCE = 'BC REG MANUAL_OTHER'
CFS_CM_BATCH_SOURCE = 'MANUAL-OTHER'
Expand Down

0 comments on commit 6390faa

Please sign in to comment.