Use this file to discover all available pages before exploring further.
Das PHP SDK bietet eine robuste und flexible Möglichkeit, Dodo Payments in Ihre PHP-Anwendungen zu integrieren. Es wurde nach modernen PHP-Standards mit PSR-4-Autoloading entwickelt und bietet umfassende Testabdeckung sowie detaillierte Dokumentation.
Das SDK verwendet benannte Parameter, um optionale Argumente anzugeben. Sie können Value-Objekte mit dem statischen with-Konstruktor initialisieren:
<?phpuse Dodopayments\Customers\AttachExistingCustomer;// Recommended: Use static 'with' constructor with named parameters$customer = AttachExistingCustomer::with(customerID: "customer_id");
Builder sind ebenfalls als alternatives Muster verfügbar:
<?phpuse Dodopayments\Customers\AttachExistingCustomer;// Alternative: Use builder pattern$customer = (new AttachExistingCustomer)->withCustomerID("customer_id");
Bestimmte Fehler werden standardmäßig zweimal automatisch mit einem kurzen exponentiellen Backoff erneut versucht. Die folgenden Fehler lösen automatische Wiederholungen aus:
Verbindungsfehler (Netzwerkprobleme)
408 Request Timeout
409 Conflict
429 Rate Limit
500+ Internal errors
Timeouts
Konfigurieren Sie das Wiederholungsverhalten global oder pro Anfrage:
Erstellen und Verwalten wiederkehrender Abonnements:
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 benötigt mindestens den zweistelligen ISO country-Code. Übergeben Sie AttachExistingCustomer::with(customerID: '...'), um einen bestehenden Kunden zu verknüpfen, oder NewCustomer::with(email: '...', name: '...'), um einen zu erstellen. productPrice ist in der kleinsten Währungseinheit.
$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);}
Wenn die Bibliothek keine Verbindung zur API herstellen kann oder einen Statuscode ungleich Erfolg (4xx oder 5xx) erhält, wird eine Unterklasse von APIException ausgelöst:
<?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();}