eagle0504 commited on
Commit
cad5a0d
·
verified ·
1 Parent(s): 49d41d7

Create utils/helper.py

Browse files
Files changed (1) hide show
  1. utils/helper.py +36 -0
utils/helper.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import stripe
3
+ import streamlit as st
4
+
5
+ # Set your secret key. Remember to switch to your live secret key in production!
6
+ stripe.api_key = os.environ["STRIPE_API_KEY"]
7
+
8
+ # Set the product id.
9
+ stripe_price_id = os.environ["STRIPE_PRICE_ID"]
10
+
11
+ # Function to create a Stripe Checkout Session
12
+ def create_checkout_session():
13
+ try:
14
+ session = stripe.checkout.Session.create(
15
+ payment_method_types=['card'],
16
+ line_items=[{
17
+ 'price': stripe_price_id, # Replace with your actual Stripe price ID
18
+ 'quantity': 1,
19
+ }],
20
+ mode='payment',
21
+ success_url='https://your-website.com/success?session_id={CHECKOUT_SESSION_ID}',
22
+ cancel_url='https://your-website.com/cancel',
23
+ )
24
+ return session.id, session.url
25
+ except Exception as e:
26
+ st.error(f"Error creating checkout session: {e}")
27
+ return None, None
28
+
29
+ # Function to check payment status
30
+ def check_payment_status(session_id):
31
+ try:
32
+ session = stripe.checkout.Session.retrieve(session_id)
33
+ return session.payment_status == 'paid'
34
+ except Exception as e:
35
+ st.error(f"Error checking payment status: {e}")
36
+ return False