Integre os pagamentos Dodo em suas aplicações PHP com um SDK moderno e compatível com PSR-4
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:
Copiar
<?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:
Copiar
<?phpuse Dodopayments\Customers\AttachExistingCustomer;// Alternative: Use builder pattern$customer = (new AttachExistingCustomer)->withCustomerID("customer_id");
$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 não bem-sucedido (4xx ou 5xx), uma subclasse de APIException é lançada:
Copiar
<?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();}