Compare commits

...

12 Commits

Author SHA1 Message Date
VivianDee dc21f41894 [add]: transaction offer fix 2025-05-10 10:04:06 +01:00
VivianDee 17db2cf8f9 Merge branch 'master' of https://gitlab.chiefsoft.net/DigiFi/digifi-BankToProductCore 2025-05-10 08:53:09 +01:00
VivianDee f07866a884 [add]: transaction fix 2025-05-10 08:50:10 +01:00
CHIEFSOFT\ameye 6f8e269a50 clean up active loans 2025-05-09 23:20:05 -04:00
CHIEFSOFT\ameye 4435ca2776 original transaction id 2025-05-09 23:14:08 -04:00
CHIEFSOFT\ameye d851222024 Removed product id 2025-05-09 19:13:51 -04:00
CHIEFSOFT\ameye 52ab33f260 Logger 2025-05-09 19:10:32 -04:00
CHIEFSOFT\ameye af7e0f8624 Loggers 2025-05-09 19:07:43 -04:00
CHIEFSOFT\ameye c8ab2cd6ba transaction_offer_id 2025-05-09 18:58:27 -04:00
CHIEFSOFT\ameye 8ac22fa95f Offer id and interest amount 2025-05-09 18:52:25 -04:00
CHIEFSOFT\ameye 57207faf6f Intereat amount on sawagger 2025-05-09 18:42:19 -04:00
ameye 9a90609d33 Merge branch 'fix_loan_due_date' of DigiFi/digifi-BankToProductCore into master 2025-05-07 21:33:05 +00:00
8 changed files with 63 additions and 13 deletions
+2 -2
View File
@@ -35,7 +35,7 @@ class SimbrellaIntegration:
],
}
logger.error(f"This is PayLoad: {str(payload)}", exc_info=True)
logger.info(f"This is PayLoad: {str(payload)}", exc_info=True)
headers = {
"Content-Type": "application/json",
@@ -46,7 +46,7 @@ class SimbrellaIntegration:
try:
response = httpx.post(url, json=payload, headers=headers, timeout=10.0)
logger.error(f"This is Response: {str(response)}", exc_info=True)
logger.info(f"This is Response: {str(response)}", exc_info=True)
return response
+1
View File
@@ -123,6 +123,7 @@ class BaseService:
return {
"interest": interest,
"interest_amount": interest_amount,
"management": management,
"insurance": insurance,
"vat": vat,
+14 -1
View File
@@ -1,4 +1,8 @@
from app.models import Offer, TransactionOffer
from app.models.loan import Loan
import logging
logger = logging.getLogger(__name__)
class OfferAnalysis:
@@ -10,6 +14,11 @@ class OfferAnalysis:
transaction_offer_id = int(offer_id[5:]) # The last part is int
logger.info(f"customer_id == *************** : {customer_id}")
logger.info(f"product_id == *************** : {product_id}")
logger.info(f"offer_id == *************** : {offer_id}")
logger.info(f"transaction_offer_id == *************** : {transaction_offer_id}")
transaction_offer = TransactionOffer.is_valid_transaction_offer(transaction_offer_id, customer_id, product_id)
if not transaction_offer:
@@ -20,5 +29,9 @@ class OfferAnalysis:
if not offer:
raise ValueError("Invalid Offer.")
original_transaction = transaction_id
# we can now find the origin transactions
customer_loan = Loan.get_customer_current_active_loan(customer_id)
return transaction_offer, offer, eligible_amount
return transaction_offer, offer, eligible_amount, original_transaction
+4 -2
View File
@@ -50,7 +50,7 @@ class ProvideLoanService(BaseService):
rac_response = RACCheck.get_rac_check(customer_id = customer_id, account_id = account_id)
try:
transaction_offer, offer, eligible_amount = OfferAnalysis.get_offer(
transaction_offer, offer, eligible_amount, original_transaction = OfferAnalysis.get_offer(
transaction_id=transaction_id,
rac_response=rac_response,
validated_data=validated_data
@@ -80,6 +80,7 @@ class ProvideLoanService(BaseService):
# "message": "Invalid Offer."
# }), 400
# Log Transaction
transaction = ProvideLoanService.log_transaction(validated_data=validated_data)
@@ -116,6 +117,7 @@ class ProvideLoanService(BaseService):
product_id = offer.product_id,
collection_type = collection_type,
transaction_id = validated_data.get('transactionId'),
original_transaction = validated_data.get('transactionId'),
initial_loan_amount = validated_data.get('requestedAmount'),
upfront_fee = upfront_fee,
repayment_amount = repayment_amount,
@@ -145,7 +147,7 @@ class ProvideLoanService(BaseService):
# charges = Charge.get_offer_charges(offer.id)
logger.error(f"{charges}")
logger.info(f"{charges}")
loan_id = loan.id
+8 -2
View File
@@ -32,9 +32,13 @@ class SelectOfferService(BaseService):
customer_id = validated_data.get("customerId")
amount = validated_data.get("requestedAmount")
product_id = validated_data.get("productId")
offer_id = validated_data.get("offerId")
transaction_offer_id = validated_data.get("offerId")
transaction_id = validated_data.get("transactionId")
request_id = validated_data.get("requestId")
offer_id = int(transaction_offer_id[5:]) # The last part is int
if SelectOfferService.validate_account_ownership(
account_id=account_id, customer_id=customer_id
@@ -63,6 +67,7 @@ class SelectOfferService(BaseService):
insurance = charges["insurance"]
vat = charges["vat"]
repayment_amount = charges["repayment_amount"]
interest_amount = charges["interest_amount"]
# Calculate the repayment dates
@@ -81,11 +86,12 @@ class SelectOfferService(BaseService):
offers = [
{
"offerId": offer.id,
"offerId": transaction_offer_id,
"productId": product_id,
"amount": amount,
"upfrontPayment": upfront_payment,
"interestRate": offer.interest_rate,
"interestAmount": interest_amount,
"managementRate": offer.management_rate,
"managementFee": management["fee"],
"insuranceRate": offer.insurance_rate,
+25 -3
View File
@@ -6,6 +6,8 @@ from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm import relationship
from dateutil.relativedelta import relativedelta
from datetime import timedelta
import logging
logger = logging.getLogger(__name__)
class Loan(db.Model):
@@ -69,6 +71,7 @@ class Loan(db.Model):
initial_loan_amount,
collection_type,
transaction_id,
original_transaction,
upfront_fee,
repayment_amount,
installment_amount,
@@ -92,7 +95,7 @@ class Loan(db.Model):
product_id = product_id,
collection_type = collection_type,
transaction_id = transaction_id,
original_transaction = transaction_id,
original_transaction = original_transaction,
initial_loan_amount = initial_loan_amount,
current_loan_amount = initial_loan_amount,
upfront_fee = upfront_fee,
@@ -125,13 +128,32 @@ class Loan(db.Model):
@classmethod
def get_customer_loan(cls, loan_id, customer_id):
"""
Get customer's active loans.
Get customer's active loans by loan_id.
"""
loan = cls.query.filter_by(id = loan_id, customer_id = customer_id).first()
if not loan:
raise ValueError(f"Loan with ID {loan_id} does not exist or does not belong to customer {customer_id}.")
return loan
@classmethod
def get_customer_current_active_loan(cls, customer_id):
"""
Get customer's active loans.
"""
loan = cls.query.filter_by( customer_id = customer_id).first()
if not loan:
loan = {
"eligible_amount": 0,
"loan_amount": 0,
"customer_id": customer_id,
"transaction_id": "",
"resultDescription": "No Active Loan"
}
logger.info(f" Active Loan ==>>>> {loan}")
return loan
@classmethod
def update_status(cls, loan_id, status):
"""
+4 -3
View File
@@ -26,14 +26,15 @@ class TransactionOffer(db.Model):
)
@classmethod
def is_valid_transaction_offer(cls, offer_id, customer_id, product_id):
def is_valid_transaction_offer(cls, transaction_offer_id, customer_id, product_id):
transaction_offer = cls.query.filter_by(
id = str(offer_id),
id = transaction_offer_id,
customer_id = customer_id,
product_id = product_id
# product_id = product_id
# transaction_id = transaction_id,
).first()
if not transaction_offer:
return False
return transaction_offer
@@ -49,6 +49,11 @@
"format": "float",
"example": 3.0
},
"interestAmount": {
"type": "number",
"format": "float",
"example": 3000.00
},
"ManagementRate": {
"type": "number",
"format": "float",