loand ids
This commit is contained in:
@@ -91,54 +91,33 @@ class SimbrellaClient:
|
||||
logger.info(f"Checking if repayment exists")
|
||||
repayment = RepaymentService.get_repayment_by_transaction_id(transaction_id=data['transactionId'])
|
||||
logger.info(f"Repayment Response From Database ** : {repayment}")
|
||||
loan = LoanService.get_loan_charge_by_debt_id(debt_id=repayment.loan_id)
|
||||
|
||||
# If repayment is not found
|
||||
if not repayment:
|
||||
logger.info(f"Repayment id: {data['transactionId']}, was not found")
|
||||
return 0
|
||||
|
||||
logger.info(f"Repayment data transaction_id : {repayment.transaction_id}")
|
||||
logger.info(f"Repayment data id : {repayment.id}")
|
||||
logger.info(f"Repayment data customer_id : {repayment.customer_id}")
|
||||
logger.info(f"Repayment data loan_id : {repayment.loan_id}")
|
||||
logger.info(f"Repayment data product_id : {repayment.product_id}")
|
||||
# logger.info(f"Repayment data : {repayment.}")
|
||||
# logger.info(f"Repayment data : {repayment.transaction_id}")
|
||||
# logger.info(f"Repayment data : {repayment.transaction_id}")
|
||||
repayAmount = loan.repayment_amount
|
||||
|
||||
collectAmount = repayAmount
|
||||
|
||||
collect_loan_data = {
|
||||
"transactionId": data['transactionId'],
|
||||
"fbnTransactionId": "FBN20231123",
|
||||
"debtId": data['debtId'],
|
||||
"customerId": data['customerId'],
|
||||
"accountId": "2017821799",
|
||||
"productId": data['productId'],
|
||||
"collectAmount": 80000,
|
||||
"transactionId": repayment.transaction_id,
|
||||
"fbnTransactionId": loan.reference,
|
||||
"debtId": repayment.loan_id,
|
||||
"customerId": repayment.customer_id,
|
||||
"accountId": loan.account,
|
||||
"productId": repayment.product_id,
|
||||
"collectAmount": collectAmount,
|
||||
"penalCharge": 0,
|
||||
"channel": "USSD",
|
||||
"collectionMethod": 1,
|
||||
"lienAmount": 80000,
|
||||
"lienAmount": 0,
|
||||
"countryId": "01",
|
||||
"comment": "Testing CollectionLoanRequest"
|
||||
}
|
||||
|
||||
# {
|
||||
# "channel": "string",
|
||||
# "transactionId": "string",
|
||||
# "fbnTransactionId": "string",
|
||||
# "debtId": "string",
|
||||
# "accountId": "string",
|
||||
# "customerId": "string",
|
||||
# "productId": "string",
|
||||
# "collectAmount": 0,
|
||||
# "penalCharge": 0,
|
||||
# "collectionMethod": "string",
|
||||
# "lienAmount": 0,
|
||||
# "countryId": "string",
|
||||
# "comment": "string"
|
||||
# }
|
||||
|
||||
try:
|
||||
logger.info(f"Here is your CollectLoan Request data ***** : {collect_loan_data}")
|
||||
response = requests.post(api_url, json=collect_loan_data, headers=get_headers())
|
||||
|
||||
+29
-3
@@ -12,6 +12,7 @@ class Loan(db.Model):
|
||||
)
|
||||
customer_id = db.Column(db.String(50), nullable=False)
|
||||
transaction_id = db.Column(db.String(50), nullable=True)
|
||||
original_transaction = db.Column(db.String(50), nullable=True)
|
||||
account_id = db.Column(db.String(50), nullable=False)
|
||||
offer_id = db.Column(db.String(20), nullable=False)
|
||||
product_id = db.Column(db.String(20), nullable=True)
|
||||
@@ -20,10 +21,18 @@ class Loan(db.Model):
|
||||
initial_loan_amount = db.Column(db.Float, nullable=False)
|
||||
default_penalty_fee = db.Column(db.Float, default=0)
|
||||
continuous_fee = db.Column(db.Float, default=0)
|
||||
upfront_fee = db.Column(db.Float, nullable=True, default=0.0)
|
||||
repayment_amount = db.Column(db.Float, nullable=True, default=0.0)
|
||||
installment_amount = db.Column(db.Float, nullable=True, default=0.0)
|
||||
status = db.Column(db.String(20), default='pending')
|
||||
tenor = db.Column(db.Integer, nullable=True)
|
||||
due_date = db.Column(db.DateTime, nullable=True)
|
||||
created_at = db.Column(db.DateTime, default=datetime.now(timezone.utc))
|
||||
updated_at = db.Column(db.DateTime, default=datetime.now(timezone.utc), onupdate=datetime.now(timezone.utc))
|
||||
created_at = db.Column(db.DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = db.Column(db.DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
eligible_amount = db.Column(db.Float, nullable=True, default=0.0)
|
||||
disburse_date = db.Column(db.DateTime, nullable=True)
|
||||
disburse_verify = db.Column(db.DateTime, nullable=True)
|
||||
reference = db.Column(db.String(50), nullable=True)
|
||||
|
||||
customer = relationship(
|
||||
"Customer",
|
||||
@@ -61,4 +70,21 @@ class Loan(db.Model):
|
||||
|
||||
@classmethod
|
||||
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 set_disbursement_date(cls, loan_id, customer_id):
|
||||
"""
|
||||
Update the status of the loan with the given loan_id.
|
||||
"""
|
||||
# Retrieve loan
|
||||
loan = cls.query.get(loan_id)
|
||||
|
||||
if not loan:
|
||||
raise ValueError(f"Loan with ID {loan_id} does not exist.")
|
||||
|
||||
if loan.status == status:
|
||||
return
|
||||
|
||||
# Update loan disburse_date and timestamp datetime.today().strftime('%Y-%m-%d %H:%M:%S')
|
||||
loan.disburse_date = datetime.today().strftime('%Y-%m-%d %H:%M:%S')
|
||||
@@ -14,4 +14,11 @@ class LoanService:
|
||||
"""
|
||||
Get the loan charge by debt ID
|
||||
"""
|
||||
return LoanCharge.get_loan_charge_by_debt_id(debt_id)
|
||||
return LoanCharge.get_loan_charge_by_debt_id(debt_id)
|
||||
|
||||
@classmethod
|
||||
def set_disbursement_date(cls, loan_id, customer_id):
|
||||
"""
|
||||
Update the disbursement status of the loan with the given loan_id.
|
||||
"""
|
||||
return Loan.set_disbursement_date(loan_id, customer_id)
|
||||
|
||||
Reference in New Issue
Block a user