Files
2025-03-26 15:05:52 +01:00

68 lines
2.8 KiB
Python

from flask import request, jsonify
from marshmallow import ValidationError
from app.utils.logger import logger
from app.api.schemas.disbursement import DisbursementSchema, DisbursementResponseSchema
class DisbursementService:
@staticmethod
def process_request(data):
"""
Process the Disbursement request.
Args:
data (dict): The request data.
Returns:
dict: A standardized response.
"""
try:
logger.info("Processing Disbursement request")
# Validate input data using DisbursementSchema
schema = DisbursementSchema()
validated_data = schema.load(data) # Raises ValidationError if invalid
# Extract fees details for easier access
fees_details = validated_data.get('feesDetails', {})
# Simulated processing logic
# In a real implementation, this would interact with your business logic
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'),
"provideAmount": validated_data.get('provideAmount'),
"totalFees": validated_data.get('totalFees'),
"feesDetails": {
"collectAmountInterest": fees_details.get('collectAmountInterest'),
"collectAmountMgtFee": fees_details.get('collectAmountMgtFee'),
"collectAmountInsurance": fees_details.get('collectAmountInsurance'),
"collectAmountVAT": fees_details.get('collectAmountVAT')
},
"resultCode": "00",
"resultDescription": "Loan Request Completed Successfully!"
}
# Validate the response using the response schema
response_schema = DisbursementResponseSchema()
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