File size: 2,262 Bytes
eed0f39
dc4966e
eed0f39
9666f2d
dc4966e
 
7e9a3a0
 
eed0f39
7e9a3a0
 
f7b02d4
 
 
7e9a3a0
 
 
edacdd6
7e9a3a0
edacdd6
 
 
7e9a3a0
 
7f982fb
edacdd6
 
7e9a3a0
 
 
edacdd6
eed0f39
edacdd6
7e9a3a0
 
 
edacdd6
7e9a3a0
eed0f39
7e9a3a0
 
551abb7
 
 
 
 
 
 
 
7e9a3a0
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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. πŸ“‹")