This is the official PHP library for integrating with Chargebee.
- 📘 For a complete reference of available APIs, check out our API Documentation.
- 🧪 To explore and test API capabilities interactively, head over to our API Explorer.
Note: Chargebee now supports two API versions - V1 and V2, of which V2 is the latest release and all future developments will happen in V2. This library is for API version V2. If you’re looking for V1, head to chargebee-v1 branch.
PHP 8.1 or later
Chargebee
is available on Packagist and can be installed using Composer
composer require chargebee/chargebee-php
To use the bindings,
require_once('vendor/autoload.php');
use Chargebee\ChargebeeClient;
$chargebee = new ChargebeeClient(options: [
"site" => "{your_site}",
"apiKey" => "{your_apiKey}",
]);
$result = $chargebee->subscription()->createWithItems("customer_id", [
"subscription_items" => [
[
"item_price_id" => "Montly-Item",
"quantity" => "3",
]
]
]);
$subscription = $result->subscription;
$customer = $result->customer;
Idempotency keys are passed along with request headers to allow a safe retry of POST requests.
use Chargebee\ChargebeeClient;
$chargebee = new ChargebeeClient(options: [
"site" => "{your_site}",
"apiKey" => "{your_apiKey}",
]);
$responseCustomer = $chargebee->customer()->create([
"first_name" => "John",
"last_name" => "Doe",
"email" => "john@test.com",
"card" => [
"first_name" => "Joe",
"last_name" => "Doe",
"number" => "4012888888881881",
"expiry_month" => "10",
"expiry_year" => "29",
"cvv" => "231"
]
],
[
"chargebee-idempotency-key" => "<<UUID>>" // Replace <<UUID>> with a unique string
]
);
$responseHeaders = $responseCustomer->getResponseHeaders(); // Retrieves response headers
print_r($responseHeaders);
$idempotencyReplayedValue = $responseCustomer->isIdempotencyReplayed(); // Retrieves Idempotency replayed header value
print_r($idempotencyReplayedValue);
isIdempotencyReplayed()
method can be accessed to differentiate between original and replayed requests.
See the LICENSE file.