From 5c8505f923cda01254bd1bb65dae573a23672acb Mon Sep 17 00:00:00 2001 From: Chinenye Nmoh Date: Thu, 30 Oct 2025 17:17:13 +0100 Subject: [PATCH 1/2] added new config --- app/config.py | 3 ++- app/helpers/collect_loan_helper.py | 14 +++++++++----- app/integrations/simbrella.py | 3 +-- app/utils/auth.py | 6 +++--- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/config.py b/app/config.py index 5845270..5c67b11 100644 --- a/app/config.py +++ b/app/config.py @@ -43,6 +43,7 @@ class Config: # SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{DATABASE_USER}:{DATABASE_PASSWORD}@{DATABASE_HOST}:{DATABASE_PORT}/{DATABASE_NAME}" SQLALCHEMY_TRACK_MODIFICATIONS = False # SQLALCHEMY_ECHO = True + OVERRIDE_COLLECTION_TRANCATION_ID = int(os.getenv("OVERRIDE_COLLECTION_TRANCATION_ID", 100)) MAIL_SERVER = os.getenv('MAIL_SERVER','smtp.zoho.com') @@ -60,7 +61,7 @@ class Config: BANK_CALL_COLLECT_LOAN_ENDPOINT = os.getenv("BANK_CALL_COLLECT_LOAN_ENDPOINT","/CollectLoan") BANK_CALL_TRANSACTION_VERIFY = os.getenv("BANK_CALL_TRANSACTION_VERIFY", "/TransactionVerify") BANK_HEALTH_CHECK_ENDPOINT = os.getenv("BANK_HEALTH_CHECK_ENDPOINT", "/system-health-check") - BANK_CALL_AUTH_ENDPOINT = os.getenv("BANK_CALL_AUTH_ENDPOINT", "/api/Auth/generate-token") + BANK_CALL_AUTH_ENDPOINT = os.getenv("BANK_CALL_AUTH_ENDPOINT", "/Auth/generate-token") BANK_GRANT_TYPE = os.getenv("BANK_GRANT_TYPE", "password") TEST_NO = os.getenv("TEST_NO", "2347038224367") diff --git a/app/helpers/collect_loan_helper.py b/app/helpers/collect_loan_helper.py index 7a1e603..369d4b2 100644 --- a/app/helpers/collect_loan_helper.py +++ b/app/helpers/collect_loan_helper.py @@ -4,9 +4,9 @@ from app.services.repayment import RepaymentService from app.services.loan import LoanService from app.helpers.response_helper import ResponseHelper from app.utils.logger import logger -from decimal import Decimal, ROUND_HALF_UP -from app.services.loan_repayment_schedule import LoanRepaymentScheduleService -from app.enums.loan_status import LoanStatus +from app.config import settings + +OVERRIDE_COLLECTION_TRANCATION_ID = settings.OVERRIDE_COLLECTION_TRANCATION_ID class CollectLoanHelper: @staticmethod @@ -27,9 +27,13 @@ class CollectLoanHelper: @staticmethod def _build_collect_loan_payload(loan_data, repayment_data, data, collectionMethod): - debtId = str(loan_data.get('debtId', "")).strip().zfill(6) - t_id = ''.join(random.choices(string.ascii_uppercase, k=22)) + logger.info(f"building CollectLoan endpoint with data: {loan_data}") + debtId = str(loan_data.get('debtId', "")).strip().zfill(6) + #this can be overridden based on config + t_id = ''.join(random.choices(string.ascii_uppercase, k=22)) + if OVERRIDE_COLLECTION_TRANCATION_ID == 100: + t_id = loan_data['transactionId'] return { "transactionId": t_id, "fbnTransactionId": loan_data['transactionId'], diff --git a/app/integrations/simbrella.py b/app/integrations/simbrella.py index 6d701bb..9a6a162 100644 --- a/app/integrations/simbrella.py +++ b/app/integrations/simbrella.py @@ -18,9 +18,8 @@ from app.services.salary import SalaryService from app.enums.loan_status import LoanStatus from app.models.loan_repayment_schedule import LoanRepaymentSchedule from decimal import Decimal, ROUND_HALF_UP -from requests.exceptions import SSLError, RequestException,Timeout +from requests.exceptions import SSLError, RequestException,Timeout,ReadTimeout, ConnectTimeout import sys -from requests.exceptions import ReadTimeout, ConnectTimeout import socket from app.helpers.collect_loan_helper import CollectLoanHelper diff --git a/app/utils/auth.py b/app/utils/auth.py index 6401cbb..f805f7a 100644 --- a/app/utils/auth.py +++ b/app/utils/auth.py @@ -9,7 +9,7 @@ def get_headers(): BANK_CALL_BASIC_AUTH_PASSWORD = settings.BANK_CALL_BASIC_AUTH_PASSWORD BANK_GRANT_TYPE = settings.BANK_GRANT_TYPE #authenticate - url = f"{BANK_CALL_BASE_URL}{BANK_CALL_AUTH_ENDPOINT}" + url = f"{BANK_CALL_BASE_URL}/Auth/generate-token" data = { "grant_type": BANK_GRANT_TYPE, "username": BANK_CALL_BASIC_AUTH_USERNAME, @@ -41,7 +41,7 @@ def get_headers(): except requests.exceptions.RequestException as e: logger.error(f"Failed to get auth token: {e}") - return {"error": "Authentication request failed"} + raise except ValueError as e: logger.error(f"Failed to parse auth response JSON: {e}") - return {"error": "Invalid authentication response"} + raise From 417dfecf9dcf81434f26f154f6b4c692ea3dc912 Mon Sep 17 00:00:00 2001 From: Chinenye Nmoh Date: Thu, 30 Oct 2025 17:18:43 +0100 Subject: [PATCH 2/2] added new config --- app/utils/auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/utils/auth.py b/app/utils/auth.py index f805f7a..34ed4fd 100644 --- a/app/utils/auth.py +++ b/app/utils/auth.py @@ -9,7 +9,7 @@ def get_headers(): BANK_CALL_BASIC_AUTH_PASSWORD = settings.BANK_CALL_BASIC_AUTH_PASSWORD BANK_GRANT_TYPE = settings.BANK_GRANT_TYPE #authenticate - url = f"{BANK_CALL_BASE_URL}/Auth/generate-token" + url = f"{BANK_CALL_BASE_URL}{BANK_CALL_AUTH_ENDPOINT}" data = { "grant_type": BANK_GRANT_TYPE, "username": BANK_CALL_BASIC_AUTH_USERNAME,