Files
Azeez Muibi ba4d878daf Major update
2025-03-27 08:21:20 +01:00

77 lines
2.9 KiB
Python

from flask import request, jsonify
from marshmallow import ValidationError
from app.utils.logger import logger
from app.api.schemas.status_call import StatusCallSchema, StatusCallResponseSchema
class StatusCallService:
@staticmethod
def process_request(data):
"""
Process the StatusCall request.
Args:
data (dict): The request data.
Returns:
dict: A standardized response.
"""
try:
logger.info("Processing StatusCall request")
# Validate input data using StatusCallSchema
schema = StatusCallSchema()
validated_data = schema.load(data) # Raises ValidationError if invalid
# Simulated processing logic
# In a real implementation, this would interact with your business logic
# to check the status of a transaction
# For demonstration, we'll simulate different responses based on transaction type
transaction_type = validated_data.get('transactionType')
if transaction_type == "Disbursement":
provided_amount = 1000.00
collected_amount = 0.00
inner_result_description = "Loan Provision is successful"
elif transaction_type == "Collection":
provided_amount = 0.00
collected_amount = 1050.00
inner_result_description = "Loan Collection is successful"
else: # PenalCharge
provided_amount = 0.00
collected_amount = 50.00
inner_result_description = "Penal Charge is successful"
response_data = {
"transactionId": "24110114545374721", # This would be generated in a real system
"data": {
"transactionId": validated_data.get('transactionId'),
"providedAmount": provided_amount,
"collectedAmount": collected_amount,
"resultCode": "00",
"resultDescription": inner_result_description
},
"resultCode": "00",
"resultDescription": "SUCCESS"
}
# Validate the response using the response schema
response_schema = StatusCallResponseSchema()
validated_response = response_schema.dump(response_data)
return jsonify(validated_response)
except ValidationError as err:
logger.error(f"Validation Error: {err.messages}")
return jsonify({
"resultCode": "01",
"resultDescription": f"Validation error: {err.messages}"
}), 422
except Exception as e:
logger.error(f"An error occurred: {str(e)}", exc_info=True)
return jsonify({
"resultCode": "08",
"resultDescription": f"Error occurred: {str(e)}"
}), 500