Use this file to discover all available pages before exploring further.
SDK Python menawarkan antarmuka Pythonic untuk API Pembayaran Dodo, menyediakan klien sinkron dan asinkron dengan definisi tipe untuk permintaan dan respons. Ini mendukung Python 3.9+ dan mencakup cakupan pengujian yang komprehensif.
Untuk kinerja async yang lebih baik dengan aiohttp:
pip install dodopayments[aiohttp]
SDK ini membutuhkan Python 3.9 atau lebih tinggi. Kami menyarankan menggunakan versi stabil terbaru dari Python untuk pengalaman terbaik dan pembaruan keamanan.
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 membutuhkan minimal kode negara ISO dua huruf. customer menerima {"customer_id": ...} untuk melampirkan pelanggan yang ada atau {"email": ..., "name": ...} untuk membuat yang baru. product_price dalam denominasi mata uang terendah.
# 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")