1
0

[add]: offer analysis

This commit is contained in:
VivianDee
2025-05-06 07:09:36 +01:00
parent 4c4ef909c2
commit 74066bae56
3 changed files with 41 additions and 10 deletions
+9 -2
View File
@@ -7,7 +7,7 @@ from marshmallow import ValidationError
from app.api.enums import TransactionType
from app.api.integrations import SimbrellaIntegration
from app.extensions import db
from app.models import Offer
from app.models import Offer, RACCheck
import random
@@ -57,12 +57,19 @@ class EligibilityCheckService(BaseService):
response = SimbrellaIntegration.rac_check(
customer_id = customer_id,
account_id = account_id,
transaction_id = transaction.id,
transaction_id = transaction.transaction_id,
)
# this chck for error is not valid
if response.status_code != 200:
return jsonify({"message": "RACCheck failed"}), 400
RACCheck.add_rac_check(
customer_id = customer_id,
account_id = account_id,
transaction_id = transaction.transaction_id,
data = response.data
)
offers = Offer.get_all_offers()
+6 -3
View File
@@ -8,7 +8,7 @@ from app.models.loan_charge import LoanCharge
from app.utils.logger import logger
from app.api.schemas.provide_loan import ProvideLoanSchema
from threading import Thread
from app.models import Loan, Offer, Charge , TransactionOffer
from app.models import Loan, Offer, Charge , TransactionOffer, RACCheck
from app.api.enums import LoanStatus
from app.extensions import db
from datetime import datetime, timezone
@@ -46,11 +46,14 @@ class ProvideLoanService(BaseService):
customer = Customer.is_valid_customer(customer_id)
if (ProvideLoanService.validate_account_ownership(account_id = account_id, customer_id = customer_id)):
if (ProvideLoanService.validate_account_ownership(account_id = account_id, customer_id = customer_id)):
rac_response = RACCheck.get_rac_check(customer_id = customer_id, account_id = account_id)
try:
transaction_offer, offer, eligible_amount = OfferAnalysis.get_offer(
transaction_id=transaction_id,
rac_response=None,
rac_response=rac_response,
validated_data=validated_data
)
except ValueError as ve:
+26 -5
View File
@@ -1,7 +1,7 @@
from datetime import datetime, timezone
from app.extensions import db
from sqlalchemy.orm import relationship
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.exc import IntegrityError
from uuid import uuid4
from sqlalchemy.types import JSON
@@ -16,6 +16,26 @@ class RACCheck(db.Model):
created_at = db.Column(db.DateTime, default=datetime.now(timezone.utc))
updated_at = db.Column(db.DateTime, default=datetime.now(timezone.utc), onupdate=datetime.now(timezone.utc))
@classmethod
def add_rac_check(cls, customer_id, account_id, transaction_id, data = None):
# Save the response
rac_check = cls(
customer_id = customer_id,
account_id = account_id,
transaction_id = transaction_id,
original_transaction = transaction_id,
rac_response = data
)
try:
db.session.add(rac_check)
except IntegrityError as err:
raise ValueError(f"Database integrity error: {err}")
return rac_check
@classmethod
def get_all_rac_checks(cls):
"""
@@ -24,18 +44,19 @@ class RACCheck(db.Model):
rac_checks = cls.query.all()
if not rac_checks:
raise ValueError("No available RAC checks")
return None
return rac_checks
@classmethod
def get_rac_check_by_id(cls, check_id):
def get_rac_check(cls, customer_id, account_id):
"""
Return a RAC check by its ID.
"""
rac_check = cls.query.filter_by(id=check_id).first()
rac_check = cls.query.filter_by( customer_id = customer_id,
account_id = account_id,).first()
if not rac_check:
raise ValueError(f"RAC Check with ID {check_id} not found")
raise ValueError(f"RAC Check for customer not found")
return rac_check
def to_dict(self):