eagle0504 commited on
Commit
edacdd6
·
verified ·
1 Parent(s): 4a98305

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -35
app.py CHANGED
@@ -44,41 +44,26 @@ st.title("Stripe Payment Integration")
44
  if 'session_id' not in st.session_state:
45
  st.session_state.session_id = None
46
 
47
- def list_prices_for_product(product_id):
48
- try:
49
- prices = stripe.Price.list(product=product_id)
50
- return prices
51
- except Exception as e:
52
- print(f"Error listing prices: {e}")
53
- return None
54
-
55
- # Example usage
56
- product_id = stripe_product_id # Replace with your actual Product ID
57
- prices = list_prices_for_product(product_id)
58
-
59
- if prices:
60
- for price in prices.data:
61
- print(f"Price ID: {price.id}, Amount: {price.unit_amount}, Currency: {price.currency}")
62
 
63
- # # Button to redirect to Stripe Checkout
64
- # if st.button("Create Checkout Session"):
65
- # session_id, checkout_url = create_checkout_session()
66
- # if session_id and checkout_url:
67
- # st.session_state.session_id = session_id
68
- # st.write(f"Checkout URL: {checkout_url}")
69
- # st.markdown(f"[Proceed to Checkout]({checkout_url})", unsafe_allow_html=True)
70
 
71
- # # Input for session ID to check payment status
72
- # if st.session_state.session_id:
73
- # st.write(f"Your session ID: {st.session_state.session_id}")
74
- # if st.button("Check Payment Status"):
75
- # st.write("Checking payment status, please wait...")
76
- # time.sleep(2) # Simulating delay for payment processing
 
77
 
78
- # if check_payment_status(st.session_state.session_id):
79
- # st.success("Payment successful!")
80
- # st.write("Here's the paid content.")
81
- # else:
82
- # st.error("Payment not completed yet. Please try again.")
83
- # else:
84
- # st.info("Create a checkout session to get the session ID.")
 
44
  if 'session_id' not in st.session_state:
45
  st.session_state.session_id = None
46
 
47
+ # Button to redirect to Stripe Checkout
48
+ if st.button("Create Checkout Session"):
49
+ session_id, checkout_url = create_checkout_session()
50
+ if session_id and checkout_url:
51
+ st.session_state.session_id = session_id
52
+ st.write(f"Checkout URL: {checkout_url}")
53
+ st.markdown(f"[Proceed to Checkout]({checkout_url})", unsafe_allow_html=True)
 
 
 
 
 
 
 
 
54
 
55
+ # Input for session ID to check payment status
56
+ if st.session_state.session_id:
57
+ st.write(f"Your session ID: {st.session_state.session_id}")
58
+ if st.button("Check Payment Status"):
59
+ st.write("Checking payment status, please wait...")
60
+ time.sleep(2) # Simulating delay for payment processing
 
61
 
62
+ if check_payment_status(st.session_state.session_id):
63
+ st.success("Payment successful!")
64
+ st.write("Here's the paid content.")
65
+ else:
66
+ st.error("Payment not completed yet. Please try again.")
67
+ else:
68
+ st.info("Create a checkout session to get the session ID.")
69