61 lines
2.1 KiB
Python
61 lines
2.1 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.transaction_verify import (
|
|
TransactionVerifySchema,
|
|
TransactionVerifyResponseSchema
|
|
)
|
|
|
|
|
|
class TransactionVerifyService:
|
|
@staticmethod
|
|
def process_request(data):
|
|
"""
|
|
Process the TransactionVerify request.
|
|
|
|
Args:
|
|
data (dict): The request data.
|
|
|
|
Returns:
|
|
dict: A standardized response.
|
|
"""
|
|
try:
|
|
logger.info("Processing TransactionVerify request")
|
|
|
|
# Validate input data using TransactionVerifySchema
|
|
schema = TransactionVerifySchema()
|
|
validated_data = schema.load(data) # Raises ValidationError if invalid
|
|
|
|
# Simulated processing logic
|
|
response_data = {
|
|
"responseCode": "00",
|
|
"responseDescr": "Success",
|
|
"fullDescription": "Collect Status retrieved successfully.",
|
|
"customerId": validated_data.get("customerId"),
|
|
"accountId": validated_data.get("accountId"),
|
|
"providedAmount": 0.0,
|
|
"collectedAmount": 7.50,
|
|
"transactionId": validated_data.get("transactionId"),
|
|
"transactionType": validated_data.get("transactionType")
|
|
}
|
|
|
|
# Validate and serialize response with TransactionVerifyResponseSchema
|
|
response_schema = TransactionVerifyResponseSchema()
|
|
serialized_response = response_schema.dump(response_data)
|
|
|
|
return jsonify(serialized_response), 200
|
|
|
|
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
|