1. Go to this page and download the library: Download chargebee/chargebee-php 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 Chargebee\ChargebeeClient;
// Retry Configurations
$retryConfig = new RetryConfig();
$retryConfig->setEnabled(true); // Enable retry mechanism
$retryConfig->setMaxRetries(5); // Maximum number of retries
$retryConfig->setDelayMs(1000); // Delay in milliseconds before retrying
$retryConfig->setRetryOn([500, 502, 503, 504]); // Retry on these HTTP status codes
$chargebee = new ChargebeeClient(options: [
"site" => "{your_site}",
"apiKey" => "{your_apiKey}",
"retryConfig" => $retryConfig,
]);
// ... your Chargebee API operations below ...
use Chargebee\ChargebeeClient;
// Retry Configurations
$retryConfig = new RetryConfig();
$retryConfig->setEnabled(true); // Enable retry mechanism
$retryConfig->setMaxRetries(5); // Maximum number of retries
$retryConfig->setDelayMs(1000); // Delay in milliseconds before retrying
$retryConfig->setRetryOn([429]); // Retry on 429 HTTP status codes
$chargebee = new ChargebeeClient(options: [
"site" => "{your_site}",
"apiKey" => "{your_apiKey}",
"retryConfig" => $retryConfig,
]);
// ... your Chargebee API operations below ...
use Chargebee\ChargebeeClient;
use Chargebee\Telemetry\RequestTelemetryContext;
use Chargebee\Telemetry\RequestTelemetryResult;
use Chargebee\Telemetry\TelemetryAdapter;
use OpenTelemetry\API\Trace\Propagation\TraceContextPropagator;
use OpenTelemetry\API\Trace\SpanInterface;
use OpenTelemetry\API\Trace\SpanKind;
use OpenTelemetry\API\Trace\StatusCode;
use OpenTelemetry\API\Trace\TracerInterface;
class OtelTelemetryAdapter implements TelemetryAdapter
{
public function __construct(private readonly TracerInterface $tracer) {}
public function onRequestStart(RequestTelemetryContext $context, array &$requestHeaders): mixed
{
$span = $this->tracer
->spanBuilder($context->spanName)
->setSpanKind(SpanKind::KIND_CLIENT)
->setAttributes($context->startAttributes)
->startSpan();
$scope = $span->activate();
TraceContextPropagator::getInstance()->inject($requestHeaders);
$scope->detach();
return $span;
}
public function onRequestEnd(mixed $handle, RequestTelemetryResult $result): void
{
if (!$handle instanceof SpanInterface) {
return;
}
$span = $handle;
$span->setAttributes($result->endAttributes);
if ($result->error !== null) {
$span->setStatus(StatusCode::STATUS_ERROR, $result->error->message);
} else {
$span->setStatus(StatusCode::STATUS_OK);
}
$span->end();
}
}
$tracer = \OpenTelemetry\API\Globals::tracerProvider()->getTracer('your-app');
$chargebee = new ChargebeeClient([
'site' => '{your_site}',
'apiKey' => '{your_apiKey}',
'telemetryAdapter' => new OtelTelemetryAdapter($tracer),
]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.