Cfeate transactions
This commit is contained in:
@@ -233,7 +233,15 @@ class SimbrellaClient:
|
||||
"text": f"Transaction {loan_data.get('transactionId')} verified successfully",
|
||||
"unicode": True
|
||||
}
|
||||
|
||||
try:
|
||||
TransactionService.create_transaction(loan_data['transactionId'], loan_data['accountId'], loan_data['customerId'], "send_sms", "USSD")
|
||||
except Exception as e:
|
||||
logger.info(f"Failed to LOG SMS Transaction Record: {e}")
|
||||
|
||||
|
||||
try:
|
||||
|
||||
sms_response = requests.post(sms_url, json=sms_data, timeout=10, headers=get_headers())
|
||||
sms_response.raise_for_status() # Raise an exception for 4xx or 5xx status codes
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from app.extensions import db
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from app.utils.logger import logger
|
||||
|
||||
class Transaction(db.Model):
|
||||
__tablename__ = "transactions"
|
||||
|
||||
@@ -18,6 +20,30 @@ class Transaction(db.Model):
|
||||
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))
|
||||
|
||||
@classmethod
|
||||
def create_transaction(cls, transaction_id, account_id, customer_id, type, channel):
|
||||
|
||||
if cls.query.filter( and_( cls.transaction_id ==transaction_id, cls.type==type) ).first():
|
||||
logger.error(f"Transaction already exists for {type}")
|
||||
return '' # dont raise - do not crash beacause of this
|
||||
|
||||
transaction = cls(
|
||||
transaction_id = transaction_id,
|
||||
customer_id = customer_id,
|
||||
account_id = account_id,
|
||||
type = type,
|
||||
channel = channel,
|
||||
created_at=datetime.now(timezone.utc),
|
||||
updated_at=datetime.now(timezone.utc)
|
||||
)
|
||||
|
||||
try:
|
||||
db.session.add(transaction)
|
||||
except IntegrityError as err:
|
||||
raise ValueError(f"Database integrity error: {err}")
|
||||
|
||||
return transaction
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Transaction {self.id}>'
|
||||
|
||||
|
||||
@@ -8,4 +8,10 @@ class TransactionService:
|
||||
Get the transaction by ID
|
||||
"""
|
||||
return Transaction.get_transaction_by_transaction_id(transaction_id)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def create_transaction(transaction_id, account_id, customer_id, type, channel):
|
||||
"""
|
||||
Create Transaction Entry
|
||||
"""
|
||||
return Transaction.create_transaction(transaction_id, account_id, customer_id, type, channel)
|
||||
|
||||
Reference in New Issue
Block a user