Integra Dodo Payments nelle tue applicazioni PHP con un SDK moderno e conforme a PSR-4
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:
Copia
<?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:
Copia
<?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:
$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 riesce a connettersi all’API o riceve un codice di stato non di successo (4xx o 5xx), viene sollevata una sottoclasse di APIException:
Copia
<?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();}