Skip to content

Commit

Permalink
Create models.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 3, 2024
1 parent 9005ee2 commit 2763108
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# payment_gateway/models.py
from. import db, bcrypt

class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(50), unique=True, nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
password = db.Column(db.String(100), nullable=False)
created_at = db.Column(db.DateTime, default=db.func.current_timestamp())
updated_at = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())

def set_password(self, password):
self.password = bcrypt.generate_password_hash(password).decode("utf-8")

def check_password(self, password):
return bcrypt.check_password_hash(self.password, password)

class PaymentMethod(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
user = db.relationship("User", backref="payment_methods")
payment_method_type = db.Column(db.String(50), nullable=False)
payment_method_token = db.Column(db.String(100), nullable=False)
created_at = db.Column(db.DateTime, default=db.func.current_timestamp())
updated_at = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())

class Transaction(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
user = db.relationship("User", backref="transactions")
payment_method_id = db.Column(db.Integer, db.ForeignKey("payment_method.id"))
payment_method = db.relationship("PaymentMethod", backref="transactions")
amount = db.Column(db.Float, nullable=False)
currency = db.Column(db.String(3), nullable=False)
status = db.Column(db.String(50), nullable=False)
created_at = db.Column(db.DateTime, default=db.func.current_timestamp())
updated_at = db.Column(db.DateTime, default=db.func.current_timestamp(), onupdate=db.func.current_timestamp())

@login_manager.user_loader
def load_user(user_id):
return User.query.get(int(user_id))

0 comments on commit 2763108

Please sign in to comment.