Use this file to discover all available pages before exploring further.
Python SDK Dodo Payments API के लिए एक Pythonic इंटरफेस प्रदान करता है, जो अनुरोधों और प्रतिक्रियाओं के लिए प्रकार परिभाषाएँ के साथ समकालिक और असमकालिक क्लाइंट दोनों को प्रदान करता है। यह Python 3.9+ का समर्थन करता है और इसमें व्यापक परीक्षण कवरेज शामिल है।
SDK को Python 3.9 या उससे ऊपर की आवश्यकता होती है। सर्वोत्तम अनुभव और सुरक्षा अपडेट्स के लिए हम Python का नवीनतम स्थिर संस्करण उपयोग करने की सलाह देते हैं।
import osfrom dodopayments import DodoPaymentsclient = DodoPayments( bearer_token=os.environ.get("DODO_PAYMENTS_API_KEY"), # This is the default and can be omitted environment="test_mode", # defaults to "live_mode")checkout_session_response = client.checkout_sessions.create( product_cart=[ { "product_id": "product_id", "quantity": 1 } ],)print(checkout_session_response.session_id)
# Create a subscriptionsubscription = client.subscriptions.create( billing={ "country": "US", "city": "San Francisco", "state": "CA", "street": "1 Market St", "zipcode": "94105", }, customer={"customer_id": "cus_123"}, # or {"email": "...", "name": "..."} for a new customer product_id="pdt_456", quantity=1,)# Charge an on-demand subscription# product_price is in the lowest currency denomination (e.g., 2500 = $25.00 USD)charge_response = client.subscriptions.charge( subscription_id=subscription.subscription_id, product_price=2500,)# Retrieve usage history (for metered subscriptions)usage_history = client.subscriptions.retrieve_usage_history( subscription_id=subscription.subscription_id, start_date="2024-01-01T00:00:00Z",)
billing कम से कम दो-अक्षर का ISO देश कोड आवश्यक है। customer या तो मौजूदा ग्राहक को संलग्न करने के लिए {"customer_id": ...} या एक नया बनाने के लिए {"email": ..., "name": ...} को स्वीकार करता है। product_price सबसे छोटे मुद्रा संप्रदाय में है।
# Get a specific eventevent = client.usage_events.retrieve("api_call_12345")# List events with filteringevents = client.usage_events.list( customer_id="cus_abc123", event_name="api_request", limit=20)for event in events.data: print(f"Event: {event.event_id} at {event.timestamp}")
from dodopayments import DodoPaymentsclient = DodoPayments()all_payments = []# Automatically fetches more pages as neededfor payment in client.payments.list(): all_payments.append(payment)print(all_payments)
# Access items from current pagefirst_page = client.payments.list()for payment in first_page.items: print(payment.brand_id)# Check for more pagesif first_page.has_next_page(): next_page = first_page.get_next_page() print(f"Fetched {len(next_page.items)} more items")