Merge branch 'oluyemi' of DigiFi/digifi-EventManager into master
This commit is contained in:
@@ -131,7 +131,7 @@ class KafkaIntegration:
|
|||||||
try:
|
try:
|
||||||
response = SimbrellaClient.disbursement(message)
|
response = SimbrellaClient.disbursement(message)
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Successfully sent message to disbursement service: {response.status_code}"
|
f"Successfully sent message to disbursement service: {response}"
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.info(f"Failed to call disbursement service: {e}")
|
logger.info(f"Failed to call disbursement service: {e}")
|
||||||
@@ -145,7 +145,7 @@ class KafkaIntegration:
|
|||||||
try:
|
try:
|
||||||
response = SimbrellaClient.collect_loan(message)
|
response = SimbrellaClient.collect_loan(message)
|
||||||
logger.info(
|
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:
|
except Exception as e:
|
||||||
logger.info(f"Failed to call collect_loan service: {e}")
|
logger.info(f"Failed to call collect_loan service: {e}")
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from app.utils.auth import get_headers
|
|||||||
from app.utils.logger import logger
|
from app.utils.logger import logger
|
||||||
from flask import jsonify, current_app
|
from flask import jsonify, current_app
|
||||||
from app.services.transactions import TransactionService
|
from app.services.transactions import TransactionService
|
||||||
|
from app.services.repayment import RepaymentService
|
||||||
|
|
||||||
|
|
||||||
class SimbrellaClient:
|
class SimbrellaClient:
|
||||||
@@ -58,6 +59,16 @@ class SimbrellaClient:
|
|||||||
api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/CollectLoan"
|
api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}/CollectLoan"
|
||||||
logger.info(f"Calling CollectLoan endpoint with data: {data}")
|
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 = {
|
collect_loan_data = {
|
||||||
"transactionId": "T002",
|
"transactionId": "T002",
|
||||||
"fbnTransactionId": "FBN20231123",
|
"fbnTransactionId": "FBN20231123",
|
||||||
@@ -120,7 +131,3 @@ class SimbrellaClient:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.info(f"Failed to call Payment Callback endpoint: {e}")
|
logger.info(f"Failed to call Payment Callback endpoint: {e}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def check_transaction(txn_id):
|
|
||||||
return run_in_app_context(Transaction.get_transaction_by_id(txn_id))
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
from .transactions import Transaction
|
from .transactions import Transaction
|
||||||
|
from .repayment import Repayment
|
||||||
|
|
||||||
__all__ = ['Transaction']
|
__all__ = ['Transaction', 'Repayment']
|
||||||
@@ -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()
|
||||||
@@ -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)
|
||||||
Reference in New Issue
Block a user