Updated Disbursement

This commit is contained in:
Azeez Muibi
2025-03-26 15:05:52 +01:00
parent 183c1bf46f
commit f52de3d8f8
8 changed files with 249 additions and 45 deletions
+30 -24
View File
@@ -1,8 +1,7 @@
from flask import request, jsonify
from marshmallow import ValidationError
from app.utils.logger import logger
from app.api.helpers.response_helper import ResponseHelper
from app.api.schemas.disbursement import DisbursementSchema
from app.api.schemas.disbursement import DisbursementSchema, DisbursementResponseSchema
class DisbursementService:
@staticmethod
@@ -23,40 +22,47 @@ class DisbursementService:
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 = {
"transactionId": "T001",
"TransactionId": "Tr201712RK9232P115",
"debtId": "273194670",
"customerId": "CN621868",
"accountId": "2017821799",
"productId": "101",
"provideAmount": 100000.0,
"collectAmountInterest": 5000,
"collectAmountMgtFee": 1000,
"collectAmountInsurance": 1000,
"collectAmountVAT": 75,
"countryId": "01",
"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 ResponseHelper.success(
# data=response_data,
# message="Disbursement completed successfully"
# )
return response_data
return jsonify(validated_response)
except ValidationError as err:
logger.error(f"Validation Error: {err.messages}")
return jsonify({
"message": "Validation exception"
}) , 422
"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({
"message": "Internal Server Error"
}) , 500
"resultCode": "08",
"resultDescription": f"Error occurred: {str(e)}"
}), 500