Major update

This commit is contained in:
Azeez Muibi
2025-03-27 08:21:20 +01:00
parent 1a36416094
commit ba4d878daf
24 changed files with 776 additions and 254 deletions
+42 -38
View File
@@ -1,64 +1,68 @@
from flask import jsonify
from flask import request, jsonify
from marshmallow import ValidationError
from app.utils.logger import logger
from app.api.schemas.repayment import RepaymentSchema, RepaymentResponseSchema
class RepaymentService:
@staticmethod
def process_request(data):
"""
Process a repayment request from Simbrella to FirstBank
Process the Repayment request.
Args:
data (dict): The request data containing repayment details
data (dict): The request data.
Returns:
flask.Response: JSON response with the result of the repayment operation
dict: A standardized response.
"""
try:
# Log the incoming request
logger.info(f"Processing repayment request: {data}")
logger.info("Processing Repayment request")
# Validate required fields
required_fields = [
"requestId", "countryCode", "transactionId", "debtId",
"customerId", "accountId", "productId", "collectAmount",
"collectionMethod", "lienAmount"
]
# Validate input data using RepaymentSchema
schema = RepaymentSchema()
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 process the repayment
# Process the repayment request
# This is where you would implement the actual business logic
# For now, we'll just return a successful response
# For demonstration, we'll simulate a partial repayment
collected_amount = validated_data.get('collectedAmount') * 0.75 # 75% of requested amount
lien_amount = validated_data.get('lienAmount') * 0.25 # 25% of requested amount as lien
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", ""),
response_data = {
"requestId": validated_data.get('requestId'),
"countryCode": validated_data.get('countryCode'),
"transactionId": validated_data.get('transactionId'),
"debtId": validated_data.get('debtId'),
"customerId": validated_data.get('customerId'),
"accountId": validated_data.get('accountId'),
"productId": validated_data.get('productId'),
"collectedAmount": collected_amount,
"penalCharge": validated_data.get('penalCharge', 0),
"lienAmount": lien_amount,
"comment": validated_data.get('comment', ""),
"resultCode": "00",
"resultDescription": "Loan Collection Successful"
}
logger.info(f"Repayment response: {response}")
return jsonify(response)
# Validate the response using the response schema
response_schema = RepaymentResponseSchema()
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 repayment 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