67 lines
2.6 KiB
Python
67 lines
2.6 KiB
Python
from flask import request, jsonify
|
|
from marshmallow import ValidationError
|
|
from app.utils.logger import logger
|
|
from app.api.schemas.collect_loan import CollectLoanSchema, CollectLoanResponseSchema
|
|
|
|
|
|
class CollectLoanService:
|
|
@staticmethod
|
|
def process_request(data):
|
|
"""
|
|
Process the CollectLoan request.
|
|
|
|
Args:
|
|
data (dict): The request data.
|
|
|
|
Returns:
|
|
dict: A standardized response.
|
|
"""
|
|
try:
|
|
logger.info("Processing CollectLoan request")
|
|
|
|
# Validate input data using CollectLoanSchema
|
|
schema = CollectLoanSchema()
|
|
validated_data = schema.load(data) # Raises ValidationError if invalid
|
|
|
|
# Simulated processing logic
|
|
# In a real implementation, this would interact with your business logic
|
|
# to process the loan collection
|
|
|
|
# For demonstration, we'll simulate a partial collection
|
|
collect_amount = validated_data.get('collectAmount') * 0.75 # 75% of requested amount
|
|
lien_amount = validated_data.get('lienAmount') * 0.25 # 25% of requested amount as lien
|
|
|
|
response_data = {
|
|
"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'),
|
|
"collectAmount": collect_amount,
|
|
"penalCharge": validated_data.get('penalCharge', 0),
|
|
"lienAmount": lien_amount,
|
|
"countryId": validated_data.get('countryId'),
|
|
"comment": validated_data.get('comment', ""),
|
|
"resultCode": "00",
|
|
"resultDescription": "Loan Collection Successful"
|
|
}
|
|
|
|
# Validate the response using the response schema
|
|
response_schema = CollectLoanResponseSchema()
|
|
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 |