Added full repayment data #23
@@ -41,5 +41,6 @@ class Config:
|
||||
BANK_CALL_DISBURSE_LOAN_ENDPOINT = os.getenv("BANK_CALL_DISBURSE_LOAN_ENDPOINT","/DisburseLoan")
|
||||
BANK_CALL_COLLECT_LOAN_ENDPOINT = os.getenv("BANK_CALL_COLLECT_LOAN_ENDPOINT","/CollectLoan")
|
||||
BANK_CALL_TRANSACTION_VERIFY = os.getenv("BANK_CALL_TRANSACTION_VERIFY", "/TransactionVerify")
|
||||
TEST_NO = os.getenv("TEST_NO", "2347038224367")
|
||||
|
||||
settings = Config()
|
||||
|
||||
@@ -106,6 +106,7 @@ class SimbrellaClient:
|
||||
# Check if the transaction exists
|
||||
logger.info(f"Checking if transaction exists")
|
||||
transaction = TransactionService.get_transaction_by_transaction_id(transaction_id=data['transactionId'])
|
||||
transaction_data = transaction.to_dict()
|
||||
logger.info(f"Loan Response From Database ** : {transaction}")
|
||||
|
||||
# If transaction is not found
|
||||
@@ -142,6 +143,7 @@ class SimbrellaClient:
|
||||
"accountId": loan_data.get('accountId'),
|
||||
"transactionId": loan_data.get('transactionId'),
|
||||
"transactionType": "provide",
|
||||
"fbnTransactionId": loan_data.get('transactionId'),
|
||||
"countryId": "NG",
|
||||
"requestId": loan_data.get('transactionId')
|
||||
}
|
||||
@@ -150,10 +152,11 @@ class SimbrellaClient:
|
||||
logger.info(f"Here is your TransactionVerify Request data ****** : {verify_data}")
|
||||
response = requests.post(api_url, json=verify_data, timeout=10, headers=get_headers())
|
||||
result = response.json()
|
||||
logger.info(f"this is verify result, {result}")
|
||||
LoanService.set_disburse_verify_result(loan_data['debtId'],result.get('responseCode', ''), result.get('responseMessage', ''))
|
||||
sms_data = {
|
||||
"dest": "2347038224367",
|
||||
"text": "test",
|
||||
"dest": transaction_data.get('phone_number') or settings.TEST_NO,
|
||||
"text": f"Transaction {loan_data.get('transactionId')} verified successfully",
|
||||
"unicode": True
|
||||
}
|
||||
try:
|
||||
@@ -188,13 +191,14 @@ class SimbrellaClient:
|
||||
if not repayment:
|
||||
logger.info(f"Repayment with transactionId: {data['transactionId']}, was not found")
|
||||
return ResponseHelper.error("Repayment not found")
|
||||
|
||||
logger.info(f"Repayment Response From Database ** : {repayment.to_dict()}")
|
||||
repayment_data = repayment.to_dict()
|
||||
loan = LoanService.get_loan_by_transaction_id(transaction_id=repayment_data['transactionId'])
|
||||
loan = LoanService.get_loan_by_loan_id(loan_id=int(repayment_data['loanId']))
|
||||
|
||||
|
||||
# If loan is not found
|
||||
if not loan:
|
||||
logger.info(f"Loan with debtId: {repayment_data.loan_id}, was not found")
|
||||
if loan is None:
|
||||
logger.info(f"Loan with debtId: {repayment_data['loanId']}, was not found")
|
||||
return ResponseHelper.error("Loan not found")
|
||||
|
||||
loan_data = loan.to_dict()
|
||||
@@ -233,7 +237,19 @@ class SimbrellaClient:
|
||||
logger.info(f"CollectLoan response: {response.json()}")
|
||||
RepaymentService.set_repay_result(repayment_data['Id'], response.json().get('responseCode', ''), response.json().get('responseMessage', ''))
|
||||
result = response.json()
|
||||
new_repayment_data = RepaymentsData.add_repayment_data(result)
|
||||
logger.info(f"this is the result {result}")
|
||||
data_to_add = {
|
||||
"transactionId": result.get('transactionId') or collect_loan_data.get('transactionId'),
|
||||
"fbnTransactionId": result.get('fbnTransactionId') or collect_loan_data.get('fbnTransactionId'),
|
||||
"accountId": result.get('accountId') or collect_loan_data.get('accountId'),
|
||||
"customerId": result.get('customerId') or collect_loan_data.get('customerId'),
|
||||
"amountCollected": result.get('amountCollected'),
|
||||
"repaymentAmount": collect_loan_data.get('collectAmount'),
|
||||
"responseCode": result.get('responseCode'),
|
||||
"responseDescr": result.get('responseMessage'),
|
||||
}
|
||||
|
||||
new_repayment_data = RepaymentsData.add_repayment_data(data_to_add)
|
||||
logger.info(f"Repayment data added successfully: {new_repayment_data.to_dict()}")
|
||||
if not new_repayment_data:
|
||||
logger.info(f"Failed to add repayment data")
|
||||
|
||||
@@ -93,6 +93,9 @@ class Loan(db.Model):
|
||||
@classmethod
|
||||
def get_loan_by_transaction_id(cls, transaction_id):
|
||||
return cls.query.filter_by(transaction_id=transaction_id).first()
|
||||
@classmethod
|
||||
def get_loan_by_loan_id(cls, loan_id):
|
||||
return cls.query.filter_by(id=loan_id).first()
|
||||
|
||||
@classmethod
|
||||
def set_disbursement_date(cls, loan_id, customer_id):
|
||||
|
||||
@@ -10,6 +10,11 @@ class RepaymentsData(db.Model):
|
||||
added_date = db.Column(db.DateTime(timezone=True), default=datetime.now(timezone.utc), nullable=False)
|
||||
response_code = db.Column(db.String(10), nullable=True)
|
||||
response_descr = db.Column(db.String(255), nullable=True)
|
||||
fbn_transaction_id = db.Column(db.String(255),nullable=True)
|
||||
account_id = db.Column(db.String(50), nullable=True)
|
||||
customer_id = db.Column(db.String(50), nullable=True)
|
||||
repayment_amount = db.Column(db.Float, nullable=True)
|
||||
amount_collected = db.Column(db.Float, nullable=True)
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
@@ -18,6 +23,11 @@ class RepaymentsData(db.Model):
|
||||
"added_date": self.added_date.isoformat() if self.added_date else None,
|
||||
"response_code": self.response_code,
|
||||
"response_descr": self.response_descr,
|
||||
"customerId": self.customer_id,
|
||||
"accountId": self.customer_id,
|
||||
"fbnTransactionId": self.fbn_transaction_id,
|
||||
"repaymentAmount": self.repayment_amount,
|
||||
"amountCollected": self.amount_collected
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +43,12 @@ class RepaymentsData(db.Model):
|
||||
new_data = cls(
|
||||
transaction_id=data.get('transactionId'),
|
||||
response_code=data.get('responseCode'),
|
||||
response_descr=data.get('responseMessage')
|
||||
response_descr=data.get('responseDescr'),
|
||||
fbn_transaction_id=data.get('fbnTransactionId'),
|
||||
account_id=data.get('accountId'),
|
||||
customer_id=data.get('customerId'),
|
||||
amount_collected=data.get('amountCollected'),
|
||||
repayment_amount=data.get('repaymentAmount'),
|
||||
)
|
||||
db.session.add(new_data)
|
||||
db.session.commit()
|
||||
|
||||
@@ -14,6 +14,7 @@ class Transaction(db.Model):
|
||||
customer_id = db.Column(db.String(50), nullable=True)
|
||||
type = db.Column(db.String(50), nullable=False)
|
||||
channel = db.Column(db.String(50), nullable=False)
|
||||
phone_number = db.Column(db.String(50), 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))
|
||||
|
||||
@@ -29,6 +30,7 @@ class Transaction(db.Model):
|
||||
'transaction_id': self.transaction_id,
|
||||
'account_id': self.account_id,
|
||||
'customer_id': self.customer_id,
|
||||
'phone_number':self.phone_number,
|
||||
'type': self.type,
|
||||
'channel': self.channel,
|
||||
}
|
||||
|
||||
@@ -8,6 +8,13 @@ class LoanService:
|
||||
Get the loan by transaction ID
|
||||
"""
|
||||
return Loan.get_loan_by_transaction_id(transaction_id)
|
||||
@classmethod
|
||||
def get_loan_by_loan_id(cls, loan_id):
|
||||
"""
|
||||
Get the loan by ID
|
||||
"""
|
||||
return Loan.get_loan_by_loan_id(loan_id)
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_loan_by_debt_id(cls, debt_id):
|
||||
|
||||
@@ -7,4 +7,5 @@ class TransactionService:
|
||||
"""
|
||||
Get the transaction by ID
|
||||
"""
|
||||
return Transaction.get_transaction_by_transaction_id(transaction_id)
|
||||
return Transaction.get_transaction_by_transaction_id(transaction_id)
|
||||
|
||||
Reference in New Issue
Block a user