Use this file to discover all available pages before exploring further.
Il SDK Python offre un’interfaccia Pythonica per l’API Dodo Payments, fornendo sia client sincroni che asincroni con definizioni di tipo per richieste e risposte. Supporta Python 3.9+ e include una copertura di test completa.
L’SDK richiede Python 3.9 o versioni successive. Consigliamo di utilizzare l’ultima versione stabile di Python per offrire la migliore esperienza e gli aggiornamenti di sicurezza.
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 richiede almeno il codice ISO del paese a due lettere. customer accetta {"customer_id": ...} per allegare un cliente esistente o {"email": ..., "name": ...} per crearne uno nuovo. product_price è nella denominazione più bassa della valuta.
# 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}")
Iterare automaticamente attraverso tutti gli elementi:
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")