Updated Select Offer
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from app.api.services.rac_check import RACCheckService
|
||||
from app.api.services.disbursement import DisbursementService
|
||||
from app.api.services.select_offer import SelectOfferService
|
||||
from app.api.services.collect_loan import CollectLoanService
|
||||
from app.api.services.transaction_verify import TransactionVerifyService
|
||||
from app.api.services.penal_charge import PenalChargeService
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
from flask import request, jsonify
|
||||
from marshmallow import ValidationError
|
||||
from app.utils.logger import logger
|
||||
from app.api.schemas.select_offer import SelectOfferSchema, SelectOfferResponseSchema
|
||||
|
||||
class SelectOfferService:
|
||||
@staticmethod
|
||||
def process_request(data):
|
||||
"""
|
||||
Process the SelectOffer request.
|
||||
|
||||
Args:
|
||||
data (dict): The request data.
|
||||
|
||||
Returns:
|
||||
dict: A standardized response.
|
||||
"""
|
||||
try:
|
||||
logger.info("Processing SelectOffer request")
|
||||
|
||||
# Validate input data using SelectOfferSchema
|
||||
schema = SelectOfferSchema()
|
||||
validated_data = schema.load(data) # Raises ValidationError if invalid
|
||||
|
||||
# Simulated processing logic
|
||||
# In a real implementation, this would interact with your business logic
|
||||
# to determine eligible loan offers based on the requested amount and product
|
||||
response_data = {
|
||||
"requestId": validated_data.get('requestId'),
|
||||
"transactionId": validated_data.get('transactionId'),
|
||||
"customerId": validated_data.get('customerId'),
|
||||
"accountId": validated_data.get('accountId'),
|
||||
"outstandingDebtAmount": 0,
|
||||
"loan": [
|
||||
{
|
||||
"offerId": "14451",
|
||||
"productId": "2030",
|
||||
"amount": validated_data.get('requestedAmount'),
|
||||
"upfrontPayment": validated_data.get('requestedAmount') * 0.1, # 10% upfront
|
||||
"interestRate": 3.0,
|
||||
"Interest": validated_data.get('requestedAmount') * 0.03, # 3% interest
|
||||
"ManagementRate": 1.0,
|
||||
"ManagementFee": validated_data.get('requestedAmount') * 0.01, # 1% management fee
|
||||
"InsuranceRate": 1.0,
|
||||
"InsuranceFee": validated_data.get('requestedAmount') * 0.01, # 1% insurance
|
||||
"VATRate": 7.5,
|
||||
"VATamount": (validated_data.get('requestedAmount') * 0.01) * 0.075, # 7.5% VAT on management fee
|
||||
"recommendedRepaymentDates": ["2023-12-30"], # Example date
|
||||
"installmentAmount": validated_data.get('requestedAmount') * 1.1, # Principal + 10% fees
|
||||
"totalRepaymentAmount": validated_data.get('requestedAmount') * 1.1 # Principal + 10% fees
|
||||
}
|
||||
],
|
||||
"resultCode": "00",
|
||||
"resultDescription": "Successful"
|
||||
}
|
||||
|
||||
# Validate the response using the response schema
|
||||
response_schema = SelectOfferResponseSchema()
|
||||
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
|
||||
Reference in New Issue
Block a user