# stripe_checkout.py | |
import os | |
import stripe | |
# Load your Stripe secret key | |
stripe.api_key = os.getenv("STRIPE_API_KEY") | |
# Load the redirect URLs from environment (must be set in HF Secrets) | |
SUCCESS_URL = os.getenv("SUCCESS_URL") | |
CANCEL_URL = os.getenv("CANCEL_URL") | |
if not SUCCESS_URL: | |
raise RuntimeError("β SUCCESS_URL is not set. Please add it to your Hugging Face Space Secrets.") | |
if not CANCEL_URL: | |
raise RuntimeError("β CANCEL_URL is not set. Please add it to your Hugging Face Space Secrets.") | |
def create_stripe_session(): | |
""" | |
Creates a Stripe Checkout Session in subscription mode. | |
""" | |
session = stripe.checkout.Session.create( | |
payment_method_types=["card"], | |
line_items=[{ | |
"price_data": { | |
"currency": "usd", | |
"product_data": {"name": "AutoExec AI Pro Subscription"}, | |
"unit_amount": 4900, # $49.00 | |
}, | |
"quantity": 1, | |
}], | |
mode="subscription", | |
success_url=SUCCESS_URL, | |
cancel_url=CANCEL_URL, | |
) | |
return session.url | |