stripe-demo / app.py
eagle0504's picture
Update app.py
551abb7 verified
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. πŸ“‹")