done with check transaction_id on repayment #14

Merged
ameye merged 1 commits from oluyemi into master 2025-04-16 09:42:30 +00:00
5 changed files with 50 additions and 8 deletions
+2 -2
View File
@@ -131,7 +131,7 @@ class KafkaIntegration:
try:
response = SimbrellaClient.disbursement(message)
logger.info(
f"Successfully sent message to disbursement service: {response.status_code}"
f"Successfully sent message to disbursement service: {response}"
)
except Exception as e:
logger.info(f"Failed to call disbursement service: {e}")
@@ -145,7 +145,7 @@ class KafkaIntegration:
try:
response = SimbrellaClient.collect_loan(message)
logger.info(
f"Successfully sent message to collect_loan service: {response.status_code}"
f"Successfully sent message to collect_loan service: {response}"
)
except Exception as e:
logger.info(f"Failed to call collect_loan service: {e}")
+12 -5
View File
@@ -4,6 +4,7 @@ from app.utils.auth import get_headers
from app.utils.logger import logger
from flask import jsonify, current_app
from app.services.transactions import TransactionService
from app.services.repayment import RepaymentService
class SimbrellaClient:
@@ -58,6 +59,16 @@ class SimbrellaClient:
api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/CollectLoan"
logger.info(f"Calling CollectLoan endpoint with data: {data}")
# Check if the repayment exists
logger.info(f"Checking if repayment exists")
repayment = RepaymentService.get_repayment_by_transaction_id(transaction_id=data['transactionId'])
logger.info(f"Response from database: {repayment}")
# If repayment is not found
if not repayment:
logger.info(f"Repayment id: {data['transactionId']}, was not found")
return 0
collect_loan_data = {
"transactionId": "T002",
"fbnTransactionId": "FBN20231123",
@@ -119,8 +130,4 @@ class SimbrellaClient:
except Exception as e:
logger.info(f"Failed to call Payment Callback endpoint: {e}")
raise
@staticmethod
def check_transaction(txn_id):
return run_in_app_context(Transaction.get_transaction_by_id(txn_id))
raise
+2 -1
View File
@@ -1,3 +1,4 @@
from .transactions import Transaction
from .repayment import Repayment
__all__ = ['Transaction']
__all__ = ['Transaction', 'Repayment']
+24
View File
@@ -0,0 +1,24 @@
from app.extensions import db
from datetime import datetime, timezone
class Repayment(db.Model):
__tablename__ = "repayments"
id = db.Column(
db.Integer,
primary_key=True,
autoincrement=True,
)
loan_id = db.Column(db.String(50), nullable=False)
customer_id = db.Column(db.String(50), nullable=False)
product_id = db.Column(db.String(20), nullable=True)
transaction_id = db.Column(db.String(50), nullable=False)
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))
def __repr__(self):
return f'<Repayment {self.id}>'
@classmethod
def get_repayment_by_transaction_id(cls, transaction_id):
return cls.query.filter_by(transaction_id=transaction_id).first()
+10
View File
@@ -0,0 +1,10 @@
from app.models import Repayment
class RepaymentService:
@staticmethod
def get_repayment_by_transaction_id(transaction_id):
"""
Get the repayment by transaction ID
"""
return Repayment.get_repayment_by_transaction_id(transaction_id)