From 6ef2be96259fd99d6b0de09916d3314b144e25ce Mon Sep 17 00:00:00 2001 From: VivianDee <115420678+VivianDee@users.noreply.github.com> Date: Thu, 12 Jun 2025 15:24:14 +0100 Subject: [PATCH] [add]: Offer analysis update --- app/api/integrations/simbrella.py | 2 +- app/api/services/eligibility_check.py | 6 ++--- app/api/services/offer_analysis.py | 34 +++++++++++++++++++-------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/app/api/integrations/simbrella.py b/app/api/integrations/simbrella.py index b9c3e75..3455aef 100644 --- a/app/api/integrations/simbrella.py +++ b/app/api/integrations/simbrella.py @@ -21,7 +21,7 @@ class SimbrellaIntegration: "customerId": customer_id, "accountId": account_id, "transactionId": str(transaction_id), - "fbnTransactionId": f"FBN{transaction_id}", + "fbnTransactionId": str(transaction_id), "countryCode": "NG", "channel": "USSD" } diff --git a/app/api/services/eligibility_check.py b/app/api/services/eligibility_check.py index b92cbd6..5670e1c 100644 --- a/app/api/services/eligibility_check.py +++ b/app/api/services/eligibility_check.py @@ -74,14 +74,14 @@ class EligibilityCheckService(BaseService): logger.info(f"This is Response (from Eligibility Check): {str(response)}", exc_info=True) - if not response: + if not response or response['responseCode'] != '00': if response: - logger.error(f"{response}") + logger.error(f"{response['responseMessage']}") return ResponseHelper.error(result_description=f"RACCheck failed") - rack_checks_response = response['racResponse'] + rack_checks_response = response['data']['racResponse'] rac_check = RACCheck.add_rac_check( customer_id = customer_id, diff --git a/app/api/services/offer_analysis.py b/app/api/services/offer_analysis.py index 750af01..77d0533 100644 --- a/app/api/services/offer_analysis.py +++ b/app/api/services/offer_analysis.py @@ -70,11 +70,17 @@ class OfferAnalysis: # Salary rules for key in RAC_SALARY_PAYMENTS: value = rack_response.get(key) + + if isinstance(value, Decimal): - salaries.append(value) + # Only use values greater than 0 + if value > 0: + salaries.append(value) elif isinstance(value, (int, float, str)): try: - salaries.append(Decimal(str(value))) + value = Decimal(str(value)) + if value > 0: + salaries.append(value) except: logger.warning(f"Could not convert value of {key} to Decimal: {value}") @@ -93,23 +99,26 @@ class OfferAnalysis: min_salary = min(salaries) # Check consistency rule - consistent_income = rack_response.get("rule7-consistent-salary-amount", False) + consistent_income = rack_response.get("rule7_consistent_salary_amount", False) - # Determine percentage based on offer tenure - tenure = getattr(offer, "tenure", 30) - if tenure == 30: + # Determine percentage based on offer tenor + tenor = offer.tenor + + if tenor == 30 and consistent_income: eligible_amount = min_salary * Decimal("0.5") - - elif tenure == 90 and consistent_income: + logger.info("Applying 50% of least salary in 6 months due to 1-month offer tenor with stable income.") + elif tenor == 90 and consistent_income: eligible_amount = min_salary * Decimal("0.75") + logger.info("Applying 75% of least salary in 6 months due to 3-months offer tenor with stable income.") else: # Income is not consistent - eligible_amount = min_salary * Decimal("0.5") + eligible_amount = 0 + logger.info("Applying np percentage on least salary due unstable income.") logger.info(f"Calculated eligible amount from RAC: {eligible_amount} based on {'stable' if consistent_income else 'unstable'} income.") - + return eligible_amount.quantize(Decimal("1.00")) # "racResponse": { @@ -209,6 +218,11 @@ class OfferAnalysis: approved_amount = new_eligible_amount approved_amount = round(approved_amount, 2) + if approved_amount < offer.min_amount: + logger.error(f"Max eligible amount ({approved_amount}) is less than the minimum offer amount ({offer.min_amount}).") + raise ValueError("You are not eligible for a loan at this time.") + + transaction_offer = TransactionOffer.create_transaction_offer( customer_id=customer_id, transaction_id=transaction_id, -- 2.34.1