Active Subscriptions
Real-time status of users with active or trialing plans.
🔄 Loading WebAssembly Environment & Stripe Data...
Customer / Email
Subscription ID
Status
Current Period Ends
- requests
import requests from datetime import datetime from js import document STRIPE_API_KEY = "sk_live_h5Roa2xQ29Ig30ywCZ3bl0le" # ⚠️ Replace with your Stripe Secret Key def fetch_stripe_subscriptions(): # 💡 Using an allorigins proxy wrapper to completely bypass browser CORS restrictions locally url = f"https://allorigins.win{requests.utils.quote('https://stripe.com[]=data.customer')}" headers = { "Authorization": f"Bearer {STRIPE_API_KEY}" } try: # Allorigins handles the preflight, allowing browser requests without CORS blocking response = requests.get(url, headers=headers) if response.status_code == 200: # The proxy wraps the original JSON inside a "contents" string key import json raw_data = response.json().get("contents", "{}") stripe_data = json.loads(raw_data) render_table(stripe_data.get("data", [])) else: render_error(f"Proxy Error {response.status_code}") except Exception as e: render_error(f"Failed to fetch data: {str(e)}") def render_table(subscriptions): table_body = document.getElementById("subscription-rows") table_body.innerHTML = "" if not subscriptions: table_body.innerHTML = "
No active subscriptions found.
" document.getElementById("loading-spinner").style.display = "none" return for sub in subscriptions: sub_id = sub.get("id") status = sub.get("status") customer_obj = sub.get("customer") customer_info = "Unknown Customer" if isinstance(customer_obj, dict): customer_info = customer_obj.get("email") or customer_obj.get("name") or customer_obj.get("id") else: customer_info = customer_obj current_period_end = sub.get("current_period_end") expiry_date = datetime.fromtimestamp(current_period_end).strftime('%Y-%m-%d') if current_period_end else "N/A" status_color = "bg-green-100 text-green-800" if status == "active" else "bg-blue-100 text-blue-800" row_html = f"""
{customer_info}
{sub_id}
{status}
{expiry_date}
""" table_body.innerHTML += row_html document.getElementById("loading-spinner").style.display = "none" def render_error(msg): document.getElementById("subscription-rows").innerHTML = f"
{msg}
" document.getElementById("loading-spinner").style.display = "none" # Initialize fetch_stripe_subscriptions()