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 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) # Simulated RAC check logic — create racResponse manually or via logic rac_response = { "hasSalaryAccount": True, "bvnValidated": True, "creditBureauCheck": False, "crmsCheck": True, "accountStatus": True, "hasLien": False, "noBouncedCheck": True, "isWhitelisted": True, "hasPastDueLoan": False } full_response = { "transactionId": validated_data["transactionId"], "customerId": validated_data["customerId"], "accountId": validated_data["accountId"], "racResponse": rac_response } response_schema = RACCheckResponseSchema() result = response_schema.dump(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