sub scription prooductds
This commit is contained in:
@@ -2,6 +2,7 @@ from datetime import datetime, timezone
|
||||
from app.extensions import db
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
# Inside Stripe_Product ===== : {'product_id': 'prod_SvB4RlFx6qXK6v', 'price_id': 'price_1RzKi4LjZLojw6IZA246JDAa'}
|
||||
|
||||
class SubscriptionOptions(db.Model):
|
||||
__tablename__ = 'subscription_options'
|
||||
@@ -14,6 +15,8 @@ class SubscriptionOptions(db.Model):
|
||||
status = db.Column(db.Integer, nullable=True, default=1)
|
||||
added = db.Column(db.DateTime(timezone=False), server_default=func.now())
|
||||
updated = db.Column(db.DateTime(timezone=False), server_default=func.now(), onupdate=func.now())
|
||||
stripe_product_id = db.Column(db.String(100), nullable=True)
|
||||
stripe_price_id = db.Column(db.String(100), nullable=True)
|
||||
|
||||
|
||||
@classmethod
|
||||
@@ -23,6 +26,28 @@ class SubscriptionOptions(db.Model):
|
||||
return None
|
||||
return sub_options
|
||||
|
||||
@classmethod
|
||||
def set_stripe_product_id(cls,package_uid, stripe_product_id):
|
||||
# Retrieve
|
||||
sub_option = cls.query.filter_by(uid=str(package_uid)).first()
|
||||
|
||||
if not sub_option:
|
||||
raise ValueError(f"Reset with ID {package_uid} does not exist.")
|
||||
|
||||
# Update stripe_product_id
|
||||
sub_option.stripe_product_id = stripe_product_id
|
||||
|
||||
@classmethod
|
||||
def set_stripe_price_id(cls, package_uid, stripe_price_id):
|
||||
# Retrieve
|
||||
sub_option = cls.query.filter_by(uid=str(package_uid)).first()
|
||||
|
||||
if not sub_option:
|
||||
raise ValueError(f"Reset with ID {package_uid} does not exist.")
|
||||
|
||||
# Update stripe_price_id
|
||||
sub_option.stripe_price_id = stripe_price_id
|
||||
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
@@ -31,6 +56,8 @@ class SubscriptionOptions(db.Model):
|
||||
"display_name": self.display_name,
|
||||
"status": self.status,
|
||||
"monthly": self.monthly,
|
||||
"stripe_product_id": self.stripe_product_id,
|
||||
"stripe_price_id": self.stripe_price_id,
|
||||
"added": self.added.isoformat() if self.added else None,
|
||||
"updated": self.updated.isoformat() if self.updated else None
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user