ref
This commit is contained in:
+3
-3
@@ -37,8 +37,8 @@ class Config:
|
|||||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||||
|
|
||||||
BANK_CALL_BASE_URL = os.getenv("BANK_CALL_BASE_URL", "https://bank-emulator.dev.simbrellang.net")
|
BANK_CALL_BASE_URL = os.getenv("BANK_CALL_BASE_URL", "https://bank-emulator.dev.simbrellang.net")
|
||||||
BANK_CALL_DISBURSE_LOAN_ENDPOINT = os.getenv("BANK_CALL_DISBURSE_LOAN_ENDPOINT","DisburseLoan")
|
BANK_CALL_DISBURSE_LOAN_ENDPOINT = os.getenv("BANK_CALL_DISBURSE_LOAN_ENDPOINT","api/DisburseLoan")
|
||||||
BANK_CALL_COLLECT_LOAN_ENDPOINT = os.getenv("BANK_CALL_COLLECT_LOAN_ENDPOINT","CollectLoan")
|
BANK_CALL_COLLECT_LOAN_ENDPOINT = os.getenv("BANK_CALL_COLLECT_LOAN_ENDPOINT","api/CollectLoan")
|
||||||
BANK_CALL_TRANSACTION_VERIFY = os.getenv("BANK_CALL_TRANSACTION_VERIFY", "TransactionVerify")
|
BANK_CALL_TRANSACTION_VERIFY = os.getenv("BANK_CALL_TRANSACTION_VERIFY", "api/TransactionVerify")
|
||||||
|
|
||||||
settings = Config()
|
settings = Config()
|
||||||
|
|||||||
@@ -19,34 +19,41 @@ class SimbrellaClient:
|
|||||||
BANK_CALL_TRANSACTION_VERIFY = settings.BANK_CALL_TRANSACTION_VERIFY
|
BANK_CALL_TRANSACTION_VERIFY = settings.BANK_CALL_TRANSACTION_VERIFY
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def disburse_loan():
|
def disburse_loan(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_DISBURSE_LOAN_ENDPOINT}"
|
||||||
logger.info(f"Calling DisburseLoan api_url==> : {api_url}")
|
logger.info(f"Calling DisburseLoan api_url==> : {api_url}")
|
||||||
loan = LoanService.get_latest_loan_without_disburse_date()
|
logger.info(f"Calling DisburseLoan endpoint with data: {data}")
|
||||||
if not loan:
|
|
||||||
logger.info(f"No loan found without disbursement date")
|
|
||||||
return 0
|
|
||||||
logger.info(f"Calling DisburseLoan endpoint with data: {loan}")
|
|
||||||
loan_data = loan.to_dict()
|
|
||||||
logger.info(f"Here is your loan data: {loan_data}")
|
|
||||||
|
|
||||||
# Check if the transaction exists
|
# Check if the transaction exists
|
||||||
logger.info(f"Checking if transaction exists")
|
logger.info(f"Checking if transaction exists")
|
||||||
transaction = TransactionService.get_transaction_by_transaction_id(transaction_id=loan_data['transactionId'])
|
transaction = TransactionService.get_transaction_by_transaction_id(transaction_id=data['transactionId'])
|
||||||
logger.info(f"Loan Response From Database ** : {transaction}")
|
logger.info(f"Loan Response From Database ** : {transaction}")
|
||||||
|
|
||||||
# If transaction is not found
|
# If transaction is not found
|
||||||
if not transaction:
|
if not transaction:
|
||||||
logger.info(f"Transaction id: {loan_data['transactionId']}, was not found")
|
logger.info(f"Transaction id: {data['transactionId']}, was not found")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
# Fetch the loan based on the transaction_id
|
||||||
|
logger.info(f"Fetching the loan with transaction ID: {data['transactionId']}")
|
||||||
|
loan = LoanService.get_loan_by_transaction_id(transaction_id=data['transactionId'])
|
||||||
|
logger.info(f"Response from database: {loan}")
|
||||||
|
|
||||||
|
# If loan is not found
|
||||||
|
if not loan:
|
||||||
|
logger.info(f"Could not find loan with transaction id: {data['transactionId']}")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
loan_data = loan.to_dict()
|
||||||
|
logger.info(f"Here is your loan data: {loan_data}")
|
||||||
|
|
||||||
if loan_data['disburseDate'] is not None:
|
if loan_data['disburseDate'] is not None:
|
||||||
logger.info(f"Please call verify loan : {loan_data['transactionId']} loan send for processing at {loan_data['disburseDate']}")
|
logger.info(
|
||||||
else:
|
f"Please call verify loan : {data['transactionId']} loan send for processing at {loan_data['disburseDate']}")
|
||||||
logger.info(f"Here are your cal 111 : *********************************************************")
|
return 0
|
||||||
# let us set disbursement date
|
|
||||||
LoanService.set_disbursement_date(loan_data['debtId'], loan_data['customerId']) # toda this must return something
|
# let us set disbursement date
|
||||||
logger.info(f"Here are your cal 000 : *********************************************************")
|
LoanService.set_disbursement_date(loan_data['debtId'],loan_data['customerId']) # toda this must return something
|
||||||
logger.info(f"Here is your loan data after setting disbursement date: {loan_data}")
|
logger.info(f"Here is your loan data after setting disbursement date: {loan_data}")
|
||||||
|
|
||||||
loan_charges = preprocess_loan_charges_data([loan_charge.to_dict() for loan_charge in loan.loan_charges])
|
loan_charges = preprocess_loan_charges_data([loan_charge.to_dict() for loan_charge in loan.loan_charges])
|
||||||
@@ -57,10 +64,12 @@ class SimbrellaClient:
|
|||||||
interest_fee = loan_charges.get("INTEREST")['amount']
|
interest_fee = loan_charges.get("INTEREST")['amount']
|
||||||
insurance_fee = loan_charges.get("INSURANCE")['amount']
|
insurance_fee = loan_charges.get("INSURANCE")['amount']
|
||||||
|
|
||||||
|
debtId = str(loan_data.get('debtId', "")).strip().zfill(6)
|
||||||
|
|
||||||
disbursement_data = {
|
disbursement_data = {
|
||||||
"transactionId": loan_data.get('transactionId'),
|
"transactionId": loan_data.get('transactionId'),
|
||||||
"FbnTransactionId": loan_data.get('transactionId'),
|
"FbnTransactionId": loan_data.get('transactionId'),
|
||||||
"debtId": str(loan_data.get('debtId', "")).strip().zfill(6),
|
"debtId": debtId,
|
||||||
"customerId": loan_data.get('customerId'),
|
"customerId": loan_data.get('customerId'),
|
||||||
"accountId": loan_data.get('accountId'),
|
"accountId": loan_data.get('accountId'),
|
||||||
"productId": str(loan_data.get('productId', "")),
|
"productId": str(loan_data.get('productId', "")),
|
||||||
@@ -79,14 +88,68 @@ class SimbrellaClient:
|
|||||||
logger.info(f"Disbursement response: {response.json()}")
|
logger.info(f"Disbursement response: {response.json()}")
|
||||||
result = response.json()
|
result = response.json()
|
||||||
LoanService.set_disbursement_result(loan_data['debtId'],result.get('responseCode', ''), result.get('responseMessage', ''))
|
LoanService.set_disbursement_result(loan_data['debtId'],result.get('responseCode', ''), result.get('responseMessage', ''))
|
||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.info(f"Failed to call Disbursement endpoint: {e}")
|
logger.info(f"Failed to call Disbursement endpoint: {e}")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
#Calling CollectLoan endpoint with data: {'transactionId': 'TRX1747960765928545', 'customerId': 'CID0000055362', 'productId': '101', 'debtId': '9590'}
|
|
||||||
|
@staticmethod
|
||||||
|
def verify_transaction(data):
|
||||||
|
api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/{SimbrellaClient.BANK_CALL_DISBURSE_LOAN_ENDPOINT}"
|
||||||
|
logger.info(f"Calling TransactionVerify api_url==> : {api_url}")
|
||||||
|
|
||||||
|
# Check if the transaction exists
|
||||||
|
logger.info(f"Checking if transaction exists")
|
||||||
|
transaction = TransactionService.get_transaction_by_transaction_id(transaction_id=data['transactionId'])
|
||||||
|
logger.info(f"Loan Response From Database ** : {transaction}")
|
||||||
|
|
||||||
|
# If transaction is not found
|
||||||
|
if not transaction:
|
||||||
|
logger.info(f"Transaction id: {data['transactionId']}, was not found")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
# Fetch the loan based on the transaction_id
|
||||||
|
logger.info(f"Fetching the loan with transaction ID: {data['transactionId']}")
|
||||||
|
loan = LoanService.get_loan_by_transaction_id(transaction_id=data['transactionId'])
|
||||||
|
logger.info(f"Response from database: {loan}")
|
||||||
|
|
||||||
|
# If loan is not found
|
||||||
|
if not loan:
|
||||||
|
logger.info(f"Could not find loan with transaction id: {data['transactionId']}")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
loan_data = loan.to_dict()
|
||||||
|
logger.info(f"Here is your loan data: {loan_data}")
|
||||||
|
|
||||||
|
if loan_data['disburseDate'] is not None and loan_data['disburseVerify'] is None :
|
||||||
|
logger.info(f"Good to Verify transaction id: {data['transactionId']}")
|
||||||
|
else:
|
||||||
|
logger.info(
|
||||||
|
f"Please call disburse loan : {data['transactionId']} loan send for processing first")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
verify_data = {
|
||||||
|
"channel": "USSD",
|
||||||
|
"customerId": loan_data.get('customerId'),
|
||||||
|
"accountId": loan_data.get('accountId'),
|
||||||
|
"transactionId": loan_data.get('transactionId'),
|
||||||
|
"transactionType": "LOAN",
|
||||||
|
"countryId": "NG",
|
||||||
|
"requestId": loan_data.get('transactionId')
|
||||||
|
}
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.info(f"Failed to call TransactionVerify endpoint: {e}")
|
||||||
|
return 0
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def collect_loan(data):
|
def collect_loan(data):
|
||||||
@@ -136,31 +199,6 @@ class SimbrellaClient:
|
|||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def verify_transaction():
|
|
||||||
api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/{SimbrellaClient.BANK_CALL_DISBURSE_LOAN_ENDPOINT}"
|
|
||||||
logger.info(f"Calling TransactionVerify api_url==> : {api_url}")
|
|
||||||
|
|
||||||
verify_data = {
|
|
||||||
"channel": "string",
|
|
||||||
"accountId": "string",
|
|
||||||
"customerId": "string",
|
|
||||||
"transactionId": "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())
|
|
||||||
logger.info(f"TransactionVerify Response: {response.json()}")
|
|
||||||
return ResponseHelper.success(response, "Successful")
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.info(f"Failed to call TransactionVerify endpoint: {e}")
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def refresh_disbursement(data):
|
def refresh_disbursement(data):
|
||||||
|
|||||||
@@ -144,6 +144,15 @@ class Loan(db.Model):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_latest_loan_without_disburse_date(cls):
|
def get_latest_loan_without_disburse_date(cls):
|
||||||
|
"""
|
||||||
|
Get the latest loan without a disbursement date.
|
||||||
|
"""
|
||||||
|
return cls.query.filter(
|
||||||
|
cls.disburse_date.is_(None)
|
||||||
|
).order_by(cls.created_at.desc()).first()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_latest_loan_with_disburse_date(cls):
|
||||||
"""
|
"""
|
||||||
Get the latest loan without a disbursement date.
|
Get the latest loan without a disbursement date.
|
||||||
"""
|
"""
|
||||||
|
|||||||
+35
-17
@@ -5,6 +5,7 @@ from app.helpers.response_helper import ResponseHelper
|
|||||||
from app.utils.auth import get_headers
|
from app.utils.auth import get_headers
|
||||||
from app.utils.logger import logger
|
from app.utils.logger import logger
|
||||||
from app.integrations.simbrella import SimbrellaClient
|
from app.integrations.simbrella import SimbrellaClient
|
||||||
|
from app.services.loan import LoanService
|
||||||
|
|
||||||
autocall_bp = Blueprint("autocall", __name__)
|
autocall_bp = Blueprint("autocall", __name__)
|
||||||
|
|
||||||
@@ -12,29 +13,46 @@ autocall_bp = Blueprint("autocall", __name__)
|
|||||||
def verify_transaction():
|
def verify_transaction():
|
||||||
logger.info(f"Calling VerifyTransaction Components")
|
logger.info(f"Calling VerifyTransaction Components")
|
||||||
|
|
||||||
response = SimbrellaClient.verify_transaction()
|
loan = LoanService.get_latest_loan_with_disburse_date()
|
||||||
|
if not loan:
|
||||||
|
logger.info(f"No loan found without disbursement date")
|
||||||
|
return 0
|
||||||
|
logger.info(f"Calling VerifyTransaction endpoint with data: {loan}")
|
||||||
|
loan_data = loan.to_dict()
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"transactionId": loan_data.get('transactionId'),
|
||||||
|
"FbnTransactionId": loan_data.get('transactionId'),
|
||||||
|
"debtId": str(loan_data.get('debtId')),
|
||||||
|
"customerId": loan_data.get('customerId'),
|
||||||
|
"accountId": loan_data.get('accountId'),
|
||||||
|
"productId": str(loan_data.get('productId', "")),
|
||||||
|
"provideAmount": loan_data.get('currentLoanAmount'),
|
||||||
|
}
|
||||||
|
response = SimbrellaClient.verify_transaction(data)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@autocall_bp.route("/refresh-disbursement", methods=["GET"])
|
@autocall_bp.route("/refresh-disbursement", methods=["GET"])
|
||||||
def disbursement():
|
def disbursement():
|
||||||
# data = request.json()
|
# data = request.json()
|
||||||
logger.info(f"Calling Disbursement Components")
|
logger.info(f"Calling Disbursement Components")
|
||||||
""" data = {
|
loan = LoanService.get_latest_loan_without_disburse_date()
|
||||||
"transactionId": "TRX1749033507722975",
|
if not loan:
|
||||||
"FbnTransactionId":"TRX1748643654575327",
|
logger.info(f"No loan found without disbursement date")
|
||||||
"debtId": "94696900",
|
return 0
|
||||||
"customerId": "CID00000559140T",
|
logger.info(f"Calling DisburseLoan endpoint with data: {loan}")
|
||||||
"accountId": "ACC20267810160T",
|
loan_data = loan.to_dict()
|
||||||
"productId": "3MPC",
|
|
||||||
"provideAmount": 10000.0,
|
data = {
|
||||||
"collectAmountInterest": 19.0,
|
"transactionId": loan_data.get('transactionId'),
|
||||||
"collectAmountMgtFee": 66.0,
|
"FbnTransactionId": loan_data.get('transactionId'),
|
||||||
"collectAmountInsurance": 66.0,
|
"debtId": str(loan_data.get('debtId')),
|
||||||
"collectAmountVAT": 75.00,
|
"customerId": loan_data.get('customerId'),
|
||||||
"countryId": "01",
|
"accountId": loan_data.get('accountId'),
|
||||||
"comment": "Loan Disbursement"
|
"productId": str(loan_data.get('productId', "")),
|
||||||
}"""
|
"provideAmount": loan_data.get('currentLoanAmount'),
|
||||||
response = SimbrellaClient.disburse_loan()
|
}
|
||||||
|
response = SimbrellaClient.disburse_loan(data)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -43,4 +43,11 @@ class LoanService:
|
|||||||
"""
|
"""
|
||||||
Get the latest loan without a disbursement date.
|
Get the latest loan without a disbursement date.
|
||||||
"""
|
"""
|
||||||
return Loan.get_latest_loan_without_disburse_date()
|
return Loan.get_latest_loan_without_disburse_date()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_latest_loan_with_disburse_date(cls):
|
||||||
|
"""
|
||||||
|
Get the latest loan without a disbursement date.
|
||||||
|
"""
|
||||||
|
return Loan.get_latest_loan_with_disburse_date()
|
||||||
|
|||||||
Reference in New Issue
Block a user