made loan data dynamic and populated result fields
This commit was merged in pull request #19.
This commit is contained in:
@@ -8,6 +8,7 @@ from app.utils.logger import logger
|
||||
from flask import jsonify, current_app
|
||||
from app.services.transactions import TransactionService
|
||||
from app.services.repayment import RepaymentService
|
||||
from app.extensions import db
|
||||
|
||||
|
||||
class SimbrellaClient:
|
||||
@@ -18,40 +19,33 @@ class SimbrellaClient:
|
||||
BANK_CALL_TRANSACTION_VERIFY = settings.BANK_CALL_TRANSACTION_VERIFY
|
||||
|
||||
@staticmethod
|
||||
def disburse_loan(data):
|
||||
def disburse_loan():
|
||||
api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/{SimbrellaClient.BANK_CALL_DISBURSE_LOAN_ENDPOINT}"
|
||||
logger.info(f"Calling DisburseLoan api_url==> : {api_url}")
|
||||
logger.info(f"Calling DisburseLoan endpoint with data: {data}")
|
||||
loan = LoanService.get_latest_loan_without_disburse_date()
|
||||
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()
|
||||
logger.info(f"Here is your loan data: {loan_data}")
|
||||
|
||||
# Check if the transaction exists
|
||||
logger.info(f"Checking if transaction exists")
|
||||
transaction = TransactionService.get_transaction_by_transaction_id(transaction_id=data['transactionId'])
|
||||
transaction = TransactionService.get_transaction_by_transaction_id(transaction_id=loan_data['transactionId'])
|
||||
logger.info(f"Loan Response From Database ** : {transaction}")
|
||||
|
||||
# If transaction is not found
|
||||
if not transaction:
|
||||
logger.info(f"Transaction id: {data['transactionId']}, was not found")
|
||||
logger.info(f"Transaction id: {loan_data['transactionId']}, was not found")
|
||||
return 0
|
||||
|
||||
# Fetch the loan based on the transaction_id
|
||||
logger.info(f"Fetching the loan with transaction ID: {data['transactionId']}")
|
||||
loan = LoanService.get_loan_by_transaction_id(transaction_id=data['transactionId'])
|
||||
logger.info(f"Response from database: {loan}")
|
||||
|
||||
# If loan is not found
|
||||
if not loan:
|
||||
logger.info(f"Could not find loan with transaction id: {data['transactionId']}")
|
||||
return 0
|
||||
|
||||
loan_data = loan.to_dict()
|
||||
logger.info(f"Here is your loan data: {loan_data}")
|
||||
|
||||
if loan_data['disburseDate'] is not None:
|
||||
logger.info(f"Please call verify loan : {data['transactionId']} loan send for processing at {loan_data['disburseDate']}")
|
||||
return 0
|
||||
logger.info(f"Here are your cal 111 : *********************************************************")
|
||||
# let us set disbursement date
|
||||
LoanService.set_disbursement_date(loan_data['debtId'], loan_data['customerId']) # toda this must return something
|
||||
logger.info(f"Please call verify loan : {loan_data['transactionId']} loan send for processing at {loan_data['disburseDate']}")
|
||||
else:
|
||||
logger.info(f"Here are your cal 111 : *********************************************************")
|
||||
# let us set disbursement date
|
||||
LoanService.set_disbursement_date(loan_data['debtId'], loan_data['customerId']) # toda this must return something
|
||||
logger.info(f"Here are your cal 000 : *********************************************************")
|
||||
logger.info(f"Here is your loan data after setting disbursement date: {loan_data}")
|
||||
|
||||
@@ -64,12 +58,11 @@ class SimbrellaClient:
|
||||
insurance_fee = loan_charges.get("INSURANCE")['amount']
|
||||
|
||||
disbursement_data = {
|
||||
"requestId": data.get('requestId'),
|
||||
"transactionId": data.get('transactionId'),
|
||||
"FbnTransactionId": data.get('FbnTransactionId'),
|
||||
"debtId": str(loan_data.get('debtId', "")),
|
||||
"customerId": data.get('customerId'),
|
||||
"accountId": data.get('accountId'),
|
||||
"transactionId": loan_data.get('transactionId'),
|
||||
"FbnTransactionId": loan_data.get('transactionId'),
|
||||
"debtId": str(loan_data.get('debtId', "")).strip().zfill(6),
|
||||
"customerId": loan_data.get('customerId'),
|
||||
"accountId": loan_data.get('accountId'),
|
||||
"productId": str(loan_data.get('productId', "")),
|
||||
"provideAmount": loan_data.get('currentLoanAmount'),
|
||||
"collectAmountInterest": interest_fee,
|
||||
@@ -84,7 +77,9 @@ class SimbrellaClient:
|
||||
logger.info(f"Here is your Disbursement Request data ****** : {disbursement_data}")
|
||||
response = requests.post(api_url, json=disbursement_data, timeout=10, headers=get_headers())
|
||||
logger.info(f"Disbursement response: {response.json()}")
|
||||
|
||||
result = response.json()
|
||||
LoanService.set_disbursement_result(loan_data['debtId'],result.get('responseCode', ''), result.get('responseMessage', ''))
|
||||
|
||||
|
||||
except Exception as e:
|
||||
logger.info(f"Failed to call Disbursement endpoint: {e}")
|
||||
|
||||
Reference in New Issue
Block a user