Merge branch 'test' of DigiFi/digifi-EventManager into master
This commit is contained in:
@@ -53,6 +53,7 @@ class SimbrellaClient:
|
|||||||
# let us set disbursement date
|
# let us set disbursement date
|
||||||
LoanService.set_disbursement_date(loan_data['debtId'], loan_data['customerId']) # toda this must return something
|
LoanService.set_disbursement_date(loan_data['debtId'], loan_data['customerId']) # toda this must return something
|
||||||
logger.info(f"Here are your cal 000 : *********************************************************")
|
logger.info(f"Here are your cal 000 : *********************************************************")
|
||||||
|
logger.info(f"Here is your loan data after setting disbursement date: {loan_data}")
|
||||||
|
|
||||||
loan_charges = preprocess_loan_charges_data([loan_charge.to_dict() for loan_charge in loan.loan_charges])
|
loan_charges = preprocess_loan_charges_data([loan_charge.to_dict() for loan_charge in loan.loan_charges])
|
||||||
logger.info(f"Here are your loan_charges: {loan_charges}")
|
logger.info(f"Here are your loan_charges: {loan_charges}")
|
||||||
@@ -62,14 +63,15 @@ class SimbrellaClient:
|
|||||||
interest_fee = loan_charges.get("INTEREST")['amount']
|
interest_fee = loan_charges.get("INTEREST")['amount']
|
||||||
insurance_fee = loan_charges.get("INSURANCE")['amount']
|
insurance_fee = loan_charges.get("INSURANCE")['amount']
|
||||||
|
|
||||||
disbursement_data ={
|
disbursement_data = {
|
||||||
"requestId": data['requestId'],
|
"requestId": data.get('requestId'),
|
||||||
"transactionId": data['transactionId'],
|
"transactionId": data.get('transactionId'),
|
||||||
"debtId": loan_data['debtId'],
|
"FbnTransactionId": data.get('FbnTransactionId'),
|
||||||
"customerId": data['customerId'],
|
"debtId": str(loan_data.get('debtId', "")),
|
||||||
"accountId": data['accountId'],
|
"customerId": data.get('customerId'),
|
||||||
"productId": loan_data['productId'],
|
"accountId": data.get('accountId'),
|
||||||
"provideAmount": loan_data['currentLoanAmount'],
|
"productId": str(loan_data.get('productId', "")),
|
||||||
|
"provideAmount": loan_data.get('currentLoanAmount'),
|
||||||
"collectAmountInterest": interest_fee,
|
"collectAmountInterest": interest_fee,
|
||||||
"collectAmountMgtFee": mgt_fee,
|
"collectAmountMgtFee": mgt_fee,
|
||||||
"collectAmountInsurance": insurance_fee,
|
"collectAmountInsurance": insurance_fee,
|
||||||
|
|||||||
+21
-10
@@ -7,6 +7,7 @@ import logging
|
|||||||
from sqlalchemy import and_, or_, not_
|
from sqlalchemy import and_, or_, not_
|
||||||
from sqlalchemy.sql import func
|
from sqlalchemy.sql import func
|
||||||
from app.utils.logger import logger
|
from app.utils.logger import logger
|
||||||
|
from app.extensions import db
|
||||||
|
|
||||||
class Loan(db.Model):
|
class Loan(db.Model):
|
||||||
__tablename__ = "loans"
|
__tablename__ = "loans"
|
||||||
@@ -72,7 +73,7 @@ class Loan(db.Model):
|
|||||||
'status': self.status,
|
'status': self.status,
|
||||||
'productId': self.product_id,
|
'productId': self.product_id,
|
||||||
'dueDate': self.due_date.isoformat() if self.due_date else None,
|
'dueDate': self.due_date.isoformat() if self.due_date else None,
|
||||||
'loanDate': self.created_at.isoformat if self.created_at else None,
|
'loanDate': self.created_at.isoformat() if self.created_at else None,
|
||||||
'disburseDate': self.disburse_date.isoformat() if self.disburse_date else None,
|
'disburseDate': self.disburse_date.isoformat() if self.disburse_date else None,
|
||||||
'disburseVerify': self.disburse_verify.isoformat if self.disburse_verify else None,
|
'disburseVerify': self.disburse_verify.isoformat if self.disburse_verify else None,
|
||||||
'reference': self.reference
|
'reference': self.reference
|
||||||
@@ -82,22 +83,32 @@ class Loan(db.Model):
|
|||||||
def get_loan_by_transaction_id(cls, transaction_id):
|
def get_loan_by_transaction_id(cls, transaction_id):
|
||||||
return cls.query.filter_by(transaction_id=transaction_id).first()
|
return cls.query.filter_by(transaction_id=transaction_id).first()
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_loan_by_debt_id(cls, debt_id):
|
|
||||||
return cls.query.filter_by(id=debt_id).first()
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_disbursement_date(cls, loan_id, customer_id):
|
def set_disbursement_date(cls, loan_id, customer_id):
|
||||||
"""
|
"""
|
||||||
Update the status of the loan with the given loan_id.
|
Update the disburse date of the loan with the given loan_id.
|
||||||
"""
|
"""
|
||||||
# Retrieve loan
|
# Retrieve loan
|
||||||
loan = cls.query.get(loan_id)
|
loan = cls.query.get(loan_id)
|
||||||
|
|
||||||
if not loan:
|
if not loan:
|
||||||
raise ValueError(f"Loan with ID {loan_id} does not exist.")
|
raise ValueError(f"Loan with ID {loan_id} does not exist.")
|
||||||
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
||||||
logger.info(f"What is now ======= ==== ==> : {current_time}")
|
# Check if customer_id matches
|
||||||
# Update loan disburse_date and timestamp datetime.today().strftime('%Y-%m-%d %H:%M:%S')
|
if loan.customer_id != customer_id:
|
||||||
loan.disburse_date = current_time # datetime.today().strftime('%Y-%m-%d %H:%M:%S')
|
raise ValueError(f"Customer ID {customer_id} does not match the loan's customer ID.")
|
||||||
|
|
||||||
|
current_time = datetime.now()
|
||||||
|
logger.info(f"What is now ======= ==== ==> : {current_time}")
|
||||||
|
# Update loan disburse_date
|
||||||
|
loan.disburse_date = current_time
|
||||||
|
|
||||||
|
# Commit changes to database
|
||||||
|
try:
|
||||||
|
logger.info(f"Updating disburse date for loan ID {loan_id} to {current_time}")
|
||||||
|
db.session.commit()
|
||||||
|
except Exception as e:
|
||||||
|
db.session.rollback()
|
||||||
|
logger.error(f"Failed to update disburse date: {e}")
|
||||||
|
raise
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from flask import Blueprint, request, jsonify, current_app
|
|||||||
import requests
|
import requests
|
||||||
from app.utils.auth import get_headers
|
from app.utils.auth import get_headers
|
||||||
from app.config import settings
|
from app.config import settings
|
||||||
|
from app.utils.logger import logger
|
||||||
|
|
||||||
auth_bp = Blueprint("auth", __name__)
|
auth_bp = Blueprint("auth", __name__)
|
||||||
|
|
||||||
@@ -10,6 +11,7 @@ BASE_URL = settings.BANK_CALL_BASE_URL
|
|||||||
|
|
||||||
@auth_bp.route("/health", methods=["GET"])
|
@auth_bp.route("/health", methods=["GET"])
|
||||||
def health():
|
def health():
|
||||||
|
logger.info("Health check endpoint called")
|
||||||
return jsonify({"status": "Up"})
|
return jsonify({"status": "Up"})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+17
-3
@@ -19,9 +19,23 @@ def verify_transaction():
|
|||||||
def disbursement():
|
def disbursement():
|
||||||
# data = request.json()
|
# data = request.json()
|
||||||
logger.info(f"Calling Disbursement Components")
|
logger.info(f"Calling Disbursement Components")
|
||||||
|
data = {
|
||||||
response = SimbrellaClient.verify_transaction()
|
"requestId": "TRX1747399791142408",
|
||||||
|
"transactionId": "TRX1747399791142408",
|
||||||
|
"FbnTransactionId":"TRX1747399791142408",
|
||||||
|
"debtId": "9451",
|
||||||
|
"customerId": "CUC1696296013",
|
||||||
|
"accountId": "ACC8112865094",
|
||||||
|
"productId": "AMPC",
|
||||||
|
"provideAmount": 6600.0,
|
||||||
|
"collectAmountInterest": 198.0,
|
||||||
|
"collectAmountMgtFee": 66.0,
|
||||||
|
"collectAmountInsurance": 66.0,
|
||||||
|
"collectAmountVAT": 4.95,
|
||||||
|
"countryId": "01",
|
||||||
|
"comment": "Loan Disbursement"
|
||||||
|
}
|
||||||
|
response = SimbrellaClient.disburse_loan(data)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user