Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,52 +1,42 @@
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import stripe
|
3 |
-
import
|
|
|
4 |
|
5 |
# Set your secret key. Remember to switch to your live secret key in production!
|
6 |
stripe.api_key = os.environ["STRIPE_API_KEY"]
|
7 |
|
8 |
-
# Function to
|
9 |
-
def
|
10 |
-
try:
|
11 |
-
product = stripe.Product.retrieve(product_id)
|
12 |
-
price = stripe.Price.list(product=product_id)
|
13 |
-
return product, price.data[0]
|
14 |
-
except Exception as e:
|
15 |
-
st.error(f"Error fetching product information: {e}")
|
16 |
-
return None, None
|
17 |
-
|
18 |
-
# Function to create a checkout session
|
19 |
-
def create_checkout_session(price_id):
|
20 |
try:
|
21 |
-
session = stripe.checkout.Session.
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
}],
|
27 |
-
mode='payment',
|
28 |
-
success_url='https://buy.stripe.com/14kbLG4FV5s509OdQV',
|
29 |
-
cancel_url='https://www.future-minds.io/',
|
30 |
-
)
|
31 |
-
return session.url
|
32 |
-
except Exception as e:
|
33 |
-
st.error(f"Error creating checkout session: {e}")
|
34 |
-
return None
|
35 |
|
36 |
# Streamlit app
|
37 |
-
st.title("Stripe
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
import streamlit as st
|
4 |
import stripe
|
5 |
+
import requests
|
6 |
+
import time
|
7 |
|
8 |
# Set your secret key. Remember to switch to your live secret key in production!
|
9 |
stripe.api_key = os.environ["STRIPE_API_KEY"]
|
10 |
|
11 |
+
# Function to simulate checking payment status (for demo purposes)
|
12 |
+
def check_payment_status(session_id):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
try:
|
14 |
+
session = stripe.checkout.Session.retrieve(session_id)
|
15 |
+
return session.payment_status == 'paid'
|
16 |
+
except stripe.error.StripeError as e:
|
17 |
+
st.error(f"Error checking payment status: {e}")
|
18 |
+
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
# Streamlit app
|
21 |
+
st.title("Stripe Payment Integration")
|
22 |
+
|
23 |
+
# Button to redirect to Stripe Checkout
|
24 |
+
if st.button("Go to Checkout"):
|
25 |
+
checkout_url = "https://buy.stripe.com/14kbLG4FV5s509OdQV"
|
26 |
+
st.markdown(f"[Proceed to Checkout]({checkout_url})", unsafe_allow_html=True)
|
27 |
+
|
28 |
+
# Input for session ID to check payment status
|
29 |
+
session_id = st.text_input("Enter your Stripe Session ID after payment:")
|
30 |
+
|
31 |
+
if st.button("Check Payment Status"):
|
32 |
+
if session_id:
|
33 |
+
st.write("Checking payment status, please wait...")
|
34 |
+
time.sleep(2) # Simulating delay for payment processing
|
35 |
+
|
36 |
+
if check_payment_status(session_id):
|
37 |
+
st.success("Payment successful!")
|
38 |
+
st.write("Here's the paid content.")
|
39 |
+
else:
|
40 |
+
st.error("Payment not completed yet. Please try again.")
|
41 |
+
else:
|
42 |
+
st.error("Please enter a valid session ID.")
|