55 lines
1.8 KiB
Python
55 lines
1.8 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.penal_charge import PenalChargeSchema, CollectPenalFeeResponseSchema
|
|
|
|
|
|
class PenalChargeService:
|
|
@staticmethod
|
|
def process_request(data):
|
|
"""
|
|
Process the PenalCharge request.
|
|
|
|
Args:
|
|
data (dict): The request data.
|
|
|
|
Returns:
|
|
dict: A standardized response.
|
|
"""
|
|
try:
|
|
logger.info("Processing PenalCharge request")
|
|
|
|
# Validate input data using PenalChargeSchema
|
|
schema = PenalChargeSchema()
|
|
validated_data = schema.load(data)
|
|
|
|
# Simulated processing logic
|
|
response_data = {
|
|
"customerId": validated_data.get("customerId"),
|
|
"transactionId": validated_data.get("transactionId"),
|
|
"amountCollected": validated_data.get("penalCharge", 0.0),
|
|
"accountId": validated_data.get("accountId"),
|
|
"responseCode": "00",
|
|
"responseMessage": "Penal charge debited successfully"
|
|
}
|
|
|
|
# Optionally validate/serialize response using schema
|
|
response_schema = CollectPenalFeeResponseSchema()
|
|
result = response_schema.dump(response_data)
|
|
|
|
return result
|
|
|
|
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
|