[add]: Account Balance check
This commit was merged in pull request #77.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from app.api.integrations.simbrella import SimbrellaIntegration
|
||||
from flask import request, jsonify
|
||||
from marshmallow import ValidationError
|
||||
from app.api.enums.loan_status import LoanStatus
|
||||
@@ -12,9 +13,11 @@ from app.api.enums import TransactionType
|
||||
from threading import Thread
|
||||
from app.extensions import db
|
||||
from app.api.integrations import EventServiceIntegration
|
||||
from app.config import settings
|
||||
|
||||
class RepaymentService(BaseService):
|
||||
TRANSACTION_TYPE = TransactionType.REPAYMENT
|
||||
ENABLE_ACCOUNT_BALANCE_CHECK = settings.ENABLE_ACCOUNT_BALANCE_CHECK
|
||||
|
||||
@staticmethod
|
||||
def process_request(data):
|
||||
@@ -46,6 +49,38 @@ class RepaymentService(BaseService):
|
||||
# Check loan exists
|
||||
load_loan = Loan.get_customer_loan(loan_id = loan_id, customer_id = customer_id)
|
||||
|
||||
|
||||
# Check Customer Account Balance if enabled
|
||||
if RepaymentService.ENABLE_ACCOUNT_BALANCE_CHECK:
|
||||
response = SimbrellaIntegration.verify_account_balance(
|
||||
account_id = account_id,
|
||||
amount = load_loan.balance,
|
||||
request_id = request_id,
|
||||
)
|
||||
|
||||
# this check for error is not valid
|
||||
if response.status_code != 200:
|
||||
return ResponseHelper.error(result_description="Balance Check failed")
|
||||
|
||||
response = response.json()
|
||||
|
||||
logger.info(f"This is Response (Balance Check): {str(response)}", exc_info=True)
|
||||
|
||||
|
||||
if not response or response['responseCode'] != '00':
|
||||
|
||||
if response:
|
||||
logger.error(f"{response['responseMessage']}")
|
||||
|
||||
return ResponseHelper.error(result_description=f"Balance Check failed")
|
||||
|
||||
verify_account_balance_response = response['isSufficient']
|
||||
|
||||
if not verify_account_balance_response or verify_account_balance_response in [False, "false"]:
|
||||
logger.error(f"Balance Check failed: Insufficient Account Balance")
|
||||
return ResponseHelper.error(result_description=f"Insufficient Account Balance")
|
||||
|
||||
|
||||
# Save the repayment details
|
||||
repayment = Repayment.create_repayment(
|
||||
customer_id = customer_id,
|
||||
|
||||
Reference in New Issue
Block a user