[add]: Offer analysis
This commit is contained in:
@@ -6,3 +6,4 @@ from app.api.services.repayment import RepaymentService
|
||||
from app.api.services.customer_consent import CustomerConsentService
|
||||
from app.api.services.notification_callback import NotificationCallbackService
|
||||
from app.api.services.authorization import AuthorizationService
|
||||
from app.api.services.offer_analysis import OfferAnalysis
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
from app.models import Offer, TransactionOffer
|
||||
|
||||
class OfferAnalysis:
|
||||
|
||||
@staticmethod
|
||||
def get_offer(transaction_id, rac_response, validated_data):
|
||||
customer_id = validated_data.get("customerId")
|
||||
product_id = validated_data.get("productId")
|
||||
offer_id = validated_data.get("offerId")
|
||||
|
||||
transaction_offer_id = int(offer_id[5:]) # The last part is int
|
||||
|
||||
transaction_offer = TransactionOffer.is_valid_transaction_offer(transaction_offer_id, customer_id, product_id)
|
||||
|
||||
if not transaction_offer:
|
||||
raise ValueError("Invalid Transaction Offer.")
|
||||
|
||||
eligible_amount = transaction_offer.eligible_amount
|
||||
offer = Offer.is_valid_offer( transaction_offer.offer_id)
|
||||
|
||||
if not offer:
|
||||
raise ValueError("Invalid Offer.")
|
||||
|
||||
return transaction_offer, offer, eligible_amount
|
||||
@@ -14,6 +14,7 @@ from app.extensions import db
|
||||
from datetime import datetime, timezone
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from app.models import LoanRepaymentSchedule
|
||||
from app.api.services import OfferAnalysis
|
||||
|
||||
|
||||
class ProvideLoanService(BaseService):
|
||||
@@ -45,25 +46,37 @@ class ProvideLoanService(BaseService):
|
||||
|
||||
customer = Customer.is_valid_customer(customer_id)
|
||||
|
||||
if (ProvideLoanService.validate_account_ownership(account_id = account_id, customer_id = customer_id)):
|
||||
|
||||
transaction_offer_id = int(offer_id[5:]) # The last part is int
|
||||
|
||||
transaction_offer = TransactionOffer.is_valid_transaction_offer(transaction_offer_id)
|
||||
if not transaction_offer:
|
||||
logger.error(f"Invalid Transaction Offer")
|
||||
if (ProvideLoanService.validate_account_ownership(account_id = account_id, customer_id = customer_id)):
|
||||
try:
|
||||
transaction_offer, offer, eligible_amount = OfferAnalysis.get_offer(
|
||||
transaction_id=transaction_id,
|
||||
rac_response=None,
|
||||
validated_data=validated_data
|
||||
)
|
||||
except ValueError as ve:
|
||||
logger.error(str(ve))
|
||||
return jsonify({
|
||||
"message": "Invalid Transaction Offer."
|
||||
"message": str(ve)
|
||||
}), 400
|
||||
|
||||
# transaction_offer_id = int(offer_id[5:]) # The last part is int
|
||||
|
||||
eligible_amount = transaction_offer.eligible_amount
|
||||
offer = Offer.is_valid_offer( transaction_offer.offer_id)
|
||||
# transaction_offer = TransactionOffer.is_valid_transaction_offer(transaction_offer_id)
|
||||
|
||||
# if not transaction_offer:
|
||||
# logger.error(f"Invalid Transaction Offer")
|
||||
# return jsonify({
|
||||
# "message": "Invalid Transaction Offer."
|
||||
# }), 400
|
||||
|
||||
if not offer:
|
||||
logger.error(f"Invalid Offer")
|
||||
return jsonify({
|
||||
"message": "Invalid Offer."
|
||||
}), 400
|
||||
# eligible_amount = transaction_offer.eligible_amount
|
||||
# offer = Offer.is_valid_offer( transaction_offer.offer_id)
|
||||
|
||||
# if not offer:
|
||||
# logger.error(f"Invalid Offer")
|
||||
# return jsonify({
|
||||
# "message": "Invalid Offer."
|
||||
# }), 400
|
||||
|
||||
# Log Transaction
|
||||
transaction = ProvideLoanService.log_transaction(validated_data=validated_data)
|
||||
|
||||
@@ -26,8 +26,13 @@ class TransactionOffer(db.Model):
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def is_valid_transaction_offer(cls, offer_id):
|
||||
transaction_offer = cls.query.filter_by(id=str(offer_id)).first()
|
||||
def is_valid_transaction_offer(cls, offer_id, customer_id, product_id):
|
||||
transaction_offer = cls.query.filter_by(
|
||||
id = str(offer_id),
|
||||
customer_id = customer_id,
|
||||
product_id = product_id
|
||||
# transaction_id = transaction_id,
|
||||
).first()
|
||||
|
||||
if not transaction_offer:
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user