""" Controller for notification callback endpoints. """ from flask import Blueprint, request, jsonify from api.middleware import basic_auth_required from api.models import NotificationCallbackRequest, NotificationCallbackResponse import logging # Configure logger logger = logging.getLogger(__name__) # Create blueprint notification_bp = Blueprint('notification', __name__) @notification_bp.route('/NotificationCallback', methods=['POST']) @basic_auth_required def notification_callback(): """ Endpoint to receive transaction status notifications. This method is used for informing Simbrella about the status of transactions that FirstBank has processed. Returns: JSON response acknowledging receipt of notification """ try: # Parse and validate request data = request.get_json() if not data: return jsonify({ 'resultCode': '400', 'resultDescription': 'Invalid JSON payload' }), 400 # Validate required fields required_fields = ['fbnTransactionId', 'transactionId', 'customerId', 'accountId', 'debtId', 'transactionType', 'amountProvided', 'amountCollected', 'responseCode', 'responseDescription'] for field in required_fields: if field not in data: return jsonify({ 'resultCode': '422', 'resultDescription': f'Missing required field: {field}' }), 422 # Create request model req = NotificationCallbackRequest.from_dict(data) # Process notification (this would connect to the business logic) # For demonstration, we'll return a mock response # Log the notification details logger.info(f"Received notification for transaction {req.transactionId}, " f"type {req.transactionType}, status {req.responseCode}") # Create response response = NotificationCallbackResponse( resultCode="00", resultDescription="Successful" ) return jsonify(response.to_dict()) except Exception as e: logger.error(f"Error processing notification callback: {str(e)}") return jsonify({ 'resultCode': '500', 'resultDescription': 'Internal server error' }), 500