Reafctor import

This commit is contained in:
CHIEFSOFT\ameye
2025-06-18 23:29:09 -04:00
parent 405c837499
commit 500e749acb
2 changed files with 48 additions and 15 deletions
+17 -15
View File
@@ -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"
+31
View File
@@ -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