File size: 1,415 Bytes
eed0f39
 
dc4966e
 
eed0f39
 
dc4966e
 
 
 
eed0f39
 
dc4966e
eed0f39
 
 
 
 
dc4966e
 
eed0f39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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.")