import requests from app.config import settings from app.utils.auth import get_headers from app.utils.logger import logger from flask import jsonify class SimbrellaClient: BANK_CALL_BASE_URL = settings.BANK_CALL_BASE_URL @staticmethod def disbursement(data): api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/Disbursement" logger.info(f"BANK_CALL_BASE_URL = {SimbrellaClient.BANK_CALL_BASE_URL}") logger.info(f"Calling Disbursement endpoint with data: {data}") disbursement_data ={ "requestId": data['requestId'], "transactionId": data['transactionId'], "debtId": "273194670", "customerId": data['customerId'], "accountId": data['accountId'], "productId": "101", "provideAmount": 100000, "collectAmountInterest": 5000, "collectAmountMgtFee": 1000, "collectAmountInsurance": 1000, "collectAmountVAT": 75, "countryId": "01", "comment": "Loan Disbursement", } 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"Disbursement response: {response.json()}") except Exception as e: logger.info(f"Failed to call Disbursement endpoint: {e}") #raise return 0 # return jsonify(response.json()), response.status_code return 1 @staticmethod def collect_loan(data): api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/CollectLoan" logger.info(f"BANK_CALL_BASE_URL = {SimbrellaClient.BANK_CALL_BASE_URL}") logger.info(f"Calling CollectLoan endpoint with data: {data}") collect_loan_data = { "transactionId": "T002", "fbnTransactionId": "FBN20231123", "debtId": data['debtId'], "customerId": data['customerId'], "accountId": "2017821799", "productId": data['productId'], "collectAmount": 80000, "penalCharge": 0, "collectionMethod": 1, "lienAmount": 80000, "countryId": "01", "comment": "Testing CollectionLoanRequest" } 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()}") except Exception as e: logger.info(f"Failed to call CollectLoan endpoint: {e}") return 0 return 1 @staticmethod def verify_transaction(): # api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/TransactionVerify" # logger.info(f"BANK_CALL_BASE_URL = {SimbrellaClient.BANK_CALL_BASE_URL}") # logger.info(f"Calling TransactionVerify endpoint with data: {data}") try: # logger.info(f"Here is your TransactionVerify Request data ***** : {data}") # response = requests.post(api_url, json=data, headers=get_headers()) # logger.info(f"TransactionVerify response: {response.json()}") return { "status": "00", "message": "Transaction verified" } except Exception as e: logger.info(f"Failed to call TransactionVerify endpoint: {e}") raise @staticmethod def refresh_disbursement(data): # api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/Disbursement" # logger.info(f"BANK_CALL_BASE_URL = {SimbrellaClient.BANK_CALL_BASE_URL}") # logger.info(f"Calling Disbursement endpoint with data: {data}") try: logger.info(f"Here is your Disbursement Request data ***** : {data}") # response = requests.post(api_url, json=data, headers=get_headers()) # logger.info(f"Disbursement response: {response.json()}") # return response.json() return data except Exception as e: logger.info(f"Failed to call Disbursement endpoint: {e}") raise @staticmethod def payment_callback(data): # api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/Payment" # logger.info(f"BANK_CALL_BASE_URL = {SimbrellaClient.BANK_CALL_BASE_URL}") # logger.info(f"Calling Payment Callback endpoint with data: {data}") try: logger.info(f"Here is your Payment Callback Request data ***** : {data}") # response = requests.post(api_url, json=data, headers=get_headers()) # logger.info(f"Payment Callback response: {response.json()}") # return response.json() return data except Exception as e: logger.info(f"Failed to call Payment Callback endpoint: {e}") raise