added verify date

This commit was merged in pull request #20.
This commit is contained in:
Chinenye Nmoh
2025-06-05 20:03:18 +01:00
parent 50769f7faf
commit b8a40bb638
4 changed files with 104 additions and 13 deletions
+28 -6
View File
@@ -14,6 +14,7 @@ from app.extensions import db
class SimbrellaClient:
BANK_CALL_BASE_URL = settings.BANK_CALL_BASE_URL
BANK_CALL_SMS_BASE_URL = settings.BANK_CALL_SMS_BASE_URL
BANK_CALL_DISBURSE_LOAN_ENDPOINT = settings.BANK_CALL_DISBURSE_LOAN_ENDPOINT
BANK_CALL_COLLECT_LOAN_ENDPOINT = settings.BANK_CALL_COLLECT_LOAN_ENDPOINT
BANK_CALL_TRANSACTION_VERIFY = settings.BANK_CALL_TRANSACTION_VERIFY
@@ -97,7 +98,8 @@ class SimbrellaClient:
@staticmethod
def verify_transaction(data):
api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/{SimbrellaClient.BANK_CALL_DISBURSE_LOAN_ENDPOINT}"
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}")
# Check if the transaction exists
@@ -124,6 +126,9 @@ class SimbrellaClient:
logger.info(f"Here is your loan data: {loan_data}")
if loan_data['disburseDate'] is not None and loan_data['disburseVerify'] is None :
LoanService.set_disburse_verify_date(loan_data['debtId'],loan_data['customerId'])
loan_data = loan.to_dict()
logger.info(f"Here is your loan data after setting verify date: {loan_data}")
logger.info(f"Good to Verify transaction id: {data['transactionId']}")
else:
logger.info(
@@ -132,11 +137,10 @@ class SimbrellaClient:
verify_data = {
"channel": "USSD",
"customerId": loan_data.get('customerId'),
"accountId": loan_data.get('accountId'),
"transactionId": loan_data.get('transactionId'),
"transactionType": "LOAN",
"transactionType": "provide",
"countryId": "NG",
"requestId": loan_data.get('transactionId')
}
@@ -144,9 +148,27 @@ class SimbrellaClient:
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")
result = response.json()
LoanService.set_disburse_verify_result(loan_data['debtId'],result.get('responseCode', ''), result.get('responseMessage', ''))
sms_data = {
"dest": "2347038224367",
"text": "test",
"unicode": True
}
try:
sms_response = requests.post(sms_url, json=sms_data, timeout=10, headers=get_headers())
sms_response.raise_for_status() # Raise an exception for 4xx or 5xx status codes
result = sms_response.json()
logger.info(f"SMS Response JSON: {result}")
if result.get('isSuccess'):
logger.info(f"sms sent successfully")
return ResponseHelper.success(response, "Successful")
logger.info(f"sms failed!")
return 1
except requests.RequestException as e:
# Handle the exception
logger.error(f"Failed to send SMS: {e}")
return 0
except Exception as e:
logger.info(f"Failed to call TransactionVerify endpoint: {e}")
return 0