Merge branch 'master' of https://gitlab.chiefsoft.net/DigiFi/digifi-BankToProductCore
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -123,6 +123,7 @@ class BaseService:
|
||||
|
||||
return {
|
||||
"interest": interest,
|
||||
"interest_amount": interest_amount,
|
||||
"management": management,
|
||||
"insurance": insurance,
|
||||
"vat": vat,
|
||||
|
||||
@@ -7,7 +7,7 @@ from marshmallow import ValidationError
|
||||
from app.api.enums import TransactionType
|
||||
from app.api.integrations import SimbrellaIntegration
|
||||
from app.extensions import db
|
||||
from app.models import Offer
|
||||
from app.models import Offer, RACCheck
|
||||
import random
|
||||
|
||||
|
||||
@@ -57,12 +57,27 @@ class EligibilityCheckService(BaseService):
|
||||
response = SimbrellaIntegration.rac_check(
|
||||
customer_id = customer_id,
|
||||
account_id = account_id,
|
||||
transaction_id = transaction.id,
|
||||
transaction_id = transaction.transaction_id,
|
||||
)
|
||||
|
||||
# this chck for error is not valid
|
||||
if response.status_code != 200:
|
||||
return jsonify({"message": "RACCheck failed"}), 400
|
||||
|
||||
response = response.json()
|
||||
|
||||
rac_check = RACCheck.add_rac_check(
|
||||
customer_id = customer_id,
|
||||
account_id = account_id,
|
||||
transaction_id = transaction.transaction_id,
|
||||
data = response['RACResponse']
|
||||
)
|
||||
|
||||
if not rac_check:
|
||||
logger.error(f"Failed to save RACCheck")
|
||||
return jsonify({
|
||||
"message": "Failed to save RACCheck."
|
||||
}), 400
|
||||
|
||||
offers = Offer.get_all_offers()
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
from app.models import Offer, TransactionOffer
|
||||
from app.models.loan import Loan
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
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
|
||||
|
||||
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:
|
||||
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.")
|
||||
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, original_transaction
|
||||
@@ -8,13 +8,13 @@ from app.models.loan_charge import LoanCharge
|
||||
from app.utils.logger import logger
|
||||
from app.api.schemas.provide_loan import ProvideLoanSchema
|
||||
from threading import Thread
|
||||
from app.models import Loan, Offer, Charge , TransactionOffer
|
||||
from app.models import Loan, Offer, Charge , TransactionOffer, RACCheck
|
||||
from app.api.enums import LoanStatus
|
||||
from app.extensions import db
|
||||
from datetime import datetime, timezone
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from app.models import LoanRepaymentSchedule
|
||||
|
||||
from app.api.services.offer_analysis import OfferAnalysis
|
||||
|
||||
class ProvideLoanService(BaseService):
|
||||
TRANSACTION_TYPE = TransactionType.PROVIDE_LOAN
|
||||
@@ -45,25 +45,40 @@ class ProvideLoanService(BaseService):
|
||||
|
||||
customer = Customer.is_valid_customer(customer_id)
|
||||
|
||||
if (ProvideLoanService.validate_account_ownership(account_id = account_id, customer_id = 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
|
||||
rac_response = RACCheck.get_rac_check(customer_id = customer_id, account_id = account_id)
|
||||
|
||||
transaction_offer = TransactionOffer.is_valid_transaction_offer(transaction_offer_id)
|
||||
if not transaction_offer:
|
||||
logger.error(f"Invalid Transaction Offer")
|
||||
try:
|
||||
transaction_offer, offer, eligible_amount, original_transaction = OfferAnalysis.get_offer(
|
||||
transaction_id=transaction_id,
|
||||
rac_response=rac_response,
|
||||
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
|
||||
@@ -102,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,
|
||||
@@ -131,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
|
||||
|
||||
|
||||
@@ -32,10 +32,14 @@ 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
|
||||
|
||||
#"offerId": "SAL30001129",
|
||||
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user