awacke1's picture
Create app.py
ecffc04
import streamlit as st
import stripe
# Initialize Stripe API
stripe.api_key = "sk_test_your_secret_key_here"
# Streamlit UI
st.title("Stripe API Demo with Streamlit πŸ˜ƒ")
# Create Customer πŸ˜‡
if st.button("Create Customer"):
customer = stripe.Customer.create(
name="John Doe",
email="[email protected]",
)
st.write(f"Customer Created: {customer['id']} πŸŽ‰")
# Retrieve Customer πŸ•΅οΈ
if st.button("Retrieve Customer"):
customer = stripe.Customer.retrieve(customer['id'])
st.write(f"Customer Retrieved: {customer['id']} πŸ•΅οΈ")
# Update Customer πŸ”„
if st.button("Update Customer"):
customer = stripe.Customer.modify(
customer['id'],
name="Jane Doe",
)
st.write(f"Customer Updated: {customer['name']} πŸ”„")
# Delete Customer πŸ—‘οΈ
if st.button("Delete Customer"):
deleted_customer = stripe.Customer.delete(customer['id'])
st.write(f"Customer Deleted: {deleted_customer['id']} πŸ—‘οΈ")
# Create Payment Intent πŸ’°
if st.button("Create Payment Intent"):
payment_intent = stripe.PaymentIntent.create(
amount=1000,
currency="usd",
)
st.write(f"Payment Intent Created: {payment_intent['id']} πŸ’°")
# Confirm Payment Intent βœ…
if st.button("Confirm Payment Intent"):
confirmed_payment = stripe.PaymentIntent.confirm(payment_intent['id'])
st.write(f"Payment Intent Confirmed: {confirmed_payment['status']} βœ…")
# Cancel Payment Intent ❌
if st.button("Cancel Payment Intent"):
canceled_payment = stripe.PaymentIntent.cancel(payment_intent['id'])
st.write(f"Payment Intent Canceled: {canceled_payment['status']} ❌")
# List Payment Intents πŸ“‹
if st.button("List Payment Intents"):
payment_intents = stripe.PaymentIntent.list(limit=3)
st.write(f"Payment Intents Listed: {[p['id'] for p in payment_intents['data']]} πŸ“‹")