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/ */
dodopayments / client example snippets
use Dodopayments\Client;
use Dodopayments\CheckoutSessions\CheckoutSessionCreateParams\ProductCart;
$client = new Client(
bearerToken: getenv("DODO_PAYMENTS_API_KEY") ?: "My Bearer Token",
environment: "test_mode",
);
$checkoutSessionResponse = $client->checkoutSessions->create(
productCart: [ProductCart::with(productID: "product_id", quantity: 0)]
);
var_dump($checkoutSessionResponse->session_id);
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\CheckoutSessions\CheckoutSessionCreateParams\ProductCart;
use Dodopayments\Core\Exceptions\APIConnectionException;
try {
$checkoutSessionResponse = $client->checkoutSessions->create(
productCart: [ProductCart::with(productID: "product_id", quantity: 0)]
);
} catch (APIConnectionException $e) {
echo "The server could not be reached", PHP_EOL;
var_dump($e->getPrevious());
} catch (RateLimitError $_) {
echo "A 429 status code was received; we should back off a bit.", PHP_EOL;
} catch (APIStatusError $e) {
echo "Another non-200-range status code was received", PHP_EOL;
echo $e->getMessage();
}
use Dodopayments\Client;
use Dodopayments\RequestOptions;
use Dodopayments\CheckoutSessions\CheckoutSessionCreateParams\ProductCart;
// Configure the default for all requests:
$client = new Client(maxRetries: 0);
// Or, configure per-request:
$result = $client->checkoutSessions->create(
productCart: [ProductCart::with(productID: "product_id", quantity: 0)],
requestOptions: RequestOptions::with(maxRetries: 5),
);