made changes on the api to match bank api

This commit was merged in pull request #6.
This commit is contained in:
Chinenye Nmoh
2025-05-18 20:18:15 +01:00
parent 556d51f133
commit d0d51f35c0
26 changed files with 1085 additions and 776 deletions
+26 -27
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, DisburseLoanResponseSchema
class DisbursementService:
@staticmethod
@@ -14,7 +13,7 @@ class DisbursementService:
data (dict): The request data.
Returns:
dict: A standardized response.
tuple: JSON response and HTTP status code.
"""
try:
logger.info("Processing Disbursement request")
@@ -23,40 +22,40 @@ class DisbursementService:
schema = DisbursementSchema()
validated_data = schema.load(data) # Raises ValidationError if invalid
# Simulated processing logic
# For demo purposes, we simulate a response using the validated data
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",
"resultCode": "00",
"resultDescription": "Loan Request Completed Successfully!"
"transactionId": validated_data.get("transactionId"),
"fbnTransactionId": "Tr201712RK9232P115", # Example or generated value
"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"),
"collectAmountInterest": validated_data.get("collectAmountInterest"),
"collectAmountMgtFee": validated_data.get("collectAmountMgtFee"),
"collectAmountInsurance": validated_data.get("collectAmountInsurance"),
"collectAmountVAT": validated_data.get("collectAmountVAT"),
"countryId": validated_data.get("countryId"),
"responseCode": "00", # success code example
"responseMessage": "Loan Request Completed Successfully!"
}
# Serialize response
response_schema = DisburseLoanResponseSchema()
result = response_schema.dump(response_data)
# return ResponseHelper.success(
# data=response_data,
# message="Disbursement completed successfully"
# )
return response_data
return jsonify(result), 200
except ValidationError as err:
logger.error(f"Validation Error: {err.messages}")
return jsonify({
"message": "Validation exception"
}) , 422
"message": "Validation exception",
"errors": 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
}), 500