1. Go to this page and download the library: Download dodopayments/client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Dodopayments\Client;
$client = new Client(
bearerToken: getenv('DODO_PAYMENTS_API_KEY') ?: 'My Bearer Token',
environment: 'test_mode',
);
$page = $client->payments->list();
var_dump($page);
// fetch items from the current page
foreach ($page->getItems() as $item) {
var_dump($item->brand_id);
}
// make additional network requests to fetch items from all pages, including and after the current page
foreach ($page->pagingEachItem() as $item) {
var_dump($item->brand_id);
}
use Dodopayments\Core\Exceptions\APIConnectionException;
use Dodopayments\Core\Exceptions\RateLimitException;
use Dodopayments\Core\Exceptions\APIStatusException;
try {
$checkoutSessionResponse = $client->checkoutSessions->create(
productCart: [['productID' => 'pdt_example', 'quantity' => 1]]
);
} catch (APIConnectionException $e) {
echo "The server could not be reached", PHP_EOL;
var_dump($e->getPrevious());
} catch (RateLimitException $e) {
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();
}
use Dodopayments\Client;
// Configure the default for all requests:
$client = new Client(requestOptions: ['maxRetries' => 0]);
// Or, configure per-request:
$result = $client->checkoutSessions->create(
productCart: [['productID' => 'pdt_example', 'quantity' => 1]],
requestOptions: ['maxRetries' => 5],
);