Skip to content
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

25033 - Override Sandbox DIRECT_PAY / ONLINE_BANKING to PAD payment method #1868

Merged
merged 3 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions pay-api/src/pay_api/resources/v1/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from pay_api.utils.auth import jwt as _jwt
from pay_api.utils.constants import EDIT_ROLE, VIEW_ROLE
from pay_api.utils.endpoints_enums import EndpointEnum
from pay_api.utils.enums import CfsAccountStatus, ContentType, Role
from pay_api.utils.enums import CfsAccountStatus, ContentType, PaymentMethod, Role
from pay_api.utils.errors import Error

bp = Blueprint("ACCOUNTS", __name__, url_prefix=f"{EndpointEnum.API_V1.value}/accounts")
Expand All @@ -47,6 +47,13 @@ def post_account():
if is_sandbox and not _jwt.validate_roles([Role.CREATE_SANDBOX_ACCOUNT.value]):
abort(HTTPStatus.FORBIDDEN)

if is_sandbox and request_json.get("paymentInfo", {}).get("methodOfPayment", []) in [
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove when our sandbox supports ONLINE_BANKING AND DIRECT_PAY

PaymentMethod.ONLINE_BANKING.value,
PaymentMethod.DIRECT_PAY.value,
]:
current_app.logger.info('Overriding methodOfPayment to "PAD" for sandbox request')
request_json["paymentInfo"]["methodOfPayment"] = PaymentMethod.PAD.value

# Validate the input request
valid_format, errors = schema_utils.validate(request_json, "account_info")

Expand Down Expand Up @@ -269,11 +276,17 @@ def post_search_purchase_history(account_number: str):

any_org_transactions = request.args.get("viewAll", None) == "true"
if any_org_transactions:
check_auth(business_identifier=None, account_id=account_number,
all_of_roles=[Role.EDITOR.value, Role.VIEW_ALL_TRANSACTIONS.value])
check_auth(
business_identifier=None,
account_id=account_number,
all_of_roles=[Role.EDITOR.value, Role.VIEW_ALL_TRANSACTIONS.value],
)
else:
check_auth(business_identifier=None, account_id=account_number,
one_of_roles=[Role.EDITOR.value, Role.VIEW_ACCOUNT_TRANSACTIONS.value])
check_auth(
business_identifier=None,
account_id=account_number,
one_of_roles=[Role.EDITOR.value, Role.VIEW_ACCOUNT_TRANSACTIONS.value],
)

account_to_search = None if any_org_transactions else account_number
page: int = int(request.args.get("page", "1"))
Expand Down Expand Up @@ -308,8 +321,11 @@ def post_account_purchase_report(account_number: str):
report_name = f"{report_name}.csv"

# Check if user is authorized to perform this action
check_auth(business_identifier=None, account_id=account_number,
one_of_roles=[EDIT_ROLE, Role.VIEW_ACCOUNT_TRANSACTIONS.value])
check_auth(
business_identifier=None,
account_id=account_number,
one_of_roles=[EDIT_ROLE, Role.VIEW_ACCOUNT_TRANSACTIONS.value],
)
try:
report = Payment.create_payment_report(account_number, request_json, response_content_type, report_name)
response = Response(report, 201)
Expand Down
5 changes: 3 additions & 2 deletions pay-api/src/pay_api/resources/v1/account_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ def get_account_statement(account_id: str, statement_id: str):
response_content_type = request.headers.get("Accept", ContentType.PDF.value)

# Check if user is authorized to perform this action
auth = check_auth(business_identifier=None, account_id=account_id, one_of_roles=[EDIT_ROLE,
Role.VIEW_STATEMENTS.value])
auth = check_auth(
business_identifier=None, account_id=account_id, one_of_roles=[EDIT_ROLE, Role.VIEW_STATEMENTS.value]
)

report, report_name = StatementService.get_statement_report(
statement_id=statement_id, content_type=response_content_type, auth=auth
Expand Down
11 changes: 8 additions & 3 deletions pay-api/src/pay_api/services/payment_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from pay_api.utils.constants import EDIT_ROLE
from pay_api.utils.enums import InvoiceReferenceStatus, InvoiceStatus, LineItemStatus, PaymentMethod, PaymentStatus
from pay_api.utils.errors import Error
from pay_api.utils.user_context import UserContext, user_context
from pay_api.utils.util import generate_transaction_number, get_str_by_path

from .base_payment_system import PaymentSystemService
Expand All @@ -43,10 +44,9 @@ class PaymentService: # pylint: disable=too-few-public-methods
"""Service to manage Payment related operations."""

@classmethod
@user_context
def create_invoice(
cls,
payment_request: Tuple[Dict[str, Any]],
authorization: Tuple[Dict[str, Any]],
cls, payment_request: Tuple[Dict[str, Any]], authorization: Tuple[Dict[str, Any]], **kwargs
) -> Dict:
# pylint: disable=too-many-locals, too-many-statements
"""Create payment related records.
Expand Down Expand Up @@ -77,6 +77,11 @@ def create_invoice(
if payment_method == PaymentMethod.EFT.value and not flags.is_on("enable-eft-payment-method", default=False):
raise BusinessException(Error.INVALID_PAYMENT_METHOD)

user: UserContext = kwargs["user"]
if user.is_api_user() and not user.is_sandbox():
if payment_method in [PaymentMethod.DIRECT_PAY.value, PaymentMethod.ONLINE_BANKING.value]:
raise BusinessException(Error.INVALID_PAYMENT_METHOD)

current_app.logger.info(
f"Creating Payment Request : "
f"{payment_method}, {corp_type}, {business_identifier}, "
Expand Down
1 change: 1 addition & 0 deletions pay-api/src/pay_api/utils/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class Role(Enum):
VIEW_STATEMENTS = "view_statements"
VIEW_STATEMENT_SETTINGS = "view_statement_settings"
VIEW_ACCOUNT_TRANSACTIONS = "view_account_transactions"
API_USER = "api_user"


class Code(Enum):
Expand Down
4 changes: 4 additions & 0 deletions pay-api/src/pay_api/utils/user_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ def is_sandbox(self) -> bool:
"""Return True if the user token has sandbox role."""
return Role.SANDBOX.value in self._roles if self._roles else False

def is_api_user(self) -> bool:
"""Return True if the user is an api_user."""
return Role.API_USER.value in self._roles if self._roles else False

@property
def name(self) -> str:
"""Return the name."""
Expand Down