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

64 lines
2.4 KiB
Python

from flask import jsonify
from app.utils.logger import logger
class RepaymentService:
@staticmethod
def process_request(data):
"""
Process a repayment request from Simbrella to FirstBank
Args:
data (dict): The request data containing repayment details
Returns:
flask.Response: JSON response with the result of the repayment operation
"""
try:
# Log the incoming request
logger.info(f"Processing repayment request: {data}")
# Validate required fields
required_fields = [
"requestId", "countryCode", "transactionId", "debtId",
"customerId", "accountId", "productId", "collectAmount",
"collectionMethod", "lienAmount"
]
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 repayment request
# This is where you would implement the actual business logic
# For now, we'll just return a successful response
response = {
"requestId": data.get("requestId"),
"countryCode": data.get("countryCode"),
"transactionId": data.get("transactionId"),
"debtId": data.get("debtId"),
"customerId": data.get("customerId"),
"accountId": data.get("accountId"),
"productId": data.get("productId"),
"collectAmount": data.get("collectAmount"),
"penalCharge": data.get("penalCharge", 0),
"lienAmount": data.get("lienAmount"),
"comment": data.get("comment", ""),
"resultCode": "00",
"resultDescription": "Loan Collection Successful"
}
logger.info(f"Repayment response: {response}")
return jsonify(response)
except Exception as e:
logger.error(f"Error processing repayment request: {str(e)}")
return jsonify({
"resultCode": "08",
"resultDescription": "Error occurred"
}), 500