Skip to content

Commit

Permalink
18099 - PAY API - endpoint to add EFT Allowed flag to an account (#1307)
Browse files Browse the repository at this point in the history
* add eft flag to "get payment account route"

* fix event_listener issue

* fix queue_listener issue

* add eft_enable to payment_accounts datamodel

* make eft_enable non-nullable

* lint error fix

* add a route to enable eft

* add eft_enable column to payment_accounts_version

* fix from code review

* unit test fix

* add back missing test payload for eft_enable

* fix flake8 error
  • Loading branch information
Jxio authored Oct 30, 2023
1 parent 95cf80f commit 69d2fd3
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""18099-eft allowed flag
Revision ID: 2ef58b39cafc
Revises: 194cdd7cf986
Create Date: 2023-10-26 13:31:50.959562
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '2ef58b39cafc'
down_revision = '194cdd7cf986'
branch_labels = None
depends_on = None


def upgrade():
op.execute("set statement_timeout=20000;")
op.add_column('payment_accounts', sa.Column('eft_enable', sa.Boolean(), nullable=False, default=False))
op.add_column('payment_accounts_version', sa.Column('eft_enable', sa.Boolean(), nullable=False, default=False))


def downgrade():
op.execute("set statement_timeout=20000;")
op.drop_column('payment_accounts', 'eft_enable')
op.drop_column('payment_accounts_version', 'eft_enable')
2 changes: 2 additions & 0 deletions pay-api/src/pay_api/models/payment_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class PaymentAccount(VersionedModel): # pylint: disable=too-many-instance-attri
'created_name',
'created_on',
'credit',
'eft_enable',
'name',
'pad_activation_date',
'pad_tos_accepted_by',
Expand Down Expand Up @@ -77,6 +78,7 @@ class PaymentAccount(VersionedModel): # pylint: disable=too-many-instance-attri

credit = db.Column(db.Numeric(19, 2), nullable=True)
billable = db.Column(Boolean(), default=True)
eft_enable = db.Column(Boolean(), default=False)

# before this date , the account shouldn't get used
pad_activation_date = db.Column(db.DateTime, nullable=True)
Expand Down
17 changes: 17 additions & 0 deletions pay-api/src/pay_api/resources/v1/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@ def get_account(account_number: str):
return jsonify(response), status


@bp.route('/<string:account_number>/eft', methods=['PATCH'])
@cross_origin(origins='*')
@_tracing.trace()
@_jwt.has_one_of_roles([Role.SYSTEM.value])
def patch_account(account_number: str):
"""Enable eft for an account."""
current_app.logger.info('<patch_account_enable_eft')

try:
response, status = PaymentAccountService.enable_eft(account_number), HTTPStatus.OK
except ServiceUnavailableException as exception:
return exception.response()

current_app.logger.debug('>patch_account_enable_eft')
return jsonify(response.asdict()), status


@bp.route('/<string:account_number>', methods=['PUT'])
@cross_origin(origins='*')
@_tracing.trace()
Expand Down
21 changes: 21 additions & 0 deletions pay-api/src/pay_api/services/payment_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def __init__(self):
self._cfs_account_id: Optional[int] = None
self._cfs_account_status: Optional[str] = None
self._billable: Optional[bool] = None
self._eft_enable: Optional[bool] = None

@property
def _dao(self):
Expand All @@ -89,6 +90,7 @@ def _dao(self, value: PaymentAccountModel):
self.pad_tos_accepted_date: datetime = self._dao.pad_tos_accepted_date
self.credit: Decimal = self._dao.credit
self.billable: bool = self._dao.billable
self.eft_enable: bool = self._dao.eft_enable

cfs_account: CfsAccountModel = CfsAccountModel.find_effective_by_account_id(self.id)
if cfs_account:
Expand Down Expand Up @@ -305,6 +307,17 @@ def billable(self, value: bool):
self._billable = value
self._dao.billable = value

@property
def eft_enable(self):
"""Return the eft_enable."""
return self._eft_enable

@eft_enable.setter
def eft_enable(self, value: bool):
"""Set the eft_enable."""
self._eft_enable = value
self._dao.eft_enable = value

def save(self):
"""Save the information to the DB."""
return self._dao.save()
Expand Down Expand Up @@ -699,3 +712,11 @@ def delete_account(cls, auth_account_id: str) -> PaymentAccount:
if pay_account.statement_notification_enabled:
pay_account.statement_notification_enabled = False
pay_account.save()

@classmethod
def enable_eft(cls, auth_account_id: str) -> PaymentAccount:
"""Enable EFT on the payment account."""
pay_account: PaymentAccountModel = PaymentAccountModel.find_by_auth_account_id(auth_account_id)
pay_account.eft_enable = True
pay_account.save()
return pay_account
17 changes: 15 additions & 2 deletions pay-api/tests/unit/services/test_payment_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
from pay_api.utils.util import get_outstanding_txns_from_date
from tests.utilities.base_test import (
factory_invoice, factory_payment_account, factory_premium_payment_account, get_auth_basic_user,
get_auth_premium_user, get_basic_account_payload, get_pad_account_payload, get_premium_account_payload,
get_unlinked_pad_account_payload)
get_auth_premium_user, get_basic_account_payload, get_eft_enable_account_payload, get_pad_account_payload,
get_premium_account_payload, get_unlinked_pad_account_payload)


def test_account_saved_from_new(session):
Expand Down Expand Up @@ -244,3 +244,16 @@ def test_delete_account_failures(session):
PaymentAccountService.delete_account(payload.get('accountId'))

assert excinfo.value.code == Error.TRANSACTIONS_IN_PROGRESS.code


@pytest.mark.parametrize('payload', [
get_eft_enable_account_payload()
])
def test_patch_account(session, payload):
"""Assert that patch payment account works."""
pay_account: PaymentAccountService = PaymentAccountService.create(payload)
PaymentAccountService.enable_eft(payload.get('accountId'))

# Try to find the account by id.
pay_account = PaymentAccountService.find_by_id(pay_account.id)
assert pay_account.eft_enable is True
20 changes: 19 additions & 1 deletion pay-api/tests/utilities/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ def factory_payment_account(payment_system_code: str = 'PAYBC', payment_method_c
bcol_account='TEST',
name=name,
payment_method=payment_method_code,
pad_activation_date=datetime.now()
pad_activation_date=datetime.now(),
eft_enable=False
).save()

CfsAccount(cfs_party='11111',
Expand All @@ -405,6 +406,7 @@ def factory_premium_payment_account(bcol_user_id='PB25020', bcol_account_id='123
account = PaymentAccount(auth_account_id=auth_account_id,
bcol_user_id=bcol_user_id,
bcol_account=bcol_account_id,
eft_enable=False
)
return account

Expand Down Expand Up @@ -758,6 +760,22 @@ def get_premium_account_payload(payment_method: str = PaymentMethod.DRAWDOWN.val
}


def get_eft_enable_account_payload(payment_method: str = PaymentMethod.DRAWDOWN.value,
account_id: int = randrange(999999)):
"""Return a premium eft enable payment account object."""
return {
'accountId': account_id,
'accountName': 'Test Account',
'bcolAccountNumber': '2000000',
'bcolUserId': 'U100000',
'eft_enable': False,
'paymentInfo': {
'methodOfPayment': payment_method,
'billable': True
}
}


def get_pad_account_payload(account_id: int = randrange(999999), bank_number: str = '001', transit_number='999',
bank_account='1234567890'):
"""Return a pad payment account object."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class _Config(): # pylint: disable=too-few-public-methods
Used as the base for all the other configurations.
"""

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

Expand Down

0 comments on commit 69d2fd3

Please sign in to comment.