Reafctor import
This commit is contained in:
@@ -182,31 +182,33 @@ class SimbrellaClient:
|
|||||||
def collect_loan_user_initiated(data):
|
def collect_loan_user_initiated(data):
|
||||||
# InitiatedBy = USER_INITIATED
|
# InitiatedBy = USER_INITIATED
|
||||||
logger.info(f"Calling CollectLoan collect_loan_user_initiated ******* endpoint with data: {data}")
|
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
|
@staticmethod
|
||||||
def collect_loan_user_salary_detect(data):
|
def collect_loan_user_salary_detect(data):
|
||||||
#InitiatedBy = SALARY_DETECT
|
#InitiatedBy = SALARY_DETECT
|
||||||
logger.info(f"salary data: {data}")
|
# logger.info(f"salary data: {data}")
|
||||||
try:
|
# try:
|
||||||
salary = SalaryService.add_salary_data(data)
|
# salary = SalaryService.add_salary_data(data)
|
||||||
if salary:
|
# if salary:
|
||||||
return ResponseHelper.success(salary.to_dict(), "Successful")
|
# return ResponseHelper.success(salary.to_dict(), "Successful")
|
||||||
|
#
|
||||||
except Exception as e:
|
# except Exception as e:
|
||||||
logger.info(f"Failed to save salary: {e}")
|
# logger.info(f"Failed to save salary: {e}")
|
||||||
return ResponseHelper.error(message="Failed to call salary endpoint",
|
# return ResponseHelper.error(message="Failed to call salary endpoint",
|
||||||
status_code=400,
|
# status_code=400,
|
||||||
error=str(e) )
|
# error=str(e) )
|
||||||
|
return SimbrellaClient._collect_loan(data,2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def collect_loan_user_due_payment(data):
|
def collect_loan_user_due_payment(data):
|
||||||
# InitiatedBy = REPAYMENT_DUE
|
# InitiatedBy = REPAYMENT_DUE
|
||||||
return SimbrellaClient._collect_loan(data)
|
return SimbrellaClient._collect_loan(data,3)
|
||||||
|
|
||||||
@staticmethod
|
@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}"
|
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 api_url==> : {api_url}")
|
||||||
logger.info(f"Calling CollectLoan endpoint with data: {data}")
|
logger.info(f"Calling CollectLoan endpoint with data: {data}")
|
||||||
@@ -253,7 +255,7 @@ class SimbrellaClient:
|
|||||||
"collectAmount": loan_data['repaymentAmount'],
|
"collectAmount": loan_data['repaymentAmount'],
|
||||||
"penalCharge": 5,
|
"penalCharge": 5,
|
||||||
"channel": "USSD",
|
"channel": "USSD",
|
||||||
"collectionMethod": "1",
|
"collectionMethod": collectionMethod,
|
||||||
"lienAmount": 0,
|
"lienAmount": 0,
|
||||||
"countryId": "NG",
|
"countryId": "NG",
|
||||||
"comment": "COLLECT LOAN"
|
"comment": "COLLECT LOAN"
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from app.utils.logger import logger
|
|||||||
from app.integrations.simbrella import SimbrellaClient
|
from app.integrations.simbrella import SimbrellaClient
|
||||||
from app.services.loan import LoanService
|
from app.services.loan import LoanService
|
||||||
from app.services.repayment import RepaymentService
|
from app.services.repayment import RepaymentService
|
||||||
|
from app.services.salary import SalaryService
|
||||||
|
|
||||||
autocall_bp = Blueprint("autocall", __name__)
|
autocall_bp = Blueprint("autocall", __name__)
|
||||||
|
|
||||||
@@ -112,9 +113,39 @@ def penal_charge():
|
|||||||
|
|
||||||
@autocall_bp.route("/analytic-salary-detect", methods=["POST"])
|
@autocall_bp.route("/analytic-salary-detect", methods=["POST"])
|
||||||
def salary_detect():
|
def salary_detect():
|
||||||
|
#***************************************************
|
||||||
|
# PART 1 Accept any new import of salary detection
|
||||||
|
#**************************************************
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
logger.info(f"Calling Salary Detect Endpoints")
|
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)
|
response = SimbrellaClient.collect_loan_user_salary_detect(data)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
Reference in New Issue
Block a user