Use this file to discover all available pages before exploring further.
PHP SDK:n erbjuder ett robust och flexibelt sätt att integrera Dodo Payments i dina PHP-applikationer. Byggd enligt moderna PHP-standarder med PSR-4 autoloading, erbjuder den omfattande testtäckning och detaljerad dokumentation.
SDK:t använder namngivna parametrar för att ange valfria argument. Du kan initiera värdeobjekt med den statiska with-konstruktorn:
<?phpuse Dodopayments\Customers\AttachExistingCustomer;// Recommended: Use static 'with' constructor with named parameters$customer = AttachExistingCustomer::with(customerID: "customer_id");
Byggare finns också som ett alternativt mönster:
<?phpuse Dodopayments\Customers\AttachExistingCustomer;// Alternative: Use builder pattern$customer = (new AttachExistingCustomer)->withCustomerID("customer_id");
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 kräver minst den tvåbokstaviga ISO country-koden. Skicka AttachExistingCustomer::with(customerID: '...') för att ansluta en befintlig kund, eller NewCustomer::with(email: '...', name: '...') för att skapa en. productPrice är i den lägsta valutadenominationen.
$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);}
När biblioteket inte kan ansluta till API:et eller får tillbaka en statuskod som inte indikerar framgång (4xx eller 5xx), kastas en subklass av 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();}