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 5b8c57e..5670e1c 100644 --- a/app/api/services/eligibility_check.py +++ b/app/api/services/eligibility_check.py @@ -81,7 +81,7 @@ class EligibilityCheckService(BaseService): 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 11ec0a1..77d0533 100644 --- a/app/api/services/offer_analysis.py +++ b/app/api/services/offer_analysis.py @@ -67,14 +67,20 @@ class OfferAnalysis: failed_false_rules.append(rule) - # Expects false + # 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,15 +99,28 @@ 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 tenor + tenor = offer.tenor + + if tenor == 30 and consistent_income: + eligible_amount = min_salary * Decimal("0.5") + 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 = 0 + logger.info("Applying np percentage on least salary due unstable income.") + - if consistent_income: - eligible_amount = min_salary * Decimal("0.5") - else: - eligible_amount = min_salary * Decimal("0.75") 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": { # "accountStatus": true, # "bvnValidated": true, @@ -199,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,