diff --git a/SQL/site_data.sql b/SQL/site_data.sql index 6dfbbd9..49dbe8c 100644 --- a/SQL/site_data.sql +++ b/SQL/site_data.sql @@ -48,6 +48,8 @@ ALTER TABLE members ADD stripe_customer_id VARCHAR(100) ALTER TABLE members ADD profile_completed timestamp without time zone DEFAULT NULL; ALTER TABLE members ADD option_name VARCHAR(100) REFERENCES subscription_options(option_name); ALTER TABLE members ADD next_billing timestamp without time zone; +ALTER TABLE members ADD trial_end timestamp without time zone; + CREATE TABLE members_profile( id SERIAL, diff --git a/app/api/services/account.py b/app/api/services/account.py index 00948b8..0069f1d 100644 --- a/app/api/services/account.py +++ b/app/api/services/account.py @@ -59,7 +59,7 @@ class AccountService(BaseService): bill_style=" next_billing " else: option_name = "Free Trial" - next_bill = "End: 10/10/202" + next_bill = f"Ends: {member_data.trial_end}" view_sub = "Upgrade Account" bill_style = " billing " diff --git a/app/api/services/subscriptions.py b/app/api/services/subscriptions.py index 1d43c1a..edd218f 100644 --- a/app/api/services/subscriptions.py +++ b/app/api/services/subscriptions.py @@ -126,7 +126,7 @@ class SubscriptionsService(BaseService): 'post events', 'Cancel Anytime' ], - "next_payment": '2025-10-15 11:00:07.47214' + "next_payment": member_data.next_billing if member_data.next_billing!=None else member_data.trial_end, }, 'stripe_customer_id': member_data.stripe_customer_id, "options": res_options diff --git a/app/models/members.py b/app/models/members.py index e43a63a..925c85e 100644 --- a/app/models/members.py +++ b/app/models/members.py @@ -1,4 +1,4 @@ -from datetime import datetime, timezone +from datetime import datetime, timezone, timedelta from app.extensions import db from sqlalchemy.sql import func from sqlalchemy.exc import IntegrityError @@ -25,6 +25,7 @@ class Members(db.Model): stripe_customer_id = db.Column(db.String(100), nullable=True) option_name = db.Column(db.String(100), nullable=True) next_billing= db.Column(db.DateTime(timezone=False)) + trial_end = db.Column(db.DateTime(timezone=False)) def to_dict(self): return { @@ -45,6 +46,7 @@ class Members(db.Model): "lastname": self.lastname, 'option_name': self.option_name, "next_billing": self.next_billing, + "trial_end": self.trial_end, "stripe_customer_id": self.stripe_customer_id } @@ -80,7 +82,13 @@ class Members(db.Model): @classmethod - def add_member(cls, firstname, lastname, email, username,password, country): + def add_member(cls, firstname, lastname, email, username,password, country, trials_days = 90): + + # Get the current date and time + current_date = datetime.now() + + # Calculate the date "next_billing_days" days from now + trial_end = current_date + timedelta(days=trials_days) # Save the response member_data = cls( @@ -91,6 +99,7 @@ class Members(db.Model): email=email, country=country, password=password, + trial_end=trial_end, added=datetime.now(timezone.utc), updated=datetime.now(timezone.utc) )