73 lines
2.3 KiB
Python
73 lines
2.3 KiB
Python
from flask import session, jsonify
|
|
from app.utils.logger import logger
|
|
from app.helpers.response_helper import ResponseHelper
|
|
from app.schemas.eligibility_check import EligibilityCheckSchema
|
|
from marshmallow import ValidationError
|
|
|
|
class EligibilityCheckService:
|
|
@staticmethod
|
|
def process_request(data):
|
|
"""
|
|
Process the EligibilityCheck request.
|
|
|
|
Args:
|
|
data (dict): The request data.
|
|
|
|
Returns:
|
|
dict: A standardized response.
|
|
"""
|
|
try:
|
|
logger.info("Processing EligibilityCheck request")
|
|
|
|
# Validate input data using Schema
|
|
schema = EligibilityCheckSchema()
|
|
validated_data = schema.load(data) # Raises an error if invalid
|
|
|
|
# Example: Validate data, perform calculations, etc.
|
|
if not data:
|
|
return ResponseHelper.error("Invalid input data", status_code=400)
|
|
|
|
# Simulate processing
|
|
response_data = {
|
|
"customerId": "CN621868",
|
|
"transactionId": "Tr201712RK9232P115",
|
|
"msisdn": "3451342",
|
|
"eligibleOffers": [
|
|
{
|
|
"minamount": 5000,
|
|
"maxamount": 20000,
|
|
"productId": 101,
|
|
"offerid": 101,
|
|
"Tenor": 30
|
|
},
|
|
{
|
|
"minamount": 20000,
|
|
"maxamount": 50000,
|
|
"productId": 102,
|
|
"offerid": 102,
|
|
"Tenor": 60
|
|
}
|
|
],
|
|
"resultCode": "00",
|
|
"resultDescription": "Successful"
|
|
}
|
|
|
|
|
|
# Return a success response
|
|
# return ResponseHelper.success(
|
|
# data=response_data,
|
|
# message="Eligibility check completed successfully"
|
|
# )
|
|
|
|
return response_data
|
|
except ValidationError as err:
|
|
logger.error(f"Validation Error: {err.messages}")
|
|
return jsonify({
|
|
"message": "Validation exception"
|
|
}) , 422
|
|
|
|
except Exception as e:
|
|
logger.error(f"An error occurred: {str(e)}", exc_info=True)
|
|
return jsonify({
|
|
"message": "Internal Server Error"
|
|
}) , 500 |