Files
digifi-BankEmulator/app/api/services/status_call.py
T
2025-03-26 15:05:52 +01:00

84 lines
3.1 KiB
Python

from flask import jsonify
from app.utils.logger import logger
class StatusCallService:
@staticmethod
def process_request(data):
"""
Process a status call request to check transaction status
Args:
data (dict): The request data containing transaction details to check
Returns:
flask.Response: JSON response with the status of the transaction
"""
try:
# Log the incoming request
logger.info(f"Processing status call request: {data}")
# Validate required fields
required_fields = [
"transactionId", "transactionType", "customerId"
]
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
# Process the status call request based on transaction type
transaction_type = 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"
}
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
response = {
"requestId": data.get("requestId", ""),
"countryCode": data.get("countryCode", "NGR"),
"transactionId": data.get("transactionId"),
"Status": status,
"resultCode": "00",
"resultDescription": "SUCCESS"
}
logger.info(f"Status call response: {response}")
return jsonify(response)
except Exception as e:
logger.error(f"Error processing status call request: {str(e)}")
return jsonify({
"resultCode": "08",
"resultDescription": "Error occurred"
}), 500