Moved offer decide
This commit is contained in:
@@ -8,6 +8,8 @@ from app.api.enums import TransactionType
|
||||
from app.api.integrations import SimbrellaIntegration
|
||||
from app.extensions import db
|
||||
from app.models import Offer, RACCheck
|
||||
from app.api.services.offer_analysis import OfferAnalysis
|
||||
|
||||
import random
|
||||
|
||||
|
||||
@@ -78,39 +80,52 @@ class EligibilityCheckService(BaseService):
|
||||
return jsonify({
|
||||
"message": "Failed to save RACCheck."
|
||||
}), 400
|
||||
|
||||
offers = Offer.get_all_offers()
|
||||
|
||||
eligible_offers = []
|
||||
|
||||
for offer in offers:
|
||||
# Determine an approved amount
|
||||
random_float = random.random() # temporary to play data
|
||||
approved_amount = min(offer.max_amount, offer.max_amount * random_float) #temporary for now
|
||||
approved_amount = round(approved_amount, 2)
|
||||
|
||||
transaction_offer = TransactionOffer.create_transaction_offer(
|
||||
customer_id = customer.id,
|
||||
transaction_id = transaction.transaction_id,
|
||||
offer_id = offer.id,
|
||||
min_amount = offer.min_amount,
|
||||
max_amount = offer.max_amount,
|
||||
eligible_amount = approved_amount,
|
||||
product_id = offer.product_id,
|
||||
tenor = offer.tenor
|
||||
# -----------------TIME FOR ANALYSIS TO REGISTER OFFER ----------------------
|
||||
# eligible_offers = []
|
||||
try:
|
||||
eligible_offers = OfferAnalysis.decide_offer(
|
||||
transaction_id=transaction_id,
|
||||
rac_check=rac_check,
|
||||
validated_data=validated_data
|
||||
)
|
||||
except ValueError as ve:
|
||||
logger.error(str(ve))
|
||||
return jsonify({
|
||||
"message": str(ve)
|
||||
}), 400
|
||||
# -----------------------------------------------------------------------
|
||||
# s = Offer.get_all_offers()
|
||||
|
||||
# Visible offer ID: offer_id + padded(transaction_offer.id)
|
||||
padded_id = str(transaction_offer.id).zfill(6)
|
||||
public_offer_id = f"{offer.id}{padded_id}"
|
||||
# eligible_offers = []
|
||||
|
||||
eligible_offers.append({
|
||||
"offerId": public_offer_id,
|
||||
"product_id": offer.product_id,
|
||||
"min_amount": offer.min_amount,
|
||||
"max_amount": approved_amount,
|
||||
"tenor": offer.tenor
|
||||
})
|
||||
# for offer in offers:
|
||||
# # Determine an approved amount
|
||||
# random_float = random.random() # temporary to play data
|
||||
# approved_amount = min(offer.max_amount, offer.max_amount * random_float) #temporary for now
|
||||
# approved_amount = round(approved_amount, 2)
|
||||
#
|
||||
# transaction_offer = TransactionOffer.create_transaction_offer(
|
||||
# customer_id = customer.id,
|
||||
# transaction_id = transaction.transaction_id,
|
||||
# offer_id = offer.id,
|
||||
# min_amount = offer.min_amount,
|
||||
# max_amount = offer.max_amount,
|
||||
# eligible_amount = approved_amount,
|
||||
# product_id = offer.product_id,
|
||||
# tenor = offer.tenor
|
||||
# )
|
||||
#
|
||||
# # Visible offer ID: offer_id + padded(transaction_offer.id)
|
||||
# padded_id = str(transaction_offer.id).zfill(6)
|
||||
# public_offer_id = f"{offer.id}{padded_id}"
|
||||
#
|
||||
# eligible_offers.append({
|
||||
# "offerId": public_offer_id,
|
||||
# "product_id": offer.product_id,
|
||||
# "min_amount": offer.min_amount,
|
||||
# "max_amount": approved_amount,
|
||||
# "tenor": offer.tenor
|
||||
# })
|
||||
|
||||
# Simulate processing
|
||||
response_data = {
|
||||
|
||||
@@ -35,3 +35,43 @@ class OfferAnalysis:
|
||||
|
||||
|
||||
return transaction_offer, offer, eligible_amount, original_transaction
|
||||
|
||||
@staticmethod
|
||||
def decide_offer(transaction_id, rac_check, validated_data):
|
||||
# if we have active offers - we have to feed off it
|
||||
|
||||
|
||||
|
||||
# Do this if no active loan or registered offers
|
||||
offers = Offer.get_all_offers()
|
||||
eligible_offers = []
|
||||
for offer in offers:
|
||||
# Determine an approved amount
|
||||
random_float = random.random() # temporary to play data
|
||||
approved_amount = min(offer.max_amount, offer.max_amount * random_float) # temporary for now
|
||||
approved_amount = round(approved_amount, 2)
|
||||
|
||||
transaction_offer = TransactionOffer.create_transaction_offer(
|
||||
customer_id=customer.id,
|
||||
transaction_id=transaction.transaction_id,
|
||||
offer_id=offer.id,
|
||||
min_amount=offer.min_amount,
|
||||
max_amount=offer.max_amount,
|
||||
eligible_amount=approved_amount,
|
||||
product_id=offer.product_id,
|
||||
tenor=offer.tenor
|
||||
)
|
||||
|
||||
# Visible offer ID: offer_id + padded(transaction_offer.id)
|
||||
padded_id = str(transaction_offer.id).zfill(6)
|
||||
public_offer_id = f"{offer.id}{padded_id}"
|
||||
|
||||
eligible_offers.append({
|
||||
"offerId": public_offer_id,
|
||||
"product_id": offer.product_id,
|
||||
"min_amount": offer.min_amount,
|
||||
"max_amount": approved_amount,
|
||||
"tenor": offer.tenor
|
||||
})
|
||||
|
||||
return eligible_offers
|
||||
Reference in New Issue
Block a user