In addition to the basic client, this repository also provides a version with a set of all models that are accessible via the Chargebee API. So instead of just calling the API endpoints and working with arrays, you can also choose to work with a set of helper methods to build you requests.
For example, if you want to call the /subscriptions endpoint you can either do it via the client, or you can use the Request Builder that we call the SDK.
<?php
$client = new \Chargebee\Chargebee($site, $apiKey);
$sdk = new \Chargebee\SDK($client);
You can also use the factory method to let the SDK create the client.
Using that SDK you now have access to a subscription property that you can use to call endpoints of the entity, in our example listing all subscriptions:
<?php
$sdk->subscriptions
->list();
You can even add constraints to the request by adding them to the chain
By enabling this flag, your response will no longer be a plain array, but an array of \Chargebee\Models\Subscription objects.
Internals
Internally, the \Chargebee\SDK will do nothing more than implement the magic getter (__get) by doing a lookup in the requests/ directory, checking if a model with that key exists.
It will then create instantiate an object and pass the client to it.
So basically, you could also skip the SDK and instantiate the Request Models them manually to run the queries for that entity.
The Request model also all have a hydrate() method implemented and a method that returns the response model so that you can return hydrated responses.
In addition to the basic client, this repository also provides a version with a set of all models that are accessible via the Chargebee API. So instead of just calling the API endpoints and working with arrays, you can also choose to work with a set of helper methods to build you requests.
For example, if you want to call the
/subscriptions
endpoint you can either do it via the client, or you can use the Request Builder that we call the SDK.You can also use the factory method to let the SDK create the client.
Using that SDK you now have access to a
subscription
property that you can use to call endpoints of the entity, in our example listing all subscriptions:You can even add constraints to the request by adding them to the chain
The response will now be an array, the same as you would call the
get()
method on the client.But you can also make use of our predefined models. Therefore, enable the flag of the sdk to hydrate models.
By enabling this flag, your response will no longer be a plain array, but an array of
\Chargebee\Models\Subscription
objects.Internals
Internally, the
\Chargebee\SDK
will do nothing more than implement the magic getter (__get
) by doing a lookup in therequests/
directory, checking if a model with that key exists.It will then create instantiate an object and pass the client to it.
So basically, you could also skip the SDK and instantiate the Request Models them manually to run the queries for that entity.
The Request model also all have a
hydrate()
method implemented and a method that returns the response model so that you can return hydrated responses.