File size: 1,263 Bytes
cad5a0d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2d3ab4d
 
cad5a0d
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import stripe
import streamlit as st

# Set your secret key. Remember to switch to your live secret key in production!
stripe.api_key = os.environ["STRIPE_API_KEY"]

# Set the product id. 
stripe_price_id = os.environ["STRIPE_PRICE_ID"]

# Function to create a Stripe Checkout Session
def create_checkout_session():
    try:
        session = stripe.checkout.Session.create(
            payment_method_types=['card'],
            line_items=[{
                'price': stripe_price_id,  # Replace with your actual Stripe price ID
                'quantity': 1,
            }],
            mode='payment',
            success_url="https://39701j614g.execute-api.us-east-1.amazonaws.com/dev/?sessionID={CHECKOUT_SESSION_ID}&key=123",
            cancel_url="https://wyn-education.streamlit.app/",
        )
        return session.id, session.url
    except Exception as e:
        st.error(f"Error creating checkout session: {e}")
        return None, None

# Function to check payment status
def check_payment_status(session_id):
    try:
        session = stripe.checkout.Session.retrieve(session_id)
        return session.payment_status == 'paid'
    except Exception as e:
        st.error(f"Error checking payment status: {e}")
        return False