Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /mattyopon_faultray /scripts /setup_stripe.py
| #!/usr/bin/env python3 | |
| """ | |
| FaultRay Stripe Product & Price Setup Script | |
| Creates Stripe Products and Prices for FaultRay SaaS plans: | |
| - FaultRay Pro: $299/month recurring | |
| - FaultRay Business: $999/month recurring | |
| Outputs STRIPE_PRO_PRICE_ID and STRIPE_BUSINESS_PRICE_ID to .env file. | |
| Usage: | |
| export STRIPE_SECRET_KEY=sk_test_... | |
| python scripts/setup_stripe.py | |
| # Or specify .env output path: | |
| python scripts/setup_stripe.py --env-file .env.local | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import os | |
| import sys | |
| from pathlib import Path | |
| def check_stripe_key() -> str: | |
| """Retrieve STRIPE_SECRET_KEY from environment, exit if missing.""" | |
| key = os.environ.get("STRIPE_SECRET_KEY", "") | |
| if not key: | |
| print( | |
| "ERROR: STRIPE_SECRET_KEY environment variable is not set.\n" | |
| "\n" | |
| "To use this script, set your Stripe Secret Key:\n" | |
| "\n" | |
| " For test mode:\n" | |
| " export STRIPE_SECRET_KEY=sk_test_...\n" | |
| "\n" | |
| " For live mode:\n" | |
| " export STRIPE_SECRET_KEY=sk_live_...\n" | |
| "\n" | |
| "You can find your API keys at: https://dashboard.stripe.com/apikeys\n" | |
| "\n" | |
| "For initial setup and testing, use a test mode key (sk_test_...).", | |
| file=sys.stderr, | |
| ) | |
| sys.exit(1) | |
| return key | |
| def create_products_and_prices(api_key: str) -> dict[str, str]: | |
| """Create Stripe Products and Prices, return price IDs.""" | |
| import stripe | |
| stripe.api_key = api_key | |
| # Determine mode from key prefix | |
| mode = "LIVE" if api_key.startswith("sk_live_") else "TEST" | |
| print(f"Stripe mode: {mode}") | |
| print() | |
| # --- FaultRay Pro --- | |
| print("Creating product: FaultRay Pro...") | |
| pro_product = stripe.Product.create( | |
| name="FaultRay Pro", | |
| description=( | |
| "FaultRay Pro plan: 100 simulations/month, 50 components, " | |
| "DORA report export, email support (24h response)." | |
| ), | |
| metadata={ | |
| "plan": "pro", | |
| "app": "faultray", | |
| }, | |
| ) | |
| print(f" Product ID: {pro_product.id}") | |
| print("Creating price: $299/month for FaultRay Pro...") | |
| pro_price = stripe.Price.create( | |
| product=pro_product.id, | |
| unit_amount=29900, # $299.00 in cents | |
| currency="usd", | |
| recurring={"interval": "month"}, | |
| metadata={ | |
| "plan": "pro", | |
| "app": "faultray", | |
| }, | |
| ) | |
| print(f" Price ID: {pro_price.id}") | |
| print() | |
| # --- FaultRay Business --- | |
| print("Creating product: FaultRay Business...") | |
| business_product = stripe.Product.create( | |
| name="FaultRay Business", | |
| description=( | |
| "FaultRay Business plan: unlimited simulations, unlimited components, " | |
| "DORA report + insurance API, custom SSO, dedicated support (1h response)." | |
| ), | |
| metadata={ | |
| "plan": "business", | |
| "app": "faultray", | |
| }, | |
| ) | |
| print(f" Product ID: {business_product.id}") | |
| print("Creating price: $999/month for FaultRay Business...") | |
| business_price = stripe.Price.create( | |
| product=business_product.id, | |
| unit_amount=99900, # $999.00 in cents | |
| currency="usd", | |
| recurring={"interval": "month"}, | |
| metadata={ | |
| "plan": "business", | |
| "app": "faultray", | |
| }, | |
| ) | |
| print(f" Price ID: {business_price.id}") | |
| print() | |
| return { | |
| "STRIPE_PRO_PRICE_ID": pro_price.id, | |
| "STRIPE_BUSINESS_PRICE_ID": business_price.id, | |
| } | |
| def write_env_file(env_path: Path, price_ids: dict[str, str]) -> None: | |
| """Append or update price IDs in the .env file.""" | |
| existing_lines: list[str] = [] | |
| keys_to_write = dict(price_ids) | |
| if env_path.exists(): | |
| with open(env_path) as f: | |
| for line in f: | |
| stripped = line.strip() | |
| # Remove existing entries for these keys (we'll re-add them) | |
| key_found = False | |
| for key in price_ids: | |
| if stripped.startswith(f"{key}="): | |
| key_found = True | |
| break | |
| if not key_found: | |
| existing_lines.append(line) | |
| with open(env_path, "w") as f: | |
| # Write back existing content | |
| for line in existing_lines: | |
| f.write(line) | |
| # Ensure newline before our entries | |
| if existing_lines and not existing_lines[-1].endswith("\n"): | |
| f.write("\n") | |
| # Write new entries | |
| f.write("\n# FaultRay Stripe Price IDs (auto-generated by setup_stripe.py)\n") | |
| for key, value in keys_to_write.items(): | |
| f.write(f"{key}={value}\n") | |
| print(f"Price IDs written to {env_path}") | |
| def main() -> None: | |
| """Main entry point.""" | |
| parser = argparse.ArgumentParser( | |
| description="Set up FaultRay Stripe Products & Prices", | |
| ) | |
| parser.add_argument( | |
| "--env-file", | |
| type=Path, | |
| default=Path(".env"), | |
| help="Path to .env file for output (default: .env)", | |
| ) | |
| parser.add_argument( | |
| "--dry-run", | |
| action="store_true", | |
| help="Show what would be created without making API calls", | |
| ) | |
| args = parser.parse_args() | |
| api_key = check_stripe_key() | |
| if args.dry_run: | |
| mode = "LIVE" if api_key.startswith("sk_live_") else "TEST" | |
| print(f"DRY RUN (Stripe mode: {mode})") | |
| print() | |
| print("Would create:") | |
| print(" Product: FaultRay Pro") | |
| print(" Price: $299/month recurring (USD)") | |
| print(" Product: FaultRay Business") | |
| print(" Price: $999/month recurring (USD)") | |
| print() | |
| print(f"Would write to: {args.env_file}") | |
| print(" STRIPE_PRO_PRICE_ID=price_...") | |
| print(" STRIPE_BUSINESS_PRICE_ID=price_...") | |
| return | |
| print("=" * 50) | |
| print("FaultRay Stripe Setup") | |
| print("=" * 50) | |
| print() | |
| price_ids = create_products_and_prices(api_key) | |
| write_env_file(args.env_file, price_ids) | |
| print() | |
| print("=" * 50) | |
| print("Setup complete!") | |
| print("=" * 50) | |
| print() | |
| for key, value in price_ids.items(): | |
| print(f" {key}={value}") | |
| print() | |
| print( | |
| "You can now use these price IDs in your Stripe Checkout " | |
| "or Subscription API calls." | |
| ) | |
| if __name__ == "__main__": | |
| main() | |
Xet Storage Details
- Size:
- 6.46 kB
- Xet hash:
- 9a30bae0902ba57855b4d22798029c61666f935590c98de369d51de693edd742
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.