62 lines
2.0 KiB
Python
62 lines
2.0 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)
|
|
|
|
customerId = validated_data["customerId"]
|
|
transactionId = validated_data["transactionId"]
|
|
penalCharge = validated_data["penalCharge"]
|
|
accountId = validated_data["accountId"]
|
|
lienAmount = validated_data["lienAmount"]
|
|
|
|
response_data = {
|
|
"responseCode": "00",
|
|
"responseMessage": "Penal Collection Successful",
|
|
"customerId": customerId,
|
|
"transactionId": transactionId,
|
|
"amountCollected": penalCharge,
|
|
"lienAmount": lienAmount,
|
|
"accountId": accountId,
|
|
}
|
|
|
|
# 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
|