[add]: Offer analysis update
This commit was merged in pull request #43.
This commit is contained in:
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user