Spaces:
Build error
Build error
import os | |
import streamlit as st | |
import stripe | |
import requests | |
import time | |
# Set your secret key. Remember to switch to your live secret key in production! | |
stripe.api_key = os.environ["STRIPE_API_KEY"] | |
# Function to simulate checking payment status (for demo purposes) | |
def check_payment_status(session_id): | |
try: | |
session = stripe.checkout.Session.retrieve(session_id) | |
return session.payment_status == 'paid' | |
except stripe.error.StripeError as e: | |
st.error(f"Error checking payment status: {e}") | |
return False | |
# Streamlit app | |
st.title("Stripe Payment Integration") | |
# Button to redirect to Stripe Checkout | |
if st.button("Go to Checkout"): | |
checkout_url = "https://buy.stripe.com/14kbLG4FV5s509OdQV" | |
st.markdown(f"[Proceed to Checkout]({checkout_url})", unsafe_allow_html=True) | |
# Input for session ID to check payment status | |
session_id = st.text_input("Enter your Stripe Session ID after payment:") | |
if st.button("Check Payment Status"): | |
if session_id: | |
st.write("Checking payment status, please wait...") | |
time.sleep(2) # Simulating delay for payment processing | |
if check_payment_status(session_id): | |
st.success("Payment successful!") | |
st.write("Here's the paid content.") | |
else: | |
st.error("Payment not completed yet. Please try again.") | |
else: | |
st.error("Please enter a valid session ID.") | |