Use this file to discover all available pages before exploring further.
O SDK PHP fornece uma maneira robusta e flexível de integrar os pagamentos Dodo em suas aplicações PHP. Construído seguindo os padrões modernos de PHP com autoloading PSR-4, oferece ampla cobertura de testes e documentação detalhada.
O SDK usa parâmetros nomeados para especificar argumentos opcionais. Você pode inicializar objetos de valor usando o construtor estático with:
<?phpuse Dodopayments\Customers\AttachExistingCustomer;// Recommended: Use static 'with' constructor with named parameters$customer = AttachExistingCustomer::with(customerID: "customer_id");
Construtores também estão disponíveis como um padrão alternativo:
<?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 requer no mínimo o código country de dois dígitos ISO. Passe AttachExistingCustomer::with(customerID: '...') para anexar um cliente existente, ou NewCustomer::with(email: '...', name: '...') para criar um. productPrice está na menor denominação de moeda.
$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 a biblioteca não consegue se conectar à API ou recebe um código de status de não-sucesso (4xx ou 5xx), uma subclasse de APIException é lançada:
<?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();}