Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import streamlit as st
|
| 3 |
-
import stripe
|
| 4 |
-
import requests
|
| 5 |
import time
|
| 6 |
-
|
| 7 |
-
# Set your secret key. Remember to switch to your live secret key in production!
|
| 8 |
-
stripe.api_key = os.environ["STRIPE_API_KEY"]
|
| 9 |
-
|
| 10 |
-
# Set the product id.
|
| 11 |
-
stripe_price_id = os.environ["STRIPE_PRICE_ID"]
|
| 12 |
-
|
| 13 |
-
# Function to create a Stripe Checkout Session
|
| 14 |
-
def create_checkout_session():
|
| 15 |
-
try:
|
| 16 |
-
session = stripe.checkout.Session.create(
|
| 17 |
-
payment_method_types=['card'],
|
| 18 |
-
line_items=[{
|
| 19 |
-
'price': stripe_price_id, # Replace with your actual Stripe price ID
|
| 20 |
-
'quantity': 1,
|
| 21 |
-
}],
|
| 22 |
-
mode='payment',
|
| 23 |
-
success_url="https://39701j614g.execute-api.us-east-1.amazonaws.com/dev/?sessionID={CHECKOUT_SESSION_ID}&key=123",
|
| 24 |
-
cancel_url="https://wyn-education.streamlit.app/",
|
| 25 |
-
)
|
| 26 |
-
return session.id, session.url
|
| 27 |
-
except Exception as e:
|
| 28 |
-
st.error(f"Error creating checkout session: {e}")
|
| 29 |
-
return None, None
|
| 30 |
-
|
| 31 |
-
# Function to check payment status
|
| 32 |
-
def check_payment_status(session_id):
|
| 33 |
-
try:
|
| 34 |
-
session = stripe.checkout.Session.retrieve(session_id)
|
| 35 |
-
return session.payment_status == 'paid'
|
| 36 |
-
except Exception as e:
|
| 37 |
-
st.error(f"Error checking payment status: {e}")
|
| 38 |
-
return False
|
| 39 |
|
| 40 |
# Streamlit app
|
| 41 |
st.set_page_config(layout="wide")
|
|
|
|
| 1 |
import os
|
| 2 |
import streamlit as st
|
|
|
|
|
|
|
| 3 |
import time
|
| 4 |
+
from utils.helper import create_checkout_session, check_payment_status
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Streamlit app
|
| 7 |
st.set_page_config(layout="wide")
|