added collect loan
This commit is contained in:
@@ -89,7 +89,7 @@ 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', ''))
|
||||
|
||||
return ResponseHelper.success(response.json(), "Successful")
|
||||
except Exception as e:
|
||||
logger.info(f"Failed to call Disbursement endpoint: {e}")
|
||||
return 0
|
||||
@@ -98,7 +98,7 @@ class SimbrellaClient:
|
||||
|
||||
@staticmethod
|
||||
def verify_transaction(data):
|
||||
api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/{SimbrellaClient.BANK_CALL_TRANSACTION_VERIFY}"
|
||||
api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}{SimbrellaClient.BANK_CALL_TRANSACTION_VERIFY}"
|
||||
sms_url = f"{SimbrellaClient.BANK_CALL_SMS_BASE_URL}/singleSMS"
|
||||
logger.info(f"Calling TransactionVerify api_url==> : {api_url}")
|
||||
|
||||
@@ -162,7 +162,7 @@ class SimbrellaClient:
|
||||
logger.info(f"SMS Response JSON: {result}")
|
||||
if result.get('isSuccess'):
|
||||
logger.info(f"sms sent successfully")
|
||||
return ResponseHelper.success(response, "Successful")
|
||||
return ResponseHelper.success(response.json(), "Successful")
|
||||
logger.info(f"sms failed!")
|
||||
return 1
|
||||
except requests.RequestException as e:
|
||||
@@ -175,51 +175,66 @@ class SimbrellaClient:
|
||||
|
||||
@staticmethod
|
||||
def collect_loan(data):
|
||||
api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/{SimbrellaClient.BANK_CALL_COLLECT_LOAN_ENDPOINT}"
|
||||
logger.info(f"Calling CollectLoan api_url==> : {api_url}")
|
||||
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 endpoint with data: {data}")
|
||||
|
||||
# Check if the repayment exists
|
||||
logger.info(f"Checking if repayment exists")
|
||||
repayment = RepaymentService.get_repayment_by_transaction_id(transaction_id=data['transactionId'])
|
||||
logger.info(f"Repayment Response From Database ** : {repayment}")
|
||||
loan = LoanService.get_loan_by_debt_id(debt_id=repayment.loan_id)
|
||||
|
||||
# If repayment is not found
|
||||
if not repayment:
|
||||
logger.info(f"Repayment id: {data['transactionId']}, was not found")
|
||||
return 0
|
||||
logger.info(f"Repayment with transactionId: {data['transactionId']}, was not found")
|
||||
return ResponseHelper.error("Repayment not found")
|
||||
|
||||
repayAmount = loan.repayment_amount
|
||||
repayment_data = repayment.to_dict()
|
||||
loan = LoanService.get_loan_by_transaction_id(transaction_id=repayment_data['transactionId'])
|
||||
|
||||
collectAmount = repayAmount
|
||||
# If loan is not found
|
||||
if not loan:
|
||||
logger.info(f"Loan with debtId: {repayment_data.loan_id}, was not found")
|
||||
return ResponseHelper.error("Loan not found")
|
||||
|
||||
loan_data = loan.to_dict()
|
||||
|
||||
if repayment_data['repayDate'] is not None:
|
||||
logger.info(
|
||||
f"Please call verify collection : {data['transactionId']} repayment send for processing at {repayment_data['repayDate']}")
|
||||
return ResponseHelper.error("Repayment already processed")
|
||||
|
||||
# let us set repay date
|
||||
RepaymentService.set_repay_date(repayment_data['Id'], repayment_data['customerId'])
|
||||
repayment = RepaymentService.get_repayment_by_transaction_id(transaction_id=data['transactionId'])
|
||||
repayment_data = repayment.to_dict()
|
||||
logger.info(f"Here is your repayment data after setting repay date: {repayment_data}")
|
||||
debtId = str(loan_data.get('debtId', "")).strip().zfill(6)
|
||||
collect_loan_data = {
|
||||
"transactionId": repayment.transaction_id,
|
||||
"fbnTransactionId": loan.reference,
|
||||
"debtId": repayment.loan_id,
|
||||
"customerId": repayment.customer_id,
|
||||
"accountId": loan.account_id,
|
||||
"productId": repayment.product_id,
|
||||
"collectAmount": collectAmount,
|
||||
"penalCharge": 0,
|
||||
"channel": "USSD",
|
||||
"collectionMethod": 1,
|
||||
"lienAmount": 0,
|
||||
"countryId": "01",
|
||||
"comment": "Testing CollectionLoanRequest"
|
||||
}
|
||||
"transactionId": repayment_data['transactionId'],
|
||||
"fbnTransactionId": loan_data['transactionId'],
|
||||
"debtId": debtId,
|
||||
"customerId": repayment_data['customerId'],
|
||||
"accountId": loan_data['accountId'],
|
||||
"productId": repayment_data['productId'],
|
||||
"collectAmount": loan_data['repaymentAmount'],
|
||||
"penalCharge": 5,
|
||||
"channel": "USSD",
|
||||
"collectionMethod": "1",
|
||||
"lienAmount": 0,
|
||||
"countryId": "01",
|
||||
"comment": "COLLECT LOAN"
|
||||
}
|
||||
|
||||
try:
|
||||
logger.info(f"Here is your CollectLoan Request data ***** : {collect_loan_data}")
|
||||
response = requests.post(api_url, json=collect_loan_data, headers=get_headers())
|
||||
|
||||
logger.info(f"CollectLoan response: {response.json()}")
|
||||
|
||||
RepaymentService.set_repay_result(repayment_data['Id'], response.json().get('responseCode', ''), response.json().get('responseMessage', ''))
|
||||
return ResponseHelper.success(response.json(), "Successful")
|
||||
except Exception as e:
|
||||
logger.info(f"Failed to call CollectLoan endpoint: {e}")
|
||||
return 0
|
||||
|
||||
return 1
|
||||
return ResponseHelper.error("Failed to call CollectLoan endpoint")
|
||||
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user