Update stripe_checkout.py
Browse files- stripe_checkout.py +20 -11
stripe_checkout.py
CHANGED
|
@@ -1,25 +1,34 @@
|
|
| 1 |
# stripe_checkout.py
|
| 2 |
|
| 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 |
-
|
| 19 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
}],
|
| 21 |
mode="subscription",
|
| 22 |
-
success_url=SUCCESS_URL,
|
| 23 |
-
cancel_url=CANCEL_URL,
|
| 24 |
)
|
| 25 |
return session.url
|
|
|
|
| 1 |
# stripe_checkout.py
|
| 2 |
|
|
|
|
| 3 |
import stripe
|
| 4 |
+
import os
|
| 5 |
|
| 6 |
stripe.api_key = os.getenv("STRIPE_API_KEY")
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def create_stripe_session():
|
| 9 |
+
"""
|
| 10 |
+
Creates a Stripe Checkout Session using dynamic price_data.
|
| 11 |
+
No pre‑configured Price object required.
|
| 12 |
+
"""
|
| 13 |
session = stripe.checkout.Session.create(
|
| 14 |
payment_method_types=["card"],
|
| 15 |
line_items=[{
|
| 16 |
+
# Dynamically define the price here:
|
| 17 |
+
"price_data": {
|
| 18 |
+
"currency": "usd",
|
| 19 |
+
"product_data": {
|
| 20 |
+
"name": "AutoExec AI Pro Subscription",
|
| 21 |
+
"description": "Unlimited AI business launches & analytics"
|
| 22 |
+
},
|
| 23 |
+
"unit_amount": 4900, # $49.00 in cents
|
| 24 |
+
"recurring": {
|
| 25 |
+
"interval": "month"
|
| 26 |
+
}
|
| 27 |
+
},
|
| 28 |
+
"quantity": 1
|
| 29 |
}],
|
| 30 |
mode="subscription",
|
| 31 |
+
success_url=os.getenv("SUCCESS_URL", "https://your-domain.com/success"),
|
| 32 |
+
cancel_url=os.getenv("CANCEL_URL", "https://your-domain.com/cancel"),
|
| 33 |
)
|
| 34 |
return session.url
|