Cfeate transactions

This commit is contained in:
CHIEFSOFT\ameye
2025-11-02 17:42:56 -05:00
parent a6198a782c
commit 3602599f4a
3 changed files with 41 additions and 1 deletions
+8
View File
@@ -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
+26
View File
@@ -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}>'
+7 -1
View File
@@ -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)