File size: 1,090 Bytes
4afbf70
 
4fd9f19
4afbf70
4fd9f19
7f140e5
4fd9f19
 
7f140e5
 
 
 
 
 
 
 
 
4fd9f19
7f140e5
 
 
4fd9f19
 
 
 
 
 
7f140e5
4fd9f19
 
 
 
7f140e5
 
4fd9f19
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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