diff --git a/app/api/schemas/collect_loan.py b/app/api/schemas/collect_loan.py index e3235a7..fa74d53 100644 --- a/app/api/schemas/collect_loan.py +++ b/app/api/schemas/collect_loan.py @@ -16,15 +16,20 @@ class CollectLoanSchema(Schema): comment = fields.Str(allow_none=True) class CollectLoanResponseSchema(Schema): - responseCode = fields.Str(allow_none=True) - responseDescr = fields.Str(allow_none=True) - fullDescription = fields.Str(allow_none=True) transactionId = fields.Str(allow_none=True) + fbnTransactionId = fields.Str(allow_none=True) debtId = fields.Str(allow_none=True) customerId = fields.Str(allow_none=True) accountId = fields.Str(allow_none=True) productId = fields.Str(allow_none=True) amountCollected = fields.Float(required=True) + interestCollected = fields.Float(required=True) + penalChargeCollected = fields.Float(required=True) + lienAmount = fields.Float(required=True) countryId = fields.Str(allow_none=True) comment = fields.Str(allow_none=True) + responseCode = fields.Str(allow_none=True) responseMessage = fields.Str(allow_none=True) + responseDescr = fields.Str(allow_none=True) + fullDescription = fields.Str(allow_none=True) + diff --git a/app/api/services/collect_loan.py b/app/api/services/collect_loan.py index 6d344a1..9525519 100644 --- a/app/api/services/collect_loan.py +++ b/app/api/services/collect_loan.py @@ -1,8 +1,10 @@ +import random 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.collect_loan import CollectLoanSchema, CollectLoanResponseSchema +from app.config import Config """ Process the CollectLoan request. @@ -24,51 +26,62 @@ class CollectLoanService: validated_data = schema.load(data) amountForCollection = validated_data.get("collectAmount") - + productId = validated_data.get("productId") + customerId = validated_data.get("customerId") amountCollected = amountForCollection responseDescr= "Loan Collection Successful EMULATOR" fullDescription= "Loan collection completed successfully EMULATOR" responseMessage= "Loan collection completed successfully EMULATOR" + interestCollected = amountForCollection * 0.03 + lienAmount = validated_data.get("lienAmount", 0) - - if amountForCollection in [5555.0, 6666.0, 7777.0, 8888.0 , 9999.0, 22222.0] : - amountCollected = amountForCollection * 0.85 + isValid = not ( + int(customerId[-1]) in [2, 7, 9] + ) + if Config.MIN_AMOUNT_FOR_COLLECTION <= amountForCollection <= Config.MAX_AMOUNT_FOR_COLLECTION: + amountCollected = amountForCollection if lienAmount >= amountForCollection else 0 responseDescr = "Partial Loan Collection Successful EMULATOR" fullDescription = "Partial Loan collection completed successfully EMULATOR" responseMessage = "Partial Loan collection completed successfully EMULATOR" - # Simulated processing logic - 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"), - "amountCollected": amountCollected, - "countryId": validated_data.get("countryId"), - "comment": validated_data.get("comment", "Testing CollectionLoanRequest EMULATOR"), - "responseCode": "00", - "responseDescr": responseDescr, - "fullDescription": fullDescription, - "responseMessage": responseMessage - } + response_data = { + "transactionId": validated_data.get("transactionId"), + "fbnTransactionId": validated_data.get("fbnTransactionId"), + "debtId": validated_data.get("debtId"), + "customerId": validated_data.get("customerId"), + "accountId": validated_data.get("accountId"), + "productId": validated_data.get("productId"), + "amountCollected": amountCollected, + "interestCollected": interestCollected, + "penalChargeCollected": 0, + "lienAmount": lienAmount if amountCollected == 0 else 0, + "countryId": validated_data.get("countryId"), + "comment": validated_data.get("comment", "Testing CollectionLoanRequest EMULATOR"), + "responseCode": "00", + "responseDescr": responseDescr, + "fullDescription": fullDescription, + "responseMessage": responseMessage + } - # # Simulated processing logic - # response_data = { - # "transactionId": validated_data.get("transactionId", "T002"), - # "debtId": validated_data.get("debtId", "273194670"), - # "customerId": validated_data.get("customerId", "CN621868"), - # "accountId": validated_data.get("accountId", "2017821799"), - # "productId": validated_data.get("productId", "101"), - # "amountCollected": validated_data.get("collectAmount", 60000.00), - # "countryId": validated_data.get("countryId", "01"), - # "comment": validated_data.get("comment", "Testing CollectionLoanRequest"), - # "responseCode": "00", - # "responseDescr": "Loan Collection Successful", - # "fullDescription": "Loan collection completed successfully", - # "responseMessage": "Loan collection completed successfully" - # } - # + else: + response_data = { + "transactionId": validated_data.get("transactionId"), + "fbnTransactionId": validated_data.get("fbnTransactionId"), + "debtId": validated_data.get("debtId"), + "customerId": validated_data.get("customerId"), + "accountId": validated_data.get("accountId"), + "productId": validated_data.get("productId"), + "amountCollected": amountCollected, + "interestCollected": interestCollected, + "penalChargeCollected": 0, + "amountCollected": amountCollected, + "countryId": validated_data.get("countryId"), + "comment": validated_data.get("comment", "Testing CollectionLoanRequest EMULATOR"), + "responseCode": "00", + "responseDescr": responseDescr, + "fullDescription": fullDescription, + "responseMessage": responseMessage + } # Validate and serialize the response data response_schema = CollectLoanResponseSchema() diff --git a/app/config.py b/app/config.py index 3587b8f..2f91bf7 100644 --- a/app/config.py +++ b/app/config.py @@ -1,4 +1,5 @@ import os +from re import M from dotenv import load_dotenv class Config: @@ -10,6 +11,8 @@ class Config: DEBUG = True VALID_APP_ID = os.getenv("VALID_APP_ID", "app1") VALID_API_KEY = os.getenv("VALID_API_KEY", "test-api-key-12345") + MIN_AMOUNT_FOR_COLLECTION = int(os.getenv("MIN_AMOUNT_FOR_COLLECTION", 10000)) + MAX_AMOUNT_FOR_COLLECTION = int(os.getenv("MAX_AMOUNT_FOR_COLLECTION", 25000)) # SQLALCHEMY_DATABASE_URI =os.environ.get("DATABASE_URL", "database_url") # SQLALCHEMY_TRACK_MODIFICATIONS = False