Use this file to discover all available pages before exploring further.
O SDK Python oferece uma interface Pythonic para a API de Pagamentos Dodo, fornecendo tanto clientes síncronos quanto assíncronos com definições de tipo para requisições e respostas. Ele suporta Python 3.9+ e inclui uma cobertura de testes abrangente.
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 requer pelo menos o código de país ISO de duas letras. customer aceita {"customer_id": ...} para anexar um cliente existente ou {"email": ..., "name": ...} para criar um novo. product_price está na menor denominação de moeda.
# 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")