awacke1 commited on
Commit
ecffc04
Β·
1 Parent(s): e89eda1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import stripe
3
+
4
+ # Initialize Stripe API
5
+ stripe.api_key = "sk_test_your_secret_key_here"
6
+
7
+ # Streamlit UI
8
+ st.title("Stripe API Demo with Streamlit πŸ˜ƒ")
9
+
10
+ # Create Customer πŸ˜‡
11
+ if st.button("Create Customer"):
12
+ customer = stripe.Customer.create(
13
+ name="John Doe",
14
+ email="[email protected]",
15
+ )
16
+ st.write(f"Customer Created: {customer['id']} πŸŽ‰")
17
+
18
+ # Retrieve Customer πŸ•΅οΈ
19
+ if st.button("Retrieve Customer"):
20
+ customer = stripe.Customer.retrieve(customer['id'])
21
+ st.write(f"Customer Retrieved: {customer['id']} πŸ•΅οΈ")
22
+
23
+ # Update Customer πŸ”„
24
+ if st.button("Update Customer"):
25
+ customer = stripe.Customer.modify(
26
+ customer['id'],
27
+ name="Jane Doe",
28
+ )
29
+ st.write(f"Customer Updated: {customer['name']} πŸ”„")
30
+
31
+ # Delete Customer πŸ—‘οΈ
32
+ if st.button("Delete Customer"):
33
+ deleted_customer = stripe.Customer.delete(customer['id'])
34
+ st.write(f"Customer Deleted: {deleted_customer['id']} πŸ—‘οΈ")
35
+
36
+ # Create Payment Intent πŸ’°
37
+ if st.button("Create Payment Intent"):
38
+ payment_intent = stripe.PaymentIntent.create(
39
+ amount=1000,
40
+ currency="usd",
41
+ )
42
+ st.write(f"Payment Intent Created: {payment_intent['id']} πŸ’°")
43
+
44
+ # Confirm Payment Intent βœ…
45
+ if st.button("Confirm Payment Intent"):
46
+ confirmed_payment = stripe.PaymentIntent.confirm(payment_intent['id'])
47
+ st.write(f"Payment Intent Confirmed: {confirmed_payment['status']} βœ…")
48
+
49
+ # Cancel Payment Intent ❌
50
+ if st.button("Cancel Payment Intent"):
51
+ canceled_payment = stripe.PaymentIntent.cancel(payment_intent['id'])
52
+ st.write(f"Payment Intent Canceled: {canceled_payment['status']} ❌")
53
+
54
+ # List Payment Intents πŸ“‹
55
+ if st.button("List Payment Intents"):
56
+ payment_intents = stripe.PaymentIntent.list(limit=3)
57
+ st.write(f"Payment Intents Listed: {[p['id'] for p in payment_intents['data']]} πŸ“‹")