Giter Club home page Giter Club logo

chargebee-php's People

Contributors

bcjumpstory avatar cb-alish avatar cb-ashik avatar cb-bharathvaj avatar cb-gaurav avatar cb-goutham avatar cb-karthikp avatar cb-khushbubibay avatar cb-navaneedhan avatar cb-nithins avatar cb-prajaktachavan avatar cb-sriramthiagarajan avatar cb-thiyagu avatar cb-thushitamariaselvan avatar cb-yateshmathuria avatar geoffreytran avatar hellokps avatar rraman avatar sangeethabaskaran avatar saravana-cb avatar vaibhav1510 avatar wojciechem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chargebee-php's Issues

To be able to change default timeouts in the Guzzle client

What problem does your feature request address?

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.

Describe the desired solution

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

Alternatives considered

No response

Additional context

No response

[Bug] Empty list (array) is converted to object

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;
    }

Utilize autoloading

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.

JSON payload issue

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?

As URL encoded: does work

$ 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,
        ...
        }
    }
}

As JSON: does not work

$ 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}

No custom fields support??

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?

v3.1.0 requires guzzlehttp/guzzle ^6.5

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?

Problems with ListResult.php

Let's take a look at ListResult.php.

Here are the key facts:

  • it defines _items and _index properties (by the way, underscore is unnecessary)
  • after construction / initialisation, it fills up _items with the result records
  • checking (offsetExists), setting (offsetSet) and removing (offsetUnset) offsets affects arbitrary properties
  • getting an offset (offsetGet) access the undefined/magic list property
  • looping (current / valid) actually works with _items property

So 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:

  • the 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)

Composer support

This really should be a package that can be brought in via composer. Is this planned?

Replace Addon List seems to be not working

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
  ]);

Util::serialize isnt serializing correctly

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

Php Version Issue

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

My current version of php is 7.3
screen shot 2019-03-08 at 8 16 10 am

Would you accept a contribution with redesigned client?

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:

  • using dependency inversion and PSR-18 abstraction over http client
  • ability to inject a mock http client, in order to simulate different types of network errors / responses

Would you be interested in such a contribution?

No way to retrieve the 'retry-after' header in case of 429 OperationFailedException

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.

Composer autoload

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.

Require Product Family and other upcoming features

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.

Magic getter method bug

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

Getting "Response not in JSON format. Might not be a ChargeBee Response" exception in some requests

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;
    }

Is is Chargebee or ChargeBee?

Description of the Bug

We're having a hard time understanding whether there's a mistake in the classnames and namespaces. Is it Chargebee or ChargeBee?

Steps to reproduce

Open a class.
See ChargeBee.

Expected Behavior

See Chargebee throughout the naming.

Code Snippets (if applicable)

No response

Operating System

Linux

Language version

PHP 8.3

Library version

latest

Additional context

No response

Deprecation warnings with PHP 8.1

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

Code documentation for IDE

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.

Improved attribute name consistency and documentation

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
{

Fetching subscriptions using parameter itemId results into error

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```

Class loader is not able to load all models

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

Deprecation notices on v3.13.0 and PHP 8.1.14

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.

Typo in init.php

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');

Create method doesn"t work for me

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?

Bug - Model.php throwing exception for underscored keys

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-&gt;__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));
		}
	}

Chargebee 3.2.0-rc.1 doesn't work with Guzzle 7

Versions:

  • chargebee-php:3.2.0-rc.1
  • guzzlehttp/guzzle: "7.4.0"

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.