Use this file to discover all available pages before exploring further.
El SDK de PHP proporciona una forma robusta y flexible de integrar Dodo Payments en tus aplicaciones PHP. Construido siguiendo los estándares modernos de PHP con autoloading PSR-4, ofrece una amplia cobertura de pruebas y documentación detallada.
El SDK utiliza parámetros nombrados para especificar argumentos opcionales. Puedes inicializar objetos de valor usando el constructor estático with:
<?phpuse Dodopayments\Customers\AttachExistingCustomer;// Recommended: Use static 'with' constructor with named parameters$customer = AttachExistingCustomer::with(customerID: "customer_id");
También hay constructores disponibles como patrón alternativo:
<?phpuse Dodopayments\Customers\AttachExistingCustomer;// Alternative: Use builder pattern$customer = (new AttachExistingCustomer)->withCustomerID("customer_id");
Ciertos errores se reintentan automáticamente 2 veces por defecto con un retroceso exponencial corto. Los siguientes errores activan reintentos automáticos:
Errores de conexión (problemas de conectividad de red)
408 Request Timeout
409 Conflict
429 Rate Limit
500+ Internal errors
Timeouts
Configura el comportamiento de reintentos de forma global o por solicitud:
use Dodopayments\Customers\AttachExistingCustomer;use Dodopayments\Payments\BillingAddress;// Create a subscription$subscription = $client->subscriptions->create( billing: BillingAddress::with( country: 'US', city: 'San Francisco', state: 'CA', street: '1 Market St', zipcode: '94105', ), customer: AttachExistingCustomer::with(customerID: 'cus_123'), productID: 'pdt_456', quantity: 1,);// Charge an on-demand subscription// productPrice is in the lowest currency denomination (e.g., 2500 = $25.00 USD)$charge = $client->subscriptions->charge( $subscription->subscription_id, productPrice: 2500,);
billing requiere al menos el código country ISO de dos letras. Pase AttachExistingCustomer::with(customerID: '...') para adjuntar un cliente existente, o NewCustomer::with(email: '...', name: '...') para crear uno. productPrice está en la denominación más baja de la moneda.
$page = $client->payments->list();var_dump($page);// Fetch items from the current pageforeach ($page->getItems() as $item) { var_dump($item->brand_id);}// Auto-paginate: fetch items from all pagesforeach ($page->pagingEachItem() as $item) { var_dump($item->brand_id);}
Cuando la biblioteca no puede conectarse a la API o recibe un código de estado negativo (4xx o 5xx), se lanza una subclase de APIException:
<?phpuse Dodopayments\Core\Exceptions\APIConnectionException;use Dodopayments\Core\Exceptions\RateLimitException;use Dodopayments\Core\Exceptions\APIStatusException;try { $checkoutSessionResponse = $client->checkoutSessions->create( productCart: [["productID" => "product_id", "quantity" => 1]] );} catch (APIConnectionException $e) { echo "The server could not be reached", PHP_EOL; var_dump($e->getPrevious());} catch (RateLimitException $_) { echo "A 429 status code was received; we should back off a bit.", PHP_EOL;} catch (APIStatusException $e) { echo "Another non-200-range status code was received", PHP_EOL; echo $e->getMessage();}
Siempre envuelva llamadas API en bloques try-catch para manejar posibles errores
de manera elegante y proporcionar retroalimentación significativa a los usuarios.