chargebee / chargebee-php Goto Github PK
View Code? Open in Web Editor NEWPHP library for the Chargebee API.
Home Page: https://apidocs.chargebee.com/docs/api?lang=php
License: MIT License
PHP library for the Chargebee API.
Home Page: https://apidocs.chargebee.com/docs/api?lang=php
License: MIT License
For a production environment. The lib/ChargeBee/Environment.php with these defaults:
public static $connectTimeoutInSecs = 30;
public static $requestTimeoutInSecs = 80;
This is a bit too generous and can block php-fpm workers from serving other requests.
Be able to pass in object or an array as a second optional parameter.
Perhaps it makes most sense here to pass in second optional argument
ChargeBee_Environment::configure
No response
No response
When a property of a Model is supposed to be a list of some subtype (for example taxes
of the InvoiceEstimate
), but the ChargeBee returns 0 items in the list, the list is not becoming an empty array, but an (empty) instance of the list type.
It looks like that this can be fixed by isHash
function (inside ChargeBee_Model
) returning false not only when not being an array, but also when the array is empy.
private function isHash($array)
{
if (!is_array($array) || count($array) === 0)
return false;
foreach (array_keys($array) as $k) {
if (is_numeric($k))
return false;
}
return true;
}
The lib/ChargeBee.php
file currently loads all of this library's code. It would be nice to adopt autoloading as provided by composer. This would be easier to do after #23 is done.
Hello,
For Composer based usage specifying ext-json
in composer.json require field would be better than the runtime validation used in AbstractChargeBee, allowing composer to check for the presence of the extensions at install time rather than seeing the error at runtime.
Line 8 in 6d94561
I can submit this as a PR if relevant.
Hi there :)
I would like to send a payload as JSON to Chargebee API but it only works in URL encoded format, not in JSON format.
I need to send JSON from the requests Python package without the Chargebee wrapper.
Any idea?
$ curl https://***********-test.chargebee.com/api/v2/payment_sources/create_card \
> -u **************************************:\
> -d customer_id="cbdemo_douglas" \
> -d card[number]="378282246310005" \
> -d card[cvv]="100" \
> -d card[expiry_year]=2022 \
> -d card[expiry_month]=12
{
"payment_source": {
"id": "pm_BTcLSfTGD1TtShje",
"updated_at": 1662057402,
"resource_version": 1662057402861,
...
}
}
}
$ curl https://***********-test.chargebee.com/api/v2/payment_sources/create_card \
> -u **************************************:\
> -H 'content-type: application/json' \
> -H 'accept: application/json' \
> -d '{
> "customer_id":"cbdemo_douglas",
> "card":{
> "number":"378282246310005",
> "cvv":"100",
> "expiry_year":"2022",
> "expiry_month":"12"
> }
> }'
{"message":"customer_id : cannot be blank","type":"invalid_request","api_error_code":"invalid_request","param":"customer_id","error_code":"param_required","error_msg":"cannot be blank","error_param":"customer_id","http_status_code":400}
I have a few custom fields in my ChargeBee instance, one of which is called cf_push_licenses. When I try to push changes to ChargeBee with that field set, I get a big fat exception:
ChargeBee_InvalidRequestException: cf_push_licenses : not in allowed values in ChargeBee_Curl::handleAPIRespError() (line 90 of chargebee-php/lib/ChargeBee/Curl.php).
Does the PHP API not support custom fields, or have I done something wrong?
Previous versions as 2.8.2 ( which is what i have installed right now ) is working fine with guzzlehttp/guzzle ^7.0 ( which is what i have installed right now ). Newest version (3.1.0) requires guzzlehttp/guzzle ^6.5 to be installed. Is there a way to handle this? Can you increase the minimum guzzlehttp/guzzle version?
Let's take a look at ListResult.php
.
Here are the key facts:
_items
and _index
properties (by the way, underscore is unnecessary)_items
with the result recordsoffsetExists
), setting (offsetSet
) and removing (offsetUnset
) offsets affects arbitrary propertiesoffsetGet
) access the undefined/magic list
propertycurrent
/ valid
) actually works with _items
propertySo from my understand:
foreach($result as $k => $v){
echo "$k=$v"; // produces for example 0=somevalue
}
echo "0={$result[0]}"; // produces 0=null instead of 0=somevalue
As I see from lib/ChargeBee/Request.php:39
, response originally contains items inside list
index....so to sum this all up:
response
property does not contain the original response, but rather the value of response['list']
offset*
methods are buggy (they either get arbitrary properties or for offsetGet
, the non-existent 'list' property)This really should be a package that can be brought in via composer. Is this planned?
I'm trying to update the subscription for a customer in which I change the addons and completely replace the old one, but it seems to be not working. It just keeps adding the addons to the current list in chargebee.
ChargeBee\ChargeBee\Models\Subscription::update($cb_id, [
"addons" => $newAddons,
"replaceAddonList" => true
]);
When data is being seriazled it is losing the prefix.
For example I was using the function HostedPage::checkoutOneTime. My data array looked something like this
$data = [
'customer' => ['email'=> '[email protected]', 'id' => '_test12345_'],
'addons' => ['id'=> ['test-addon']]]
as per the documentation - https://apidocs.chargebee.com/docs/api/hosted_pages?prod_cat_ver=1&lang=curl#checkout_one-time_payments
However after Util::serialize is called the data is being transformed like the following'
$serialized = ['customer[email]' => '[email protected]', 'customer[id]' => '_test12345_', 'id[0]' => 'test-addon']
As you can seem the addons prefix is missing from the serialized data causing addon selection not working.
But I am not even sure why you are calling Util::serialize to begin with?? You are using guzzle, pass in the data array directly into. So skip the whole $ser_params = Util::serialize($params);
pass $params directly into Guzzle::doRequest
Getting an error of
Use of undefined constant s - assumed 's' (this will throw an Error in a future version of PHP)
From
chargebee/chargebee-php/lib/ChargeBee/Curl.php
seems to be coming from line 41 which is
array_push($httpHeaders, 'Accept: application/json', "User-Agent: " . $userAgent , "Lang-Version: " . phpversion() , "OS-Version: " . php_uname(s). " " . php_uname(m) . " " . php_uname(r)); // Adding headers to array
Hello Chargebee,
We've been having problems testing the client API provided with the Chargebee SDK, and for the past few meetings we've been thinking about modernizing the code to make it more testable.
It would greatly improve our experience of integrating with Chargebee. Currently we implement the required abstraction in our code, but the possibilities are limited this way. We feel that improving the open source client is more future-proof and beneficial than re-writing the API integration on our side.
Main points we would like to address with such redesign are:
Would you be interested in such a contribution?
From the "Error handling" section of the API docs :
If you receive an HTTP 429 Too Many Requests error response to an API call, it means that the API requests for your Chargebee site have exceeded acceptable limits. Chargebee may also send a Retry-After header indicating the time duration to wait before sending a new request.
But on a HTTP 429 error, trhe Chargebee-php library throws an OperationFailedException, and offers no way to access the response headers, and thus no way to read the "Retry-After" value sent by Chargbee API.
Since #4 is already open for more than a year, I decided to open a new issue with more or less the same problem.
When using the Chargebee autoload with Laravel (composer), all files are being loaded because Chargebee.php requires every single class used in this project.
Please help, im new to the devolopment field.
How do integrate chargebee bee with codeigniter
Would be nice if you could implement namespaces in the whole library
Hey guys,
Thanks for the quality work.
I've started using Product Family feature as a beta user.
Required classes are present in the Models folder however they're not "required" in ChargeBee.php file.
In order to test out these features I needed to modify the files and remove ChargeBee from composer.
I can make a PR if you guys need help so that I can use ChargeBee as a composer package.
In the method \ChargeBee_Model::__get
there is a bug affecting snake case fields:
public function __get($k)
{
if (isset($this->_data[$k]))
{
return $this->_data[$k];
}
else if(in_array($k, $this->allowed))
{
return null;
}
The property allowed
contains snake case fields (i.e. "CustomerBillingAddress" has "first_name").
However "_data" field contains keys already converted to camelCase. See line 131 of the same file:
$this->_data[ChargeBee_Util::toCamelCaseFromUnderscore($k)] = $setVal;
So if the first name in billing address is empty, both $billingAddress->first_name
and $billingAddress->firstName
throws an error.
Expected result: if the field is empty it should return null
The discount model isn't included in release
Can we add a function in ChargeBee_Model to get array values? It will be useful to serialize them in DB and restore them back later.
class ChargeBee_Model
{
...
function getValues()
{
return $this->_values;
}
}
Hi,
We are using Chargebee for almost 2 months. Sometimes we are getting errors that disturbs our services. When we check the logs we found that sometimes ItemFamilies response that returns from Chargebee API in not a valid json format. For this reason we cannot list ItemFamilies to our customers in some cases. We are using Chargebee API V2
Following is our code that returns all of the ItemFamilies from Chargebee API
$families = collect();
$itemFamilies = \ChargeBee_ItemFamily::all();
foreach ($itemFamilies as $itemFamily) {
$families->add($itemFamily->itemFamily()->GetValues());
}
return $families;
in some cases we get he following error
ERROR: Response not in JSON format. Might not be a ChargeBee Response. {"exception":"[object] (Exception(code: 0): Response not in JSON format. Might not be a ChargeBee Response. at /application/zeus/vendor/chargebee/chargebee-php/lib/ChargeBee/Curl.php:78)"}
when we check the code we can see that Chargebee's API response is not a valid json response
public static function processResponse($response, $httpCode) {
$respJson = json_decode($response, true);
if(!$respJson){
throw new Exception("Response not in JSON format. Might not be a ChargeBee Response.");
}
if ($httpCode < 200 || $httpCode > 299) {
self::handleAPIRespError($httpCode, $respJson,$response);
}
return $respJson;
}
You have to utilities function that use this:
toCamelCaseFromUnderscore
toUnderscoreFromCamelCase
We're having a hard time understanding whether there's a mistake in the classnames and namespaces. Is it Chargebee or ChargeBee?
Open a class.
See ChargeBee.
See Chargebee throughout the naming.
No response
Linux
PHP 8.3
latest
No response
Deprecated: Return type of ChargeBee_ListResult::rewind() should either be compatible with Iterator::rewind(): void,
or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Deprecated: Return type of ChargeBee_ListResult::offsetExists($k) should either be compatible with
ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily
suppress the notice
Deprecated: Return type of ChargeBee_ListResult::offsetGet($k) should either be compatible with
ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily
suppress the notice
Deprecated: Return type of ChargeBee_ListResult::offsetSet($k, $v) should either be compatible with
ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to
temporarily suppress the notice
Deprecated: Return type of ChargeBee_ListResult::offsetUnset($k) should either be compatible with
ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily
suppress the notice
Deprecated: Return type of ChargeBee_ListResult::current() should either be compatible with Iterator::current(): mixed, or
the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Deprecated: Return type of ChargeBee_ListResult::next() should either be compatible with Iterator::next(): void, or the
[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Deprecated: Return type of ChargeBee_ListResult::key() should either be compatible with Iterator::key(): mixed, or the
[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Deprecated: Return type of ChargeBee_ListResult::valid() should either be compatible with Iterator::valid(): bool, or the
[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Deprecated: Return type of ChargeBee_ListResult::rewind() should either be compatible with Iterator::rewind(): void, or the
[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
PHP version: 8.1
Package version: 2.8.3
Getting a warning in PHP 8.2:
Function utf8_encode() is deprecated in vendor/chargebee/chargebee-php/lib/ChargeBee/Guzzle.php on line 20
Hello,
It would be nice if we can have documentation in our IDE when using your \ChargeBee_Model
classes.
The implementation of \JsonSerializable
can be also useful.
Namespace support is nice too but not really useful every day.
Thanks.
I noticed some confusing inconsistencies with some of the models.
Invoice::$allowed
uses camel casing for attributes.
LineItem::$allowed
however, uses snake case with underscores.
It'd be easier to work with these objects if there was a common style.
On a second related note, it would be hugely beneficial when working with these classes if the properties were documented using PHPDoc in a way that most IDEs support.
For example:
/**
* @property string $id
* @property string $subscription_id
* @property int $date_from
* ...
*/
class ChargeBee_InvoiceLineItem extends ChargeBee_Model
{
On ChargeBee_Model class
public function __toString() { return json_encode($this->_values); }
Code that triggers the error from API:
$all = ChargeBee_Subscription::all([
"limit" => 100, // 100 is max
"sortBy[asc]" => "updated_at",
"itemId[is]" => $pp_free_plan_id,
]);
From Documentation
itemId[<operator>]
The plan item code.
Supported operators : is, isNot, startsWith, in, notIn
Example โ "itemId[is]" => "silver"
optional, string filter
Traceback:
\/chargebee\/vendor\/chargebee\/chargebee-php\/lib\/ChargeBee\/Guzzle.php(102): ChargeBee\\ChargeBee\\Guzzle::handleAPIRespError(400, Array, '{\"message\":\"ite...')\n#1
\/chargebee\/vendor\/chargebee\/chargebee-php\/lib\/ChargeBee\/Guzzle.php(27): ChargeBee\\ChargeBee\\Guzzle::processResponse('{\"message\":\"ite...', 400)\n#2
\/chargebee\/vendor\/chargebee\/chargebee-php\/lib\/ChargeBee\/Request.php(36): ChargeBee\\ChargeBee\\Guzzle::doRequest('get', '\/subscriptions', Object(ChargeBee\\ChargeBee\\Environment), Array, Array)\n#3
\/chargebee\/vendor\/chargebee\/chargebee-php\/lib\/ChargeBee\/Request.php(22): ChargeBee\\ChargeBee\\Request::send('get', '\/subscriptions', Array, Object(ChargeBee\\ChargeBee\\Environment), Array)\n#4
\/chargebee\/vendor\/chargebee\/chargebee-php\/lib\/ChargeBee\/Models\/Subscription.php(109): ChargeBee\\ChargeBee\\Request::sendListRequest('get', '\/subscriptions', Array, NULL, Array)\n#5
\/chargebee\/chargebee.php(46): ChargeBee\\ChargeBee\\Models\\Subscription::all(Array)\n```
Our account has hierarchy enabled. But when I try to load a customer with a hierarchy it fails because the class is not loaded.
Error messages:
Error: Class 'ChargeBee_CustomerParentAccountAccess' not found
Error: Class 'ChargeBee_CustomerChildAccountAccess' not found
Following on from #40, I am experiencing a whole bunch of deprecation notices in my application originating from the chargebee/chargebee-php
project.
User Deprecated: Method "Countable::count()" might add "int" as a native return type declaration in the future. Do the same in implementation "ChargeBee\ChargeBee\ListResult" now to avoid errors or add an explicit @return annotation to suppress this message.
User Deprecated: Method "ArrayAccess::offsetSet()" might add "void" as a native return type declaration in the future. Do the same in implementation "ChargeBee\ChargeBee\ListResult" now to avoid errors or add an explicit @return annotation to suppress this message.
User Deprecated: Method "ArrayAccess::offsetUnset()" might add "void" as a native return type declaration in the future. Do the same in implementation "ChargeBee\ChargeBee\ListResult" now to avoid errors or add an explicit @return annotation to suppress this message.
I am on v3.13.0 and PHP 8.1.14.
Noticed this when testing on Linux. Working fine on Windows.
In lib/init.php
, line 193, "content.php" should be "Content.php".
Change line 193 from:
require(dirname(__FILE__) . '/ChargeBee/Models/content.php');
to
require(dirname(__FILE__) . '/ChargeBee/Models/Content.php');
Hi everyone,
I'm using this package to handle subscriptions in my project
it's already in PC2.0
the issue that whenever I call ChargeBee_Subscription::create method I get the following error :
This API operation is not enabled for this site. Please contact [email protected] to get this enabled
Whereas I can use the other endpoints without any issue!
When I do the following it works just fine :
$result = ChargeBee_Customer::create(array(
"firstName" => "John",
"lastName" => "Doe",
"email" => "[email protected]",
"locale" => "fr-CA",
"billingAddress" => array(
"firstName" => "John",
"lastName" => "Doe",
"line1" => "PO Box 9999",
"city" => "Walnut",
"state" => "California",
"zip" => "91789",
"country" => "US",
),
));
ChargeBee_PaymentSource::createUsingToken(array(
"customerId" => "customer_id",
"tokenId" => "cb_token",
));
ChargeBee_Subscription::createWithItems("customer_id", array(
"subscriptionItems" => array(
array(
"itemPriceId" => "plan_id",
"quantity" => 1,
"itemType" => "plan"),
),
));
Though when doing the following it doesn't work :
$result = ChargeBee_Subscription::create(array(
"planId" => 'plan_id',
"autoCollection" => "off",
"billingAddress" => array(
"firstName" => "John",
"lastName" => "Doe",
"line1" => "PO Box 9999",
"city" => "Walnut",
"state" => "California",
"zip" => "91789",
"country" => "US"
),
"customer" => array(
"firstName" => "John",
"lastName" => "Doe",
"email" => "[email protected]"
)
));
Could you help me to know the reason?
Error I am getting when testing my Webhook URL:
<br />
<b>Fatal error</b>: Uncaught Exception: Unknown property currency_code in ChargeBee_Subscription in /www/pf/chargebee/lib/ChargeBee/Model.php:75
Stack trace:
#0 /www/cb-events.php(27): ChargeBee_Model->__get('currency_code')
#1 {main}
thrown in <b>/www/pf/chargebee/lib/ChargeBee/Model.php</b> on line <b>75</b><br />
I'm currently getting a error exception thrown back when using webhooks. When using the ChargeBee_Event::deserialize($json)
value with an underscore is failing to be found. I tracked this down to line 75 of the following below. I ended up commenting out throw new Exception("Unknown property $k in " . get_class($this));
for now to solve my issue.
public function __get($k)
{
if (isset($this->_data[$k]))
{
return $this->_data[$k];
}
else if(in_array($k, $this->allowed))
{
return null;
}
else if(substr($k, 0, 2) == "cf") //All the custom fields start with prefix cf.
{
return null;
}
else
{
throw new Exception("Unknown property $k in " . get_class($this));
}
}
Versions:
Code triggering error:
$cb_subscriptions = ChargeBee_Subscription::all([
"limit" => 100,
"offset" => $offset,
"sortBy[asc]" => "updated_at"
]);
Stack trace:
PHP Fatal error: Uncaught Error: Call to undefined method GuzzleHttp\\Utils::chooseHandler() in \/vendor\/guzzlehttp\/guzzle\/src\/functions.php:61
Stack trace:\n
#0 \/vendor\/guzzlehttp\/guzzle\/src\/HandlerStack.php(42): GuzzleHttp\\choose_handler()
#1 \/vendor\/guzzlehttp\/guzzle\/src\/Client.php(65): GuzzleHttp\\HandlerStack::create()
#2 \/vendor\/chargebee\/chargebee-php\/lib\/ChargeBee\/Guzzle.php(32): GuzzleHttp\\Client->__construct()
#3 \/vendor\/chargebee\/chargebee-php\/lib\/ChargeBee\/Guzzle.php(26): ChargeBee\\ChargeBee\\Guzzle::request('get', '\/subscriptions', Object(ChargeBee\\ChargeBee\\Environment), Array, Array)
#4 \/vendor\/chargebee\/chargebee-php\/lib\/ChargeBee\/Request.php(36): ChargeBee\\ChargeBee\\Guzzle::doRequest('get', '\/subscriptions', Object(ChargeBee\\ChargeBee\\Environment), Array, Array)
#5 \/vendor\/chargebee\/chargebee-php\/lib\/ChargeBee\/Request.php(22): ChargeBee\\ChargeBee\\Request::send('get', '\/subscriptions', Array, Object(ChargeBee\\ChargeBee\\Environment), Array)
#6 \/vendor\/chargebee\/chargebee-php\/lib\/ChargeBee\/Models\/Subscription.php(109): ChargeBee\\ChargeBee\\Request::sendListRequest('get', '\/subscriptions', Array, NULL, Array)
#7 \/chargebee.php(51): ChargeBee\\ChargeBee\\Models\\Subscription::all(Array)
I've noticed that this repo is now on version 2.6.0 in tags but packagist is still showing v2.5.9 as the highest available.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.