110 lines
3.9 KiB
Python
110 lines
3.9 KiB
Python
from flask import request
|
|
from marshmallow import ValidationError
|
|
from app.utils.logger import logger
|
|
from app.helpers.response_helper import ResponseHelper
|
|
from app.schemas.select_offer import SelectOfferSchema
|
|
|
|
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 the imported schema
|
|
schema = SelectOfferSchema()
|
|
validated_data = schema.load(data) # Raises ValidationError if invalid
|
|
|
|
# Business logic - selecting an offer
|
|
response_data = {
|
|
"outstandingDebtAmount": 0,
|
|
"requestId": "202111170001371256908",
|
|
"transactionId": "1231231321232",
|
|
"customerId": "1256907",
|
|
"accountId": "5948306019",
|
|
"offers": [
|
|
{
|
|
"offerId": "14451",
|
|
"productId": "2030",
|
|
"amount": 10000.0,
|
|
"upfrontPayment": 1000.0,
|
|
"interestRate": 3.0,
|
|
"managementRate": 1.0,
|
|
"managementFee": 1.0,
|
|
"insuranceRate": 1.0,
|
|
"insuranceFee": 100.0,
|
|
"vatRate": 7.5,
|
|
"vatAmount": 100.0,
|
|
"recommendedRepaymentDates": ["2022-11-30"],
|
|
"installmentAmount": 11000.0,
|
|
"totalRepaymentAmount": 11000.0
|
|
},
|
|
{
|
|
"offerId": "16645",
|
|
"productId": "2060",
|
|
"amount": 10000.0,
|
|
"upfrontPayment": 0.0,
|
|
"interestRate": 3.0,
|
|
"managementRate": 1.0,
|
|
"managementFee": 1.0,
|
|
"insuranceRate": 1.0,
|
|
"insuranceFee": 100.0,
|
|
"vatRate": 7.5,
|
|
"vatAmount": 100.0,
|
|
"recommendedRepaymentDates": ["2022-11-30", "2023-12-30"],
|
|
"installmentAmount": 5761.9,
|
|
"totalRepaymentAmount": 11523.8
|
|
},
|
|
{
|
|
"offerId": "122212",
|
|
"productId": "2090",
|
|
"amount": 10000.0,
|
|
"upfrontPayment": 0.0,
|
|
"interestRate": 10.0,
|
|
"managementRate": 1.0,
|
|
"managementFee": 1.0,
|
|
"insuranceRate": 1.0,
|
|
"insuranceFee": 100.0,
|
|
"vatRate": 7.5,
|
|
"vatAmount": 100.0,
|
|
"recommendedRepaymentDates": ["2022-11-30", "2022-12-30", "2023-01-29"],
|
|
"installmentAmount": 4021.15,
|
|
"totalRepaymentAmount": 12063.45
|
|
}
|
|
],
|
|
"resultCode": "00",
|
|
"resultDescription": "Successful"
|
|
}
|
|
|
|
|
|
# return ResponseHelper.success(
|
|
# data=response_data,
|
|
# message="Offer selection completed successfully"
|
|
# )
|
|
|
|
return response_data
|
|
|
|
except ValidationError as err:
|
|
logger.error(f"Validation Error: {err.messages}")
|
|
return ResponseHelper.error(
|
|
message="Invalid input data",
|
|
status_code=400,
|
|
error=err.messages
|
|
)
|
|
|
|
except Exception as e:
|
|
logger.error(f"An error occurred: {str(e)}", exc_info=True)
|
|
return ResponseHelper.error(
|
|
message="An internal error occurred",
|
|
status_code=500,
|
|
error=str(e)
|
|
)
|