-
Notifications
You must be signed in to change notification settings - Fork 39
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
19334 - Adding Find EFT Accounts Endpoint #1392
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright © 2019 Province of British Columbia | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Resource for Payment account.""" | ||
from http import HTTPStatus | ||
|
||
from flask import Blueprint, current_app, request | ||
from flask_cors import cross_origin | ||
|
||
from pay_api.services.payment_account import EFTAccountsSearch | ||
from pay_api.services.payment_account import PaymentAccount as PaymentAccountService | ||
from pay_api.utils.auth import jwt as _jwt | ||
from pay_api.utils.endpoints_enums import EndpointEnum | ||
from pay_api.utils.enums import Role | ||
from pay_api.utils.trace import tracing as _tracing | ||
|
||
|
||
bp = Blueprint('EFT_ACCOUNTS', __name__, url_prefix=f'{EndpointEnum.API_V1.value}/eft-accounts') | ||
|
||
|
||
@bp.route('', methods=['GET', 'OPTIONS']) | ||
@cross_origin(origins='*', methods=['GET']) | ||
@_tracing.trace() | ||
@_jwt.has_one_of_roles([Role.SYSTEM.value, Role.STAFF.value]) | ||
def get_eft_accounts(): | ||
"""Get EFT Payment Accounts.""" | ||
eft_accounts_search = EFTAccountsSearch( | ||
request.args.get('state', None), | ||
int(request.args.get('page', '1')), | ||
int(request.args.get('limit', '10'))) | ||
|
||
current_app.logger.info('<get_eft_accounts') | ||
|
||
response, status = PaymentAccountService.find_eft_accounts(eft_accounts_search), HTTPStatus.OK | ||
|
||
current_app.logger.debug('>get_eft_accounts') | ||
return response, status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
"""Service to manage Payment Account model related operations.""" | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from datetime import date, datetime, timedelta, timezone | ||
from decimal import Decimal | ||
from typing import Any, Dict, List, Optional, Tuple | ||
|
@@ -28,9 +29,10 @@ | |
from pay_api.models import CfsAccount as CfsAccountModel | ||
from pay_api.models import EFTCredit as EFTCreditModel | ||
from pay_api.models import EFTCreditInvoiceLink as EFTCreditInvoiceLinkModel | ||
from pay_api.models import EFTShortnames as EFTShortnamesModel | ||
from pay_api.models import Invoice as InvoiceModel | ||
from pay_api.models import PaymentAccount as PaymentAccountModel | ||
from pay_api.models import PaymentAccountSchema | ||
from pay_api.models import PaymentAccountSchema, PaymentAccountSearchModel | ||
from pay_api.models import StatementRecipients as StatementRecipientModel | ||
from pay_api.models import StatementSettings as StatementSettingsModel | ||
from pay_api.models import db | ||
|
@@ -40,9 +42,10 @@ | |
from pay_api.services.queue_publisher import publish_response | ||
from pay_api.services.statement import Statement | ||
from pay_api.services.statement_settings import StatementSettings | ||
from pay_api.utils.converter import Converter | ||
from pay_api.utils.enums import ( | ||
AuthHeaderType, CfsAccountStatus, ContentType, InvoiceStatus, MessageType, PaymentMethod, PaymentSystem, | ||
StatementFrequency) | ||
AuthHeaderType, CfsAccountStatus, ContentType, EFTShortnameState, InvoiceStatus, MessageType, PaymentMethod, | ||
PaymentSystem, StatementFrequency) | ||
from pay_api.utils.errors import Error | ||
from pay_api.utils.user_context import UserContext, user_context | ||
from pay_api.utils.util import ( | ||
|
@@ -52,6 +55,15 @@ | |
from .flags import flags | ||
|
||
|
||
@dataclass | ||
class EFTAccountsSearch: | ||
"""Used for searching EFT accounts.""" | ||
|
||
state: Optional[str] = None | ||
page: Optional[int] = 1 | ||
limit: Optional[int] = 10 | ||
|
||
|
||
class PaymentAccount(): # pylint: disable=too-many-instance-attributes, too-many-public-methods | ||
"""Service to manage Payment Account model related operations.""" | ||
|
||
|
@@ -652,6 +664,38 @@ def find_by_id(cls, account_id: int): | |
account._dao = PaymentAccountModel.find_by_id(account_id) # pylint: disable=protected-access | ||
return account | ||
|
||
@classmethod | ||
def find_eft_accounts(cls, eft_accounts_search: EFTAccountsSearch): | ||
"""Find EFT accounts.""" | ||
query = db.session.query(PaymentAccountModel) \ | ||
.outerjoin(EFTShortnamesModel, PaymentAccountModel.auth_account_id == EFTShortnamesModel.auth_account_id) \ | ||
.filter(PaymentAccountModel.payment_method == PaymentMethod.EFT.value, | ||
PaymentAccountModel.eft_enable.is_(True)) | ||
|
||
if eft_accounts_search.state == EFTShortnameState.UNLINKED.value: | ||
query = query.filter(EFTShortnamesModel.auth_account_id.is_(None)) | ||
elif eft_accounts_search.state == EFTShortnameState.LINKED.value: | ||
query = query.filter(EFTShortnamesModel.auth_account_id.isnot(None)) | ||
|
||
query = query.order_by(PaymentAccountModel.id) | ||
pagination = query.paginate(per_page=eft_accounts_search.limit, page=eft_accounts_search.page) | ||
|
||
total = pagination.total | ||
eft_accounts = pagination.items | ||
|
||
eft_accounts_list = [PaymentAccountSearchModel.from_row(eft_account) for eft_account in eft_accounts] | ||
converter = Converter() | ||
eft_accounts_list = converter.unstructure(eft_accounts_list) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
data = { | ||
'total': total, | ||
'page': eft_accounts_search.page, | ||
'limit': eft_accounts_search.limit, | ||
'items': eft_accounts_list | ||
} | ||
|
||
return data | ||
|
||
@classmethod | ||
def get_eft_credit_balance(cls, account_id: int) -> Decimal: | ||
"""Calculate pay account eft balance by account id.""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'total': pagination.total
eft_accounts_list = [PaymentAccountSearchModel.from_row(eft_account) for eft_account in pagination.items]