Use this file to discover all available pages before exploring further.
El SDK de Python ofrece una interfaz Pythonic para la API de Dodo Payments, proporcionando tanto clientes síncronos como asíncronos con definiciones de tipo para solicitudes y respuestas. Soporta Python 3.9+ e incluye una cobertura de pruebas completa.
El SDK requiere Python 3.9 o posterior. Recomendamos usar la versión estable más reciente de Python para obtener la mejor experiencia y las actualizaciones de seguridad.
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 requiere como mínimo el código de país ISO de dos letras. customer acepta {"customer_id": ...} para adjuntar un cliente existente o {"email": ..., "name": ...} para crear uno nuevo. product_price está en la denominación más baja de la moneda.
# 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}")
Iterar automáticamente a través de todos los elementos:
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")