Files
digifi-BankEmulator/app/api/services/rac_check.py
T
CHIEFSOFT\ameye dfdfa51583 res[pose code
2025-06-05 22:43:38 -04:00

96 lines
3.6 KiB
Python

from flask import request, jsonify
from marshmallow import ValidationError
from app.utils.logger import logger
from app.api.helpers.response_helper import ResponseHelper
from app.api.schemas.rac_check import RACCheckSchema, RACCheckResponseSchema
from datetime import datetime
from decimal import Decimal
class RACCheckService:
@staticmethod
def process_request(data):
"""
Process the RACCheck request.
Args:
data (dict): The request data.
Returns:
tuple: JSON response and status code.
"""
try:
logger.info("Processing RACCheck request")
# Validate input data
schema = RACCheckSchema()
validated_data = schema.load(data)
transactionId = fields.Str(required=True)
fbnTransactionId = fields.Str(required=True)
customerId = fields.Str(required=True)
accountId = fields.Str(required=True)
# Simulated RAC check logic — create racResponse manually or via logic
# random_float = random.random() # temporary to play data
rac_response = {
"PROCESS_DATE": datetime.strptime("2025-06-05", "%Y-%m-%d").date(),
"CIF_ID": validated_data["transactionId"],
"CUSTOMER_id": validated_data["customerId"],
"SALACCT_1": validated_data["accountId"],
"ALERT_PHONE": "2348031234567",
"AVERAGE_SALARY": Decimal("1255000"),
"LOAN_OUSTANDING_BAL": Decimal("0"),
"EMI": Decimal("10000"),
"ELIG_AMT": Decimal("25000"),
"rule1-45day-sal": True,
"rule2-2m-sal": True,
"rule3-no-bounced-check": True,
"rule4-current-loan-payments": True,
"rule5-no-past-due-fadv-loan": True,
"rule6--no-past-due-other-loan": True,
"rule7-consistent-salary-amount": True,
"rule8-whitelisted": True,
"rule9-regular-account": True,
"rule10-bvn-validation": True,
"rule11-CRC-no-delinquency": True,
"rule12-CRMS-no-delinquency": True,
"rule13-BVN-ignore": True,
"rule14-no-lien": True,
"rule15-null-ignore": True,
"OVERALL_ELIG": True,
"SALARYPAYMENT_1": Decimal("1255000"),
"SALARYPAYMENT_2": Decimal("1255000"),
"SALARYPAYMENT_3": Decimal("1255000"),
"SALARYPAYMENT_4": Decimal("1255000"),
"SALARYPAYMENT_5": Decimal("1255000"),
"SALARYPAYMENT_6": Decimal("1255000"),
"resultCode": "00",
"resultDescription": "RAC Check Successful"
}
full_response = {
"transactionId": validated_data["transactionId"],
"customerId": validated_data["customerId"],
"accountId": validated_data["accountId"],
"racResponse": rac_response
}
# response_schema = RACCheckResponseSchema()
result = full_response
return jsonify(result), 200
except ValidationError as err:
logger.error(f"Validation Error: {err.messages}")
return jsonify({
"message": "Validation exception",
"errors": err.messages
}), 422
except Exception as e:
logger.error(f"An error occurred: {str(e)}", exc_info=True)
return jsonify({
"message": "Internal Server Error"
}), 500