Spaces:
Runtime error
Runtime error
| 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="john.doe@example.com", | |
| ) | |
| 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']]} π") | |