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.api.integrations import SimbrellaIntegration
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.models import Offer, RACCheck
|
from app.models import Offer, RACCheck
|
||||||
|
from app.api.services.offer_analysis import OfferAnalysis
|
||||||
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
|
||||||
@@ -78,39 +80,52 @@ class EligibilityCheckService(BaseService):
|
|||||||
return jsonify({
|
return jsonify({
|
||||||
"message": "Failed to save RACCheck."
|
"message": "Failed to save RACCheck."
|
||||||
}), 400
|
}), 400
|
||||||
|
# -----------------TIME FOR ANALYSIS TO REGISTER OFFER ----------------------
|
||||||
offers = Offer.get_all_offers()
|
# eligible_offers = []
|
||||||
|
try:
|
||||||
eligible_offers = []
|
eligible_offers = OfferAnalysis.decide_offer(
|
||||||
|
transaction_id=transaction_id,
|
||||||
for offer in offers:
|
rac_check=rac_check,
|
||||||
# Determine an approved amount
|
validated_data=validated_data
|
||||||
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
|
|
||||||
)
|
)
|
||||||
|
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)
|
# eligible_offers = []
|
||||||
padded_id = str(transaction_offer.id).zfill(6)
|
|
||||||
public_offer_id = f"{offer.id}{padded_id}"
|
|
||||||
|
|
||||||
eligible_offers.append({
|
# for offer in offers:
|
||||||
"offerId": public_offer_id,
|
# # Determine an approved amount
|
||||||
"product_id": offer.product_id,
|
# random_float = random.random() # temporary to play data
|
||||||
"min_amount": offer.min_amount,
|
# approved_amount = min(offer.max_amount, offer.max_amount * random_float) #temporary for now
|
||||||
"max_amount": approved_amount,
|
# approved_amount = round(approved_amount, 2)
|
||||||
"tenor": offer.tenor
|
#
|
||||||
})
|
# 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
|
# Simulate processing
|
||||||
response_data = {
|
response_data = {
|
||||||
|
|||||||
@@ -35,3 +35,43 @@ class OfferAnalysis:
|
|||||||
|
|
||||||
|
|
||||||
return transaction_offer, offer, eligible_amount, original_transaction
|
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