chargebee / chargebee-php

PHP library for the Chargebee API.
https://apidocs.chargebee.com/docs/api?lang=php
MIT License
72 stars 62 forks source link

Bug - Model.php throwing exception for underscored keys #28

Closed jessedye closed 3 years ago

jessedye commented 4 years ago

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));
        }
    }
cb-rakesh commented 3 years ago

This has been fixed in v3.0.0