Use this file to discover all available pages before exploring further.
L’SDK PHP fornisce un modo robusto e flessibile per integrare Dodo Payments nelle tue applicazioni PHP. Costruito seguendo gli standard PHP moderni con autoloading PSR-4, offre una copertura di test estesa e documentazione dettagliata.
L’SDK utilizza parametri nominati per specificare argomenti opzionali. Puoi inizializzare gli oggetti di valore usando il costruttore statico with:
<?phpuse Dodopayments\Customers\AttachExistingCustomer;// Recommended: Use static 'with' constructor with named parameters$customer = AttachExistingCustomer::with(customerID: "customer_id");
Sono disponibili anche builder come pattern alternativo:
<?phpuse Dodopayments\Customers\AttachExistingCustomer;// Alternative: Use builder pattern$customer = (new AttachExistingCustomer)->withCustomerID("customer_id");
Alcuni errori vengono riprovati automaticamente 2 volte per impostazione predefinita con un breve backoff esponenziale. I seguenti errori attivano il ripristino automatico:
Errori di connessione (problemi di connettività di rete)
408 Request Timeout
409 Conflict
429 Rate Limit
500+ Errori interni
Timeout
Configura il comportamento dei tentativi globalmente o per singola richiesta:
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 richiede almeno il codice ISO a due lettere country. Passa AttachExistingCustomer::with(customerID: '...') per collegare un cliente esistente, o NewCustomer::with(email: '...', name: '...') per crearne uno. productPrice è nella denominazione valutaria più bassa.
$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);}
Quando la libreria non può connettersi all’API o riceve un codice di stato non di successo (4xx o 5xx), viene lanciata una sottoclasse di 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();}