mgbam commited on
Commit
134719e
Β·
verified Β·
1 Parent(s): 7f140e5

Update stripe_checkout.py

Browse files
Files changed (1) hide show
  1. stripe_checkout.py +6 -17
stripe_checkout.py CHANGED
@@ -3,30 +3,19 @@
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",
 
3
  import os
4
  import stripe
5
 
 
6
  stripe.api_key = os.getenv("STRIPE_API_KEY")
7
 
8
+ PRICE_ID = os.getenv("PRICE_ID")
9
+ SUCCESS_URL = os.getenv("SUCCESS_URL")
10
+ CANCEL_URL = os.getenv("CANCEL_URL")
11
+ if not all([PRICE_ID, SUCCESS_URL, CANCEL_URL]):
12
+ raise RuntimeError("❌ PRICE_ID, SUCCESS_URL or CANCEL_URL missing in secrets")
 
 
 
13
 
14
  def create_stripe_session():
 
 
 
15
  session = stripe.checkout.Session.create(
16
  payment_method_types=["card"],
17
  line_items=[{
18
+ "price": PRICE_ID, # ← Use your recurring Price ID
 
 
 
 
19
  "quantity": 1,
20
  }],
21
  mode="subscription",