-
Notifications
You must be signed in to change notification settings - Fork 67
Migration guide for v4
chargebee-php now requires PHP >= 8.1.
- The namespace
ChargeBeehas been renamed toChargebee. - Models now follow the namespace
use Chargebee\Resources\*;instead ofuse ChargeBee\ChargeBee\Models\*;.
The way to initialize the Chargebee client has changed.
Before:
use ChargeBee\ChargeBee\Models\Environment;
Environment::configure("{site}", "{site_api_key}"); Now:
use Chargebee\ChargebeeClient;
$chargebee = new ChargebeeClient([
"site" => "{site}",
"apiKey" => "{site_api_key}",
]);Users no longer need to import individual classes for operations.
Before:
use ChargeBee\ChargeBee\Environment;
use ChargeBee\ChargeBee\Models\Customer;
Environment::configure("{site}", "{site_api_key}");
$result = Customer::retrieve("{customer-id}");Now:
use Chargebee\ChargebeeClient;
$chargebee = new ChargebeeClient([
"site" => "{site}",
"apiKey" => "{site_api_key}",
]);
$response = $chargebee->customer()->retrieve("{customer-id}");The response will no longer return a global Result class; instead, it returns a specific response class for each action.
Before:
$customerResponse = Customer::retrieve("{customer-id}");
$subscriptionResponse = Subscription::retrieve("{customer-id}");
echo get_class($customerResponse) . "\n";
echo get_class($subscriptionResponse) . "\n";Output:
ChargeBee\ChargeBee\Result
ChargeBee\ChargeBee\ResultNow:
$customerResponse = $chargebee->customer()->retrieve("{customer-id}");
$subscriptionResponse = $chargebee->subscription()->retrieve("{subs-id}");
echo get_class($customerResponse) . "\n";
echo get_class($subscriptionResponse) . "\n";Output:
Chargebee\Responses\CustomerResponse\RetrieveCustomerResponse
Chargebee\Responses\SubscriptionResponse\RetrieveSubscriptionResponsePreviously, response properties in Chargebee were accessed using method calls (e.g., $customer = $response->customer();). In the updated version, response properties are now accessed directly as object properties (e.g., $customer = $response->customer;).
Input parameters have changed from camelCase to snake_case.
Before:
$result = Subscription::createWithItems("{customer-id}", array(
"subscriptionItems" => array(
array(
"itemPriceId" => "day-pass-USD",
"unitPrice" => 100
),
array(
"itemPriceId" => "basic-USD",
"billingCycles" => 2,
"quantity" => 1
)
)
));Now:
$result = $chargebee->subscription()->createWithItems("{customer-id}", [
"subscription_items" => [
[
"item_price_id" => "day-pass-USD",
"unit_price" => 100
],
[
"item_price_id" => "basic-USD",
"billing_cycles" => 2,
"quantity" => 1
]
]
]);Properties of the model class have been changed from camelCase to snake_case.
Before:
$result = Customer::retrieve("{customer-id}");
$customer = $result->customer();
$firstName = $customer->firstName();Now:
$result = $chargebee->customer()->retrieve("{customer-id}");
$customer = $result->customer;
$firstName = $customer->first_name;The way to pass filters in list APIs has been updated.
Before:
$result = Subscription::all([
"status[in]" => ["cancelled"],
"limit" => 2,
]);Now:
$result = $chargebeeClient->subscription()->all([
"status" => ["in" => ["cancelled"]],
"limit" => 2,
]);Before:
$result = Subscription::all([
"id[is]" => "{subscription-id}"
]);Now:
$result = $chargebee->subscription()->all([
"id" => ["is" => "{subscription-id}"]
]);