added logs
This commit is contained in:
@@ -230,6 +230,7 @@ class SimbrellaClient:
|
|||||||
logger.error("Received 404 from external service")
|
logger.error("Received 404 from external service")
|
||||||
return ResponseHelper.error("Verify Service url not found (404)", status_code=404)
|
return ResponseHelper.error("Verify Service url not found (404)", status_code=404)
|
||||||
result = response.json()
|
result = response.json()
|
||||||
|
#check for res 00 and status 200
|
||||||
logger.info(f"this is verify result, {result}")
|
logger.info(f"this is verify result, {result}")
|
||||||
LoanService.set_disburse_verify_result(loan_data['debtId'],result.get('responseCode', ''), result.get('responseMessage', ''))
|
LoanService.set_disburse_verify_result(loan_data['debtId'],result.get('responseCode', ''), result.get('responseMessage', ''))
|
||||||
sms_data = {
|
sms_data = {
|
||||||
|
|||||||
+8
-129
@@ -98,46 +98,7 @@ def retry_disbursement():
|
|||||||
logger.error(f"Failed to call retry disbursement {data}: {e}")
|
logger.error(f"Failed to call retry disbursement {data}: {e}")
|
||||||
|
|
||||||
|
|
||||||
@autocall_bp.route("/verify-disbursement", methods=["POST"])
|
|
||||||
def retry_verify_disbursement():
|
|
||||||
try:
|
|
||||||
data = request.get_json()
|
|
||||||
logger.info(f"Verify Disbursement Transaction ID Data Received for :::: {data}")
|
|
||||||
|
|
||||||
transactionId = data["transactionId"]
|
|
||||||
logger.info(f"Starting Transaction ID Data Received for :::: {transactionId}")
|
|
||||||
|
|
||||||
logger.info(f"Calling Disbursement Components for Retry Transaction ID Data Received for :::: {transactionId}")
|
|
||||||
loan = LoanService.get_loan_by_transaction_id(transactionId)
|
|
||||||
if not loan:
|
|
||||||
logger.info(f"No loan found without disbursement date")
|
|
||||||
return 0
|
|
||||||
logger.info(f"Calling DisburseLoan endpoint with data: {loan}")
|
|
||||||
loan_data = loan.to_dict()
|
|
||||||
|
|
||||||
data = {
|
|
||||||
"transactionId": loan_data.get('transactionId'),
|
|
||||||
"fbnTransactionId": loan_data.get('transactionId'),
|
|
||||||
"debtId": str(loan_data.get('debtId')),
|
|
||||||
"customerId": loan_data.get('customerId'),
|
|
||||||
"accountId": loan_data.get('accountId'),
|
|
||||||
"productId": str(loan_data.get('productId', "")),
|
|
||||||
"provideAmount": loan_data.get('currentLoanAmount'),
|
|
||||||
}
|
|
||||||
response = SimbrellaClient.verify_transaction(data)
|
|
||||||
return ResponseHelper.success(message="Retry Verify Disbursement Request Sent Successfully", status_code=200)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Failed to call retry disbursement {data}: {e}")
|
|
||||||
|
|
||||||
@autocall_bp.route("/start-repayment", methods=["POST"])
|
|
||||||
def start_repayment_office():
|
|
||||||
try:
|
|
||||||
data = request.get_json()
|
|
||||||
logger.info(f"Start Repay Transaction ID Data Received for :::: {data}")
|
|
||||||
loan_repayment_function(data, 'OFFICE')
|
|
||||||
return ResponseHelper.success(message="Retry Disbursement Request Sent Successfully", status_code=200)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Failed to call retry disbursement {data}: {e}")
|
|
||||||
|
|
||||||
|
|
||||||
@autocall_bp.route("/direct/loan", methods=["POST"])
|
@autocall_bp.route("/direct/loan", methods=["POST"])
|
||||||
@@ -164,18 +125,12 @@ def direct_loan():
|
|||||||
|
|
||||||
loan = LoanService.get_loan_by_transaction_id(transaction_id=transaction_id)
|
loan = LoanService.get_loan_by_transaction_id(transaction_id=transaction_id)
|
||||||
if not loan:
|
if not loan:
|
||||||
first_error = f"Loan with transaction id {transaction_id} does not exist"
|
logger.warning(f"Loan with transaction id {transaction_id} does not exist")
|
||||||
logger.warning(first_error)
|
return jsonify({
|
||||||
loan = LoanService.get_latest_loan_without_disburse_date()
|
"status": "error",
|
||||||
if not loan:
|
"message": f"Loan with transaction id {transaction_id} does not exist"
|
||||||
logger.info(f"No loan found without disbursement date")
|
}), 400
|
||||||
return jsonify({
|
|
||||||
"status": "error",
|
|
||||||
"first_error": first_error,
|
|
||||||
"message": f"No loan found without disbursement date"
|
|
||||||
}), 400
|
|
||||||
|
|
||||||
# Tried 2 method to get the loan record at this point
|
|
||||||
loan_data = loan.to_dict()
|
loan_data = loan.to_dict()
|
||||||
|
|
||||||
# Prevent double disbursement
|
# Prevent double disbursement
|
||||||
@@ -281,85 +236,6 @@ def direct_repayment():
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def loan_repayment_function(data, initiatedBy):
|
|
||||||
logger.info(f"Data Received Loan Repayment: {data} By {initiatedBy}")
|
|
||||||
|
|
||||||
REQUIRED_KEYS = ["transactionId"]
|
|
||||||
|
|
||||||
# Check for missing keys
|
|
||||||
missing_keys = [key for key in REQUIRED_KEYS if key not in data or data[key] is None]
|
|
||||||
if missing_keys:
|
|
||||||
logger.warning(f"Missing required keys: {missing_keys}")
|
|
||||||
return jsonify({
|
|
||||||
"status": "error",
|
|
||||||
"message": f"Missing required fields: {', '.join(missing_keys)}"
|
|
||||||
}), 400
|
|
||||||
|
|
||||||
# Check if the loan exists
|
|
||||||
logger.info(f"Checking if loan with transaction id {data['transactionId']} exists")
|
|
||||||
loan = LoanService.get_loan_by_transaction_id(transaction_id=data['transactionId'])
|
|
||||||
if not loan:
|
|
||||||
logger.info(f"Loan with transaction id {data['transactionId']} does not exist")
|
|
||||||
return jsonify({
|
|
||||||
"status": "error",
|
|
||||||
"message": f"Loan with transaction id {data['transactionId']} does not exist"
|
|
||||||
}), 400
|
|
||||||
|
|
||||||
loan_data = loan.to_dict()
|
|
||||||
|
|
||||||
# check if loan has been repaid
|
|
||||||
if loan_data.get("status") == LoanStatus.REPAID and loan_data.get("balance") <= 0:
|
|
||||||
logger.info(f"Loan with Id {loan_data.get('debtId')} has been repaid")
|
|
||||||
return jsonify({
|
|
||||||
"status": "error",
|
|
||||||
"message": f"loan with Id {loan_data.get('debtId')} has been repaid"
|
|
||||||
}), 400
|
|
||||||
|
|
||||||
repayment_data = {
|
|
||||||
"customerId": loan_data.get("customerId"),
|
|
||||||
"loanId": loan_data.get("debtId"),
|
|
||||||
"productId": loan_data.get("productId"),
|
|
||||||
"transactionId": loan_data.get("transactionId"),
|
|
||||||
"initiatedBy": initiatedBy,
|
|
||||||
"salaryAmount": 0,
|
|
||||||
"LoanStatus": loan_data.get("status"),
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info(f"Creating repayment with data: {repayment_data}")
|
|
||||||
|
|
||||||
try:
|
|
||||||
repayment = RepaymentService.create_repayment(repayment_data)
|
|
||||||
logger.info(f"Repayment created: {repayment}")
|
|
||||||
except Exception as e:
|
|
||||||
db.session.rollback()
|
|
||||||
logger.error(f"Repayment creation raised exception: {e}")
|
|
||||||
return jsonify({
|
|
||||||
"status": "error",
|
|
||||||
"message": "Failed to create repayment"
|
|
||||||
}), 500
|
|
||||||
|
|
||||||
if not repayment or (isinstance(repayment, dict) and "error" in repayment):
|
|
||||||
db.session.rollback()
|
|
||||||
logger.error(f"Repayment creation failed for loan ID {loan_data.get('debtId')}: {repayment}")
|
|
||||||
|
|
||||||
try:
|
|
||||||
if loan_data.get('status') == LoanStatus.ACTIVE:
|
|
||||||
LoanService.update_status(loan_id=loan_data.get('debtId'), status=LoanStatus.START_REPAY)
|
|
||||||
except Exception as e:
|
|
||||||
db.session.rollback()
|
|
||||||
logger.error(f"Failed to update loan status for loan ID {loan_data.get('debtId')}: {e}")
|
|
||||||
repayment_data_dict = repayment.to_dict()
|
|
||||||
|
|
||||||
data_to_process = {
|
|
||||||
"transactionId": repayment_data_dict['transactionId'],
|
|
||||||
"debtId": repayment_data_dict['loanId'],
|
|
||||||
"customerId": repayment_data_dict['customerId'],
|
|
||||||
"productId": repayment_data_dict['productId'],
|
|
||||||
"Id": repayment_data_dict['Id']
|
|
||||||
}
|
|
||||||
|
|
||||||
response = SimbrellaClient.collect_loan_user_initiated(data_to_process)
|
|
||||||
return response
|
|
||||||
|
|
||||||
|
|
||||||
@autocall_bp.route("/refresh-verify-collection", methods=["GET"])
|
@autocall_bp.route("/refresh-verify-collection", methods=["GET"])
|
||||||
@@ -572,6 +448,7 @@ def overdue_loans():
|
|||||||
logger.info(f"Found {len(overdue_loans)} overdue loans.")
|
logger.info(f"Found {len(overdue_loans)} overdue loans.")
|
||||||
|
|
||||||
if not overdue_loans:
|
if not overdue_loans:
|
||||||
|
logger.info("No overdue loans found.")
|
||||||
return ResponseHelper.success(message="No overdue loans found", status_code=200)
|
return ResponseHelper.success(message="No overdue loans found", status_code=200)
|
||||||
|
|
||||||
# Step 2: Process each loan
|
# Step 2: Process each loan
|
||||||
@@ -630,6 +507,7 @@ def process_overdue_loan(loan):
|
|||||||
|
|
||||||
# Update loan status
|
# Update loan status
|
||||||
try:
|
try:
|
||||||
|
logger.info(f"Updating loan status for loan ID {loan.loan_id}")
|
||||||
LoanService.update_status(loan_id=loan.loan_id, status=LoanStatus.START_REPAY)
|
LoanService.update_status(loan_id=loan.loan_id, status=LoanStatus.START_REPAY)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
@@ -647,6 +525,7 @@ def process_overdue_loan(loan):
|
|||||||
repayment_data["overdueLoanScheduleAmount"] = amount
|
repayment_data["overdueLoanScheduleAmount"] = amount
|
||||||
repayment_data["overdueLoanScheduleId"] = loan.id
|
repayment_data["overdueLoanScheduleId"] = loan.id
|
||||||
repayment_data["Id"] = repayment.id
|
repayment_data["Id"] = repayment.id
|
||||||
|
logger.info(f"Calling Simbrella for with repayment data: {repayment_data}")
|
||||||
simbrella_response = SimbrellaClient.collect_loan_user_due_payment(repayment_data)
|
simbrella_response = SimbrellaClient.collect_loan_user_due_payment(repayment_data)
|
||||||
|
|
||||||
if isinstance(simbrella_response, tuple):
|
if isinstance(simbrella_response, tuple):
|
||||||
|
|||||||
Reference in New Issue
Block a user