forked from andika/membership-be
first commit
This commit is contained in:
81
seed_plans.py
Normal file
81
seed_plans.py
Normal file
@@ -0,0 +1,81 @@
|
||||
"""
|
||||
Seed subscription plans into the database.
|
||||
Creates a default annual membership plan for testing.
|
||||
"""
|
||||
|
||||
import os
|
||||
from database import SessionLocal
|
||||
from models import SubscriptionPlan
|
||||
from payment_service import create_stripe_price
|
||||
|
||||
def seed_plans():
|
||||
"""Create default subscription plans"""
|
||||
db = SessionLocal()
|
||||
|
||||
try:
|
||||
# Check if plans already exist
|
||||
existing_plans = db.query(SubscriptionPlan).count()
|
||||
if existing_plans > 0:
|
||||
print(f"⚠️ Found {existing_plans} existing plan(s). Skipping seed.")
|
||||
return
|
||||
|
||||
print("Creating subscription plans...")
|
||||
|
||||
# Option 1: Create plan WITHOUT Stripe Price ID (for testing without Stripe)
|
||||
# Uncomment this if you want to test UI without actual Stripe integration
|
||||
annual_plan = SubscriptionPlan(
|
||||
name="Annual Membership",
|
||||
description="Full access to all LOAF community benefits for one year",
|
||||
price_cents=10000, # $100.00
|
||||
billing_cycle="yearly",
|
||||
stripe_price_id=None, # Set to None for local testing
|
||||
active=True
|
||||
)
|
||||
|
||||
# Option 2: Create plan WITH Stripe Price ID (requires valid Stripe API key)
|
||||
# Uncomment this block and comment out Option 1 if you have Stripe configured
|
||||
"""
|
||||
try:
|
||||
stripe_price_id = create_stripe_price(
|
||||
product_name="LOAF Annual Membership",
|
||||
price_cents=10000, # $100.00
|
||||
billing_cycle="yearly"
|
||||
)
|
||||
print(f"✅ Created Stripe Price: {stripe_price_id}")
|
||||
|
||||
annual_plan = SubscriptionPlan(
|
||||
name="Annual Membership",
|
||||
description="Full access to all LOAF community benefits for one year",
|
||||
price_cents=10000,
|
||||
billing_cycle="yearly",
|
||||
stripe_price_id=stripe_price_id,
|
||||
active=True
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"❌ Failed to create Stripe Price: {e}")
|
||||
print("Creating plan without Stripe Price ID for local testing...")
|
||||
annual_plan = SubscriptionPlan(
|
||||
name="Annual Membership",
|
||||
description="Full access to all LOAF community benefits for one year",
|
||||
price_cents=10000,
|
||||
billing_cycle="yearly",
|
||||
stripe_price_id=None,
|
||||
active=True
|
||||
)
|
||||
"""
|
||||
|
||||
db.add(annual_plan)
|
||||
db.commit()
|
||||
db.refresh(annual_plan)
|
||||
|
||||
print(f"✅ Created plan: {annual_plan.name} (${annual_plan.price_cents/100:.2f}/{annual_plan.billing_cycle})")
|
||||
print(f" Plan ID: {annual_plan.id}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error seeding plans: {e}")
|
||||
db.rollback()
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
seed_plans()
|
||||
Reference in New Issue
Block a user