[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,
|
"customerId": customer_id,
|
||||||
"accountId": account_id,
|
"accountId": account_id,
|
||||||
"transactionId": str(transaction_id),
|
"transactionId": str(transaction_id),
|
||||||
"fbnTransactionId": f"FBN{transaction_id}",
|
"fbnTransactionId": str(transaction_id),
|
||||||
"countryCode": "NG",
|
"countryCode": "NG",
|
||||||
"channel": "USSD"
|
"channel": "USSD"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,14 +74,14 @@ class EligibilityCheckService(BaseService):
|
|||||||
logger.info(f"This is Response (from Eligibility Check): {str(response)}", exc_info=True)
|
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:
|
if response:
|
||||||
logger.error(f"{response}")
|
logger.error(f"{response['responseMessage']}")
|
||||||
|
|
||||||
return ResponseHelper.error(result_description=f"RACCheck failed")
|
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(
|
rac_check = RACCheck.add_rac_check(
|
||||||
customer_id = customer_id,
|
customer_id = customer_id,
|
||||||
|
|||||||
@@ -70,11 +70,17 @@ class OfferAnalysis:
|
|||||||
# Salary rules
|
# Salary rules
|
||||||
for key in RAC_SALARY_PAYMENTS:
|
for key in RAC_SALARY_PAYMENTS:
|
||||||
value = rack_response.get(key)
|
value = rack_response.get(key)
|
||||||
|
|
||||||
|
|
||||||
if isinstance(value, Decimal):
|
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)):
|
elif isinstance(value, (int, float, str)):
|
||||||
try:
|
try:
|
||||||
salaries.append(Decimal(str(value)))
|
value = Decimal(str(value))
|
||||||
|
if value > 0:
|
||||||
|
salaries.append(value)
|
||||||
except:
|
except:
|
||||||
logger.warning(f"Could not convert value of {key} to Decimal: {value}")
|
logger.warning(f"Could not convert value of {key} to Decimal: {value}")
|
||||||
|
|
||||||
@@ -93,18 +99,21 @@ class OfferAnalysis:
|
|||||||
min_salary = min(salaries)
|
min_salary = min(salaries)
|
||||||
|
|
||||||
# Check consistency rule
|
# 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
|
# Determine percentage based on offer tenor
|
||||||
tenure = getattr(offer, "tenure", 30)
|
tenor = offer.tenor
|
||||||
if tenure == 30:
|
|
||||||
|
if tenor == 30 and consistent_income:
|
||||||
eligible_amount = min_salary * Decimal("0.5")
|
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 tenure == 90 and consistent_income:
|
elif tenor == 90 and consistent_income:
|
||||||
eligible_amount = min_salary * Decimal("0.75")
|
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
|
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.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -209,6 +218,11 @@ class OfferAnalysis:
|
|||||||
approved_amount = new_eligible_amount
|
approved_amount = new_eligible_amount
|
||||||
approved_amount = round(approved_amount, 2)
|
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(
|
transaction_offer = TransactionOffer.create_transaction_offer(
|
||||||
customer_id=customer_id,
|
customer_id=customer_id,
|
||||||
transaction_id=transaction_id,
|
transaction_id=transaction_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user