From 500e749acb0a56062c99f323c30103ff7e55caec Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Wed, 18 Jun 2025 23:29:09 -0400 Subject: [PATCH] Reafctor import --- app/integrations/simbrella.py | 32 +++++++++++++++++--------------- app/routes/autocall.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/app/integrations/simbrella.py b/app/integrations/simbrella.py index b85a8b9..19a9c99 100644 --- a/app/integrations/simbrella.py +++ b/app/integrations/simbrella.py @@ -182,31 +182,33 @@ class SimbrellaClient: def collect_loan_user_initiated(data): # InitiatedBy = USER_INITIATED logger.info(f"Calling CollectLoan collect_loan_user_initiated ******* endpoint with data: {data}") - return SimbrellaClient._collect_loan(data) + return SimbrellaClient._collect_loan(data,1) @staticmethod def collect_loan_user_salary_detect(data): #InitiatedBy = SALARY_DETECT - logger.info(f"salary data: {data}") - try: - salary = SalaryService.add_salary_data(data) - if salary: - return ResponseHelper.success(salary.to_dict(), "Successful") - - except Exception as e: - logger.info(f"Failed to save salary: {e}") - return ResponseHelper.error(message="Failed to call salary endpoint", - status_code=400, - error=str(e) ) + # logger.info(f"salary data: {data}") + # try: + # salary = SalaryService.add_salary_data(data) + # if salary: + # return ResponseHelper.success(salary.to_dict(), "Successful") + # + # except Exception as e: + # logger.info(f"Failed to save salary: {e}") + # return ResponseHelper.error(message="Failed to call salary endpoint", + # status_code=400, + # error=str(e) ) + return SimbrellaClient._collect_loan(data,2) + @staticmethod def collect_loan_user_due_payment(data): # InitiatedBy = REPAYMENT_DUE - return SimbrellaClient._collect_loan(data) + return SimbrellaClient._collect_loan(data,3) @staticmethod - def _collect_loan(data): + def _collect_loan(data, collectionMethod: int): api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}{SimbrellaClient.BANK_CALL_COLLECT_LOAN_ENDPOINT}" logger.info(f"Calling CollectLoan api_url==> : {api_url}") logger.info(f"Calling CollectLoan endpoint with data: {data}") @@ -253,7 +255,7 @@ class SimbrellaClient: "collectAmount": loan_data['repaymentAmount'], "penalCharge": 5, "channel": "USSD", - "collectionMethod": "1", + "collectionMethod": collectionMethod, "lienAmount": 0, "countryId": "NG", "comment": "COLLECT LOAN" diff --git a/app/routes/autocall.py b/app/routes/autocall.py index 525afee..d1471b3 100644 --- a/app/routes/autocall.py +++ b/app/routes/autocall.py @@ -7,6 +7,7 @@ from app.utils.logger import logger from app.integrations.simbrella import SimbrellaClient from app.services.loan import LoanService from app.services.repayment import RepaymentService +from app.services.salary import SalaryService autocall_bp = Blueprint("autocall", __name__) @@ -112,9 +113,39 @@ def penal_charge(): @autocall_bp.route("/analytic-salary-detect", methods=["POST"]) def salary_detect(): + #*************************************************** + # PART 1 Accept any new import of salary detection + #************************************************** data = request.get_json() logger.info(f"Calling Salary Detect Endpoints") + try: + salary = SalaryService.add_salary_data(data) + if salary: + logger.info(f"Successful Salary Added") + # return ResponseHelper.success(salary.to_dict(), "Successful") + except Exception as e: + logger.info(f"Failed to save salary: {e}") + + # *************************************************** + # PART 2 SELECT * FROM salaries WHERE status IS NULL ORDER BY id ASC + # ************************************************** + + #in the loop + # USE the customerID to find thu user Loan + # if loan is/are found for the user + # INSERT INTO repayments TABLE + # repayment = cls( + # customer_id=customer_id, + # loan_id=loan.id, + # product_id=loan.product_id, + # transaction_id = transaction_id, + # created_at=datetime.now(timezone.utc), + # updated_at=datetime.now(timezone.utc), + # initiated_by='SALARY_DETECT' + # ) + + # by the time you call this you must be on repayment table response = SimbrellaClient.collect_loan_user_salary_detect(data) return response \ No newline at end of file