This commit is contained in:
CHIEFSOFT\ameye
2025-06-05 07:13:35 -04:00
parent 67363ff6e5
commit 50769f7faf
5 changed files with 137 additions and 65 deletions
+82 -44
View File
@@ -19,34 +19,41 @@ class SimbrellaClient:
BANK_CALL_TRANSACTION_VERIFY = settings.BANK_CALL_TRANSACTION_VERIFY
@staticmethod
def disburse_loan():
def disburse_loan(data):
api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/{SimbrellaClient.BANK_CALL_DISBURSE_LOAN_ENDPOINT}"
logger.info(f"Calling DisburseLoan api_url==> : {api_url}")
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}")
logger.info(f"Calling DisburseLoan endpoint with data: {data}")
# Check if the transaction exists
logger.info(f"Checking if transaction exists")
transaction = TransactionService.get_transaction_by_transaction_id(transaction_id=loan_data['transactionId'])
transaction = TransactionService.get_transaction_by_transaction_id(transaction_id=data['transactionId'])
logger.info(f"Loan Response From Database ** : {transaction}")
# If transaction is not found
if not transaction:
logger.info(f"Transaction id: {loan_data['transactionId']}, was not found")
logger.info(f"Transaction id: {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 : {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"Please call verify loan : {data['transactionId']} loan send for processing at {loan_data['disburseDate']}")
return 0
# let us set disbursement date
LoanService.set_disbursement_date(loan_data['debtId'],loan_data['customerId']) # toda this must return something
logger.info(f"Here is your loan data after setting disbursement date: {loan_data}")
loan_charges = preprocess_loan_charges_data([loan_charge.to_dict() for loan_charge in loan.loan_charges])
@@ -57,10 +64,12 @@ class SimbrellaClient:
interest_fee = loan_charges.get("INTEREST")['amount']
insurance_fee = loan_charges.get("INSURANCE")['amount']
debtId = str(loan_data.get('debtId', "")).strip().zfill(6)
disbursement_data = {
"transactionId": loan_data.get('transactionId'),
"FbnTransactionId": loan_data.get('transactionId'),
"debtId": str(loan_data.get('debtId', "")).strip().zfill(6),
"debtId": debtId,
"customerId": loan_data.get('customerId'),
"accountId": loan_data.get('accountId'),
"productId": str(loan_data.get('productId', "")),
@@ -79,14 +88,68 @@ class SimbrellaClient:
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}")
return 0
return 1
#Calling CollectLoan endpoint with data: {'transactionId': 'TRX1747960765928545', 'customerId': 'CID0000055362', 'productId': '101', 'debtId': '9590'}
@staticmethod
def verify_transaction(data):
api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/{SimbrellaClient.BANK_CALL_DISBURSE_LOAN_ENDPOINT}"
logger.info(f"Calling TransactionVerify api_url==> : {api_url}")
# Check if the transaction exists
logger.info(f"Checking if transaction exists")
transaction = TransactionService.get_transaction_by_transaction_id(transaction_id=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")
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 and loan_data['disburseVerify'] is None :
logger.info(f"Good to Verify transaction id: {data['transactionId']}")
else:
logger.info(
f"Please call disburse loan : {data['transactionId']} loan send for processing first")
return 0
verify_data = {
"channel": "USSD",
"customerId": loan_data.get('customerId'),
"accountId": loan_data.get('accountId'),
"transactionId": loan_data.get('transactionId'),
"transactionType": "LOAN",
"countryId": "NG",
"requestId": loan_data.get('transactionId')
}
try:
logger.info(f"Here is your TransactionVerify Request data ****** : {verify_data}")
response = requests.post(api_url, json=verify_data, timeout=10, headers=get_headers())
logger.info(f"TransactionVerify Response: {response.json()}")
return ResponseHelper.success(response, "Successful")
except Exception as e:
logger.info(f"Failed to call TransactionVerify endpoint: {e}")
return 0
@staticmethod
def collect_loan(data):
@@ -136,31 +199,6 @@ class SimbrellaClient:
return 1
@staticmethod
def verify_transaction():
api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/{SimbrellaClient.BANK_CALL_DISBURSE_LOAN_ENDPOINT}"
logger.info(f"Calling TransactionVerify api_url==> : {api_url}")
verify_data = {
"channel": "string",
"accountId": "string",
"customerId": "string",
"transactionId": "string",
"transactionType": "string",
"countryId": "string",
"requestId": "string"
}
try:
logger.info(f"Here is your TransactionVerify Request data ****** : {verify_data}")
response = requests.post(api_url, json=verify_data, timeout=10, headers=get_headers())
logger.info(f"TransactionVerify Response: {response.json()}")
return ResponseHelper.success(response, "Successful")
except Exception as e:
logger.info(f"Failed to call TransactionVerify endpoint: {e}")
return 0
@staticmethod
def refresh_disbursement(data):