Major update
This commit is contained in:
@@ -1,84 +1,77 @@
|
||||
from flask import jsonify
|
||||
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 a status call request to check transaction status
|
||||
Process the StatusCall request.
|
||||
|
||||
Args:
|
||||
data (dict): The request data containing transaction details to check
|
||||
data (dict): The request data.
|
||||
|
||||
Returns:
|
||||
flask.Response: JSON response with the status of the transaction
|
||||
dict: A standardized response.
|
||||
"""
|
||||
try:
|
||||
# Log the incoming request
|
||||
logger.info(f"Processing status call request: {data}")
|
||||
logger.info("Processing StatusCall request")
|
||||
|
||||
# Validate required fields
|
||||
required_fields = [
|
||||
"transactionId", "transactionType", "customerId"
|
||||
]
|
||||
# Validate input data using StatusCallSchema
|
||||
schema = StatusCallSchema()
|
||||
validated_data = schema.load(data) # Raises ValidationError if invalid
|
||||
|
||||
for field in required_fields:
|
||||
if field not in data:
|
||||
logger.error(f"Missing required field: {field}")
|
||||
return jsonify({
|
||||
"resultCode": "01",
|
||||
"resultDescription": f"Missing required field: {field}"
|
||||
}), 400
|
||||
# Simulated processing logic
|
||||
# In a real implementation, this would interact with your business logic
|
||||
# to check the status of a transaction
|
||||
|
||||
# Process the status call request based on transaction type
|
||||
transaction_type = data.get("transactionType")
|
||||
# For demonstration, we'll simulate different responses based on transaction type
|
||||
transaction_type = validated_data.get('transactionType')
|
||||
|
||||
# Prepare the response based on transaction type
|
||||
if transaction_type == "Disbursement":
|
||||
status = {
|
||||
"providedAmount": 1000.00,
|
||||
"collectedAmount": 0.00,
|
||||
"resultCode": "00",
|
||||
"resultDescription": "Loan Provision is successful"
|
||||
}
|
||||
provided_amount = 1000.00
|
||||
collected_amount = 0.00
|
||||
inner_result_description = "Loan Provision is successful"
|
||||
elif transaction_type == "Collection":
|
||||
status = {
|
||||
"providedAmount": 0.00,
|
||||
"collectedAmount": 100.00,
|
||||
"resultCode": "00",
|
||||
"resultDescription": "Loan Collection is successful"
|
||||
}
|
||||
elif transaction_type == "PenalCharge":
|
||||
status = {
|
||||
"transactionId": data.get("transactionId"),
|
||||
"providedAmount": 0.00,
|
||||
"collectedAmount": 100.00,
|
||||
"resultCode": "00",
|
||||
"resultDescription": "Penal Charge is successful"
|
||||
}
|
||||
else:
|
||||
logger.error(f"Invalid transaction type: {transaction_type}")
|
||||
return jsonify({
|
||||
"resultCode": "01",
|
||||
"resultDescription": f"Invalid transaction type: {transaction_type}"
|
||||
}), 400
|
||||
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 = {
|
||||
"requestId": data.get("requestId", ""),
|
||||
"countryCode": data.get("countryCode", "NGR"),
|
||||
"transactionId": data.get("transactionId"),
|
||||
"Status": status,
|
||||
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"
|
||||
}
|
||||
|
||||
logger.info(f"Status call response: {response}")
|
||||
return jsonify(response)
|
||||
# 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"Error processing status call request: {str(e)}")
|
||||
logger.error(f"An error occurred: {str(e)}", exc_info=True)
|
||||
return jsonify({
|
||||
"resultCode": "08",
|
||||
"resultDescription": "Error occurred"
|
||||
"resultDescription": f"Error occurred: {str(e)}"
|
||||
}), 500
|
||||
Reference in New Issue
Block a user