Spaces:
Runtime error
Runtime error
Create app.py
Browse files
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']]} π")
|