added repayment data
This commit was merged in pull request #23.
This commit is contained in:
@@ -106,6 +106,7 @@ class SimbrellaClient:
|
||||
# Check if the transaction exists
|
||||
logger.info(f"Checking if transaction exists")
|
||||
transaction = TransactionService.get_transaction_by_transaction_id(transaction_id=data['transactionId'])
|
||||
transaction_data = transaction.to_dict()
|
||||
logger.info(f"Loan Response From Database ** : {transaction}")
|
||||
|
||||
# If transaction is not found
|
||||
@@ -142,6 +143,7 @@ class SimbrellaClient:
|
||||
"accountId": loan_data.get('accountId'),
|
||||
"transactionId": loan_data.get('transactionId'),
|
||||
"transactionType": "provide",
|
||||
"fbnTransactionId": loan_data.get('transactionId'),
|
||||
"countryId": "NG",
|
||||
"requestId": loan_data.get('transactionId')
|
||||
}
|
||||
@@ -150,10 +152,11 @@ class SimbrellaClient:
|
||||
logger.info(f"Here is your TransactionVerify Request data ****** : {verify_data}")
|
||||
response = requests.post(api_url, json=verify_data, timeout=10, headers=get_headers())
|
||||
result = response.json()
|
||||
logger.info(f"this is verify result, {result}")
|
||||
LoanService.set_disburse_verify_result(loan_data['debtId'],result.get('responseCode', ''), result.get('responseMessage', ''))
|
||||
sms_data = {
|
||||
"dest": "2347038224367",
|
||||
"text": "test",
|
||||
"dest": transaction_data.get('phone_number') or settings.TEST_NO,
|
||||
"text": f"Transaction {loan_data.get('transactionId')} verified successfully",
|
||||
"unicode": True
|
||||
}
|
||||
try:
|
||||
@@ -188,13 +191,14 @@ class SimbrellaClient:
|
||||
if not repayment:
|
||||
logger.info(f"Repayment with transactionId: {data['transactionId']}, was not found")
|
||||
return ResponseHelper.error("Repayment not found")
|
||||
|
||||
logger.info(f"Repayment Response From Database ** : {repayment.to_dict()}")
|
||||
repayment_data = repayment.to_dict()
|
||||
loan = LoanService.get_loan_by_transaction_id(transaction_id=repayment_data['transactionId'])
|
||||
loan = LoanService.get_loan_by_loan_id(loan_id=int(repayment_data['loanId']))
|
||||
|
||||
|
||||
# If loan is not found
|
||||
if not loan:
|
||||
logger.info(f"Loan with debtId: {repayment_data.loan_id}, was not found")
|
||||
if loan is None:
|
||||
logger.info(f"Loan with debtId: {repayment_data['loanId']}, was not found")
|
||||
return ResponseHelper.error("Loan not found")
|
||||
|
||||
loan_data = loan.to_dict()
|
||||
@@ -233,7 +237,19 @@ class SimbrellaClient:
|
||||
logger.info(f"CollectLoan response: {response.json()}")
|
||||
RepaymentService.set_repay_result(repayment_data['Id'], response.json().get('responseCode', ''), response.json().get('responseMessage', ''))
|
||||
result = response.json()
|
||||
new_repayment_data = RepaymentsData.add_repayment_data(result)
|
||||
logger.info(f"this is the result {result}")
|
||||
data_to_add = {
|
||||
"transactionId": result.get('transactionId') or collect_loan_data.get('transactionId'),
|
||||
"fbnTransactionId": result.get('fbnTransactionId') or collect_loan_data.get('fbnTransactionId'),
|
||||
"accountId": result.get('accountId') or collect_loan_data.get('accountId'),
|
||||
"customerId": result.get('customerId') or collect_loan_data.get('customerId'),
|
||||
"amountCollected": result.get('amountCollected'),
|
||||
"repaymentAmount": collect_loan_data.get('collectAmount'),
|
||||
"responseCode": result.get('responseCode'),
|
||||
"responseDescr": result.get('responseMessage'),
|
||||
}
|
||||
|
||||
new_repayment_data = RepaymentsData.add_repayment_data(data_to_add)
|
||||
logger.info(f"Repayment data added successfully: {new_repayment_data.to_dict()}")
|
||||
if not new_repayment_data:
|
||||
logger.info(f"Failed to add repayment data")
|
||||
|
||||
Reference in New Issue
Block a user