Spaces:
Sleeping
Sleeping
import os | |
import streamlit as st | |
import time | |
from utils.helper import create_checkout_session, check_payment_status | |
# Streamlit app | |
st.set_page_config(layout="wide") | |
st.title("Stripe Payment Integration π³") | |
# Sidebar for payment processing | |
st.sidebar.title("Payment Section π") | |
if 'session_id' not in st.session_state: | |
st.session_state.session_id = None | |
if 'payment_checked' not in st.session_state: | |
st.session_state.payment_checked = False | |
# Button to redirect to Stripe Checkout | |
if st.sidebar.button("Create Checkout Session"): | |
session_id, checkout_url = create_checkout_session() | |
if session_id and checkout_url: | |
st.session_state.session_id = session_id | |
st.session_state.payment_checked = False | |
st.sidebar.markdown(f"[Proceed to Checkout]({checkout_url})", unsafe_allow_html=True) | |
# Input for session ID to check payment status | |
if st.session_state.session_id: | |
st.sidebar.write(f"Your session ID: {st.session_state.session_id}") | |
if st.sidebar.button("Check Payment Status"): | |
st.sidebar.write("Checking payment status, please wait... β³") | |
time.sleep(2) # Simulating delay for payment processing | |
if check_payment_status(st.session_state.session_id): | |
st.session_state.payment_checked = True | |
st.success("Payment successful! π") | |
st.sidebar.write("Payment successful! π") | |
else: | |
st.sidebar.error("Payment not completed yet. Please try again. β") | |
# Display the paid content on the main page if payment is successful | |
if st.session_state.payment_checked: | |
with st.sidebar: | |
# Embed Airtable after the download button | |
st.markdown("### Any questions or feedback?") | |
st.markdown(""" | |
<iframe class="airtable-embed" src="https://airtable.com/embed/appSl7NmyGNWEHtjs/shrDWlWLV1yVZpW7V" frameborder="0" onmousewheel="" width="100%" height="533" style="background: transparent; border: 1px solid #ccc;"></iframe> | |
""", unsafe_allow_html=True) | |
st.markdown("## Here's the paid content. π") | |
if st.button("Click for More Info"): | |
st.write("Here is the additional information for paid users! π") | |
else: | |
st.info("Create a checkout session to get the session ID. π") | |