retry loans

This commit is contained in:
CHIEFSOFT\ameye
2025-11-02 15:34:55 -05:00
parent 8ffac10cd3
commit c88e85eda1
4 changed files with 122 additions and 10 deletions
+63 -9
View File
@@ -1,6 +1,7 @@
import requests
from app.config import settings
from app.helpers.response_helper import ResponseHelper
#from app.routes.autocall import verify_transaction
from app.services.loan import LoanService
from app.services.loan_repayment_schedule import LoanRepaymentScheduleService
from app.utils.auth import get_headers
@@ -63,8 +64,15 @@ class SimbrellaClient:
logger.info(f"Here is your loan data: {loan_data}")
if loan_data['disburseDate'] is not None:
logger.info("*************************SEEM LIKE A RETRY CALL -WE WILL VERIFY Result to Continue ")
logger.info(
f"Please call verify loan : {data['transactionId']} loan send for processing at {loan_data['disburseDate']}")
f"Please call verify loan : {data['transactionId']} loan sent for processing at {loan_data['disburseDate']}")
# return 0 -- we need the disburseResult = '00' to be sure all is good
if loan_data['disburseDate'] is not None and loan_data['disburseResult'] == '00':
logger.info("*************************Duplicate call to completed loan ")
logger.info(
f"Duplicate call detected for loan : {data['transactionId']} loan sent for processing at {loan_data['disburseDate']}")
return 0
# let us set disbursement date
@@ -83,7 +91,7 @@ class SimbrellaClient:
disbursement_data = {
"transactionId": loan_data.get('transactionId'),
"FbnTransactionId": loan_data.get('transactionId'),
"fbnTransactionId": loan_data.get('transactionId'),
"debtId": debtId,
"customerId": loan_data.get('customerId'),
"accountId": loan_data.get('accountId'),
@@ -96,24 +104,60 @@ class SimbrellaClient:
"countryId": "01",
"comment": "Loan Disbursement",
}
# '''
# { Veryfing with the bank
# "transactionId": "string",
# "fbnTransactionId": "string",
# "debtId": "string",
# "customerId": "string",
# "accountId": "string",
# "productId": "string",
# "provideAmount": 0,
# "collectAmountInterest": 0,
# "collectAmountMgtFee": 0,
# "collectAmountInsurance": 0,
# "collectAmountVAT": 0,
# "countryId": "string",
# "comment": "string"
# }
# '''
try:
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"Call to bank end point returned with Here is your Disbursement Request data ****** : {disbursement_data}")
if response.status_code == 404:
logger.error("Received 404 from external service")
logger.error("")
LoanService.set_disbursement_loan_description(loan_data['debtId'],"Disbursement Service url not found (404)" )
return ResponseHelper.error("Disbursement Service url not found (404)", status_code=404)
logger.info(f"Disbursement response: {response.json()}")
result = response.json()
LoanService.set_disbursement_result(loan_data['debtId'],result.get('responseCode', ''), result.get('responseMessage', ''))
return ResponseHelper.success(response.json(), "Successful")
if response.status_code == 200:
result = response.json()
LoanService.set_disbursement_result(loan_data['debtId'],result.get('responseCode', ''), result.get('responseMessage', ''))
reload_loan = LoanService.get_loan_by_transaction_id(transaction_id=data['transactionId'])
reload_loan_data = reload_loan.to_dict()
verify_disbursement_transaction(reload_loan_data)
return ResponseHelper.success(response.json(), "Successful")
else:
logger.error("")
errorMessage = "Unable to complete Disbursement Service with HTTP status code: " + str(response.status_code)
LoanService.set_disbursement_loan_description(loan_data['debtId'],errorMessage )
return ResponseHelper.error(errorMessage, status_code=response.status_code)
except Exception as e:
logger.info(f"Failed to call Disbursement endpoint: {e}")
return 0
return 1
@staticmethod
def verify_disbursement_transaction(loan_data):
if loan_data['disburseResult'] and loan_data['disburseResult'] == '00':
verify_transaction(loan_data)
@staticmethod
def verify_transaction(data):
api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}{SimbrellaClient.BANK_CALL_TRANSACTION_VERIFY}"
@@ -164,7 +208,17 @@ class SimbrellaClient:
"countryId": "NG",
"requestId": loan_data.get('transactionId')
}
# '''
# { Verify with bank
# "accountId": "string",
# "customerId": "string",
# "transactionId": "string",
# "fbnTransactionId": "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())