Files
Azeez Muibi ba4d878daf Major update
2025-03-27 08:21:20 +01:00

72 lines
2.4 KiB
Python

from flask import request, jsonify
from marshmallow import ValidationError
from app.utils.logger import logger
from app.api.schemas.rac_check import RACCheckSchema, RACCheckResponseSchema
class RACCheckService:
@staticmethod
def process_request(data):
"""
Process the RACCheck request.
Args:
data (dict): The request data.
Returns:
dict: A standardized response.
"""
try:
logger.info("Processing RACCheck request")
# Validate input data using RACCheckSchema
schema = RACCheckSchema()
validated_data = schema.load(data) # Raises ValidationError if invalid
# Simulated processing logic
# In a real implementation, this would interact with your business logic
# to check the RAC criteria
# For demonstration, we'll simulate all checks passing
rac_response = {
"Salary account": "1",
"BVN": "1",
"BVNAttachedToAccount": "1",
"CRMS": "1",
"CRC": "1",
"AccountStatus": "1",
"Lien": "1",
"NoBouncedCheck": "1",
"Whitelist": "1",
"NoPastDueSalaryLoan": "1",
"NoPastDueOtherLoan": "1"
}
response_data = {
"transactionId": validated_data.get('transactionId'),
"customerId": validated_data.get('customerId'),
"accountId": validated_data.get('accountId'),
"RACResponse": rac_response,
"resultCode": "00",
"resultDescription": "RAC Check Successful"
}
# Validate the response using the response schema
response_schema = RACCheckResponseSchema()
validated_response = response_schema.dump(response_data)
return jsonify(validated_response)
except ValidationError as err:
logger.error(f"Validation Error: {err.messages}")
return jsonify({
"resultCode": "01",
"resultDescription": f"Validation error: {err.messages}"
}), 422
except Exception as e:
logger.error(f"An error occurred: {str(e)}", exc_info=True)
return jsonify({
"resultCode": "08",
"resultDescription": f"Error occurred: {str(e)}"
}), 500