Event.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. class ChargeBee_Event extends ChargeBee_Model
  3. {
  4. protected $allowed = array('id', 'occurredAt', 'source', 'user', 'webhookStatus', 'webhookFailureReason',
  5. 'webhooks', 'eventType', 'apiVersion');
  6. public function content()
  7. {
  8. return new ChargeBee_Content($this->_values['content']);
  9. }
  10. public static function deserialize($json)
  11. {
  12. $webhookData = json_decode($json, true);
  13. if(!$webhookData) {
  14. throw new Exception("Response not in JSON format. Might not be a ChargeBee webhook call.");
  15. }
  16. if($webhookData != null)
  17. {
  18. if( isset($webhookData['api_version']) ) {
  19. $apiVersion = strtoupper($webhookData['api_version']);
  20. if($apiVersion != null && strcasecmp($apiVersion, ChargeBee_Environment::API_VERSION) != 0){
  21. throw new RuntimeException("API version [".$apiVersion."] in response does not match "
  22. ."with client library API version [".strtoupper(ChargeBee_Environment::API_VERSION)."]");
  23. }
  24. }
  25. return new ChargeBee_Event($webhookData);
  26. }
  27. return null;
  28. }
  29. # OPERATIONS
  30. #-----------
  31. public static function all($params = array(), $env = null, $headers = array())
  32. {
  33. return ChargeBee_Request::sendListRequest(ChargeBee_Request::GET, ChargeBee_Util::encodeURIPath("events"), $params, $env, $headers);
  34. }
  35. public static function retrieve($id, $env = null, $headers = array())
  36. {
  37. return ChargeBee_Request::send(ChargeBee_Request::GET, ChargeBee_Util::encodeURIPath("events",$id), array(), $env, $headers);
  38. }
  39. }
  40. ?>