diff --git a/app/api/services/offer_analysis.py b/app/api/services/offer_analysis.py index 5b57b85..01469c1 100644 --- a/app/api/services/offer_analysis.py +++ b/app/api/services/offer_analysis.py @@ -63,6 +63,10 @@ class OfferAnalysis: logger.info(f"sum_active_loans === > {sum_active_loans}") real_eligible_amount = original_loan.eligible_amount - sum_active_loans + if real_eligible_amount < original_transaction_offer.min_amount: + logger.error(f"Max eligible amount ({real_eligible_amount}) is less than the minimum offer amount ({original_transaction_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, diff --git a/app/api/services/provide_loan.py b/app/api/services/provide_loan.py index 9aff9f0..9f8abfd 100644 --- a/app/api/services/provide_loan.py +++ b/app/api/services/provide_loan.py @@ -60,6 +60,10 @@ class ProvideLoanService(BaseService): except ValueError as ve: logger.error(str(ve)) return ResponseHelper.error(result_description=str(ve)) + + + if(amount < transaction_offer.min_amount): + return ResponseHelper.error(result_description="The amount is less than the minimum allowed transaction amount.") # transaction_offer_id = int(offer_id[5:]) # The last part is int diff --git a/app/api/services/select_offer.py b/app/api/services/select_offer.py index 67c174f..dc8f912 100644 --- a/app/api/services/select_offer.py +++ b/app/api/services/select_offer.py @@ -59,6 +59,10 @@ class SelectOfferService(BaseService): db.session.flush() + if(amount < offer.min_amount): + return ResponseHelper.error(result_description="The amount is less than the minimum allowed offer amount.") + + charges = SelectOfferService.calculate_charges(offer, amount) upfront_payment = charges["upfront_payment"] total_amount = charges["total_amount"]