payment/payment_backend/repositories/order.py

41 lines
1.4 KiB
Python

from custom_decorators import singleton
from database import Database
from utils.datetime import current_timestamp
@singleton
class OrderRepository:
def __init__(self, config):
self.db = Database(config['MYSQL'])
def create(self, order_id, quant, from_address, to_address):
timestamp = current_timestamp()
try:
self.db.execute_query(
"INSERT INTO orders (order_id, quant, from_address, to_address, create_timestamp, update_timestamp) "
"VALUES (%s, %s, %s, %s, %s, %s)",
[order_id, quant, from_address, to_address, timestamp, timestamp]
)
self.db.commit()
return timestamp
except Exception:
self.db.rollback()
raise
def update_status(self, order_id, status):
try:
self.db.execute_query("UPDATE orders "
"SET status = %s, update_timestamp = %s "
"WHERE order_id = %s",
[status, current_timestamp(), order_id])
self.db.commit()
except Exception:
self.db.rollback()
raise
def get_order_info(self, order_id):
self.db.execute_query("SELECT quant, from_address, to_address, create_timestamp "
"FROM orders "
"WHERE order_id = %s",
[order_id])