[update]: Eligibility check

This commit was merged in pull request #21.
This commit is contained in:
VivianDee
2025-04-29 08:26:41 +01:00
parent 0fbdebceb3
commit 92eadbfa16
5 changed files with 148 additions and 3 deletions
+32 -2
View File
@@ -1,4 +1,5 @@
from flask import session, jsonify
from app.models.transaction_offers import TransactionOffer
from app.utils.logger import logger
from app.api.services.base_service import BaseService
from app.api.schemas.eligibility_check import EligibilityCheckSchema
@@ -61,7 +62,36 @@ class EligibilityCheckService(BaseService):
if response.status_code != 200:
return jsonify({"message": "RACCheck failed"}), 400
offers = [offer.to_dict() for offer in Offer.get_all_offers()]
offers = Offer.get_all_offers()
eligible_offers = []
for offer in offers:
# Determine an approved amount
approved_amount = min(offer.max_amount, 5000)
transaction_offer = TransactionOffer.create_transaction_offer(
customer_id = customer.id,
transaction_id = 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 = {
@@ -69,7 +99,7 @@ class EligibilityCheckService(BaseService):
"transactionId": transactionId,
"countryCode": "NG",
"msisdn": msisdn,
"eligibleOffers": offers,
"eligibleOffers": eligible_offers,
"resultDescription": "Successful",
"resultCode": "00",
"accountId": account_id