from flask import request, jsonify from marshmallow import ValidationError from app.api.services.base_service import BaseService from app.api.enums import TransactionType from app.utils.logger import logger from app.api.schemas.notification_callback import NotificationCallbackSchema from app.extensions import db from app.api.helpers.response_helper import ResponseHelper class NotificationCallbackService(BaseService): TRANSACTION_TYPE = TransactionType.NOTIFICATION_CALLBACK @staticmethod def process_request(data): """ Process the NotificationCallback request. Args: data (dict): The request data. Returns: dict: A standardized response. """ try: logger.info("Processing NotificationCallback request") # Validate input data using the NotificationCallback schema schema = NotificationCallbackSchema() validated_data = schema.load(data) # Raises ValidationError if invalid return ResponseHelper.success() except ValidationError as err: logger.error(f"Validation Error: {getattr(err, 'messages', str(err))}") db.session.rollback() return ResponseHelper.unprocessable_entity(result_description="Validation exception") except ValueError as err: logger.error(f"{getattr(err, 'messages', str(err))}") db.session.rollback() return ResponseHelper.error(result_description=str(err)) except Exception as e: logger.error(f"An error occurred: {str(e)}", exc_info=True) db.session.rollback() return ResponseHelper.internal_server_error()