Update stripe_checkout.py
Browse files- stripe_checkout.py +16 -3
stripe_checkout.py
CHANGED
@@ -3,21 +3,34 @@
|
|
3 |
import os
|
4 |
import stripe
|
5 |
|
|
|
6 |
stripe.api_key = os.getenv("STRIPE_API_KEY")
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def create_stripe_session():
|
|
|
|
|
|
|
9 |
session = stripe.checkout.Session.create(
|
10 |
payment_method_types=["card"],
|
11 |
line_items=[{
|
12 |
"price_data": {
|
13 |
"currency": "usd",
|
14 |
"product_data": {"name": "AutoExec AI Pro Subscription"},
|
15 |
-
"unit_amount": 4900,
|
16 |
},
|
17 |
"quantity": 1,
|
18 |
}],
|
19 |
mode="subscription",
|
20 |
-
success_url=
|
21 |
-
cancel_url=
|
22 |
)
|
23 |
return session.url
|
|
|
3 |
import os
|
4 |
import stripe
|
5 |
|
6 |
+
# Load your Stripe secret key
|
7 |
stripe.api_key = os.getenv("STRIPE_API_KEY")
|
8 |
|
9 |
+
# Load the redirect URLs from environment (must be set in HF Secrets)
|
10 |
+
SUCCESS_URL = os.getenv("SUCCESS_URL")
|
11 |
+
CANCEL_URL = os.getenv("CANCEL_URL")
|
12 |
+
|
13 |
+
if not SUCCESS_URL:
|
14 |
+
raise RuntimeError("❌ SUCCESS_URL is not set. Please add it to your Hugging Face Space Secrets.")
|
15 |
+
if not CANCEL_URL:
|
16 |
+
raise RuntimeError("❌ CANCEL_URL is not set. Please add it to your Hugging Face Space Secrets.")
|
17 |
+
|
18 |
def create_stripe_session():
|
19 |
+
"""
|
20 |
+
Creates a Stripe Checkout Session in subscription mode.
|
21 |
+
"""
|
22 |
session = stripe.checkout.Session.create(
|
23 |
payment_method_types=["card"],
|
24 |
line_items=[{
|
25 |
"price_data": {
|
26 |
"currency": "usd",
|
27 |
"product_data": {"name": "AutoExec AI Pro Subscription"},
|
28 |
+
"unit_amount": 4900, # $49.00
|
29 |
},
|
30 |
"quantity": 1,
|
31 |
}],
|
32 |
mode="subscription",
|
33 |
+
success_url=SUCCESS_URL,
|
34 |
+
cancel_url=CANCEL_URL,
|
35 |
)
|
36 |
return session.url
|