diff --git a/src/Models/Answer.php b/src/Models/Answer.php index f81f241..d30991a 100644 --- a/src/Models/Answer.php +++ b/src/Models/Answer.php @@ -118,4 +118,17 @@ class Answer extends CrmClientModel $response = static::$apiInterface->call($request); return $response->status->equals(ApiStatus::OK()); } + + /** + * Serialize this object to an array + * + * @return array + */ + public function jsonSerialize() + { + return [ + 'id' => $this->id, + 'answer' => $this->answer + ]; + } } diff --git a/src/Models/ArcadiaMailDefault.php b/src/Models/ArcadiaMailDefault.php index 0ba1ecd..581d12e 100644 --- a/src/Models/ArcadiaMailDefault.php +++ b/src/Models/ArcadiaMailDefault.php @@ -254,4 +254,22 @@ class ArcadiaMailDefault extends CrmClientModel $this->isNew = !$status; return $status; } + + /** + * Serialize this object to an array + * + * @return array + */ + public function jsonSerialize() + { + return [ + 'operation' => $this->operation, + 'support_code' => $this->support_code, + 'label_type_support' => $this->label_type_support, + 'order_date' => $this->order_date, + 'order_num' => $this->order_num, + 'state_order' => $this->state_order, + 'package_unit_weight' => $this->package_unit_weight + ]; + } } diff --git a/src/Models/ArcadiaMailGame.php b/src/Models/ArcadiaMailGame.php index 718e842..1917fa9 100644 --- a/src/Models/ArcadiaMailGame.php +++ b/src/Models/ArcadiaMailGame.php @@ -171,4 +171,21 @@ class ArcadiaMailGame extends CrmClientModel $this->isNew = !$status; return $status; } + + /** + * Serialize this object to an array + * + * @return array + */ + public function jsonSerialize() + { + return [ + 'operation' => $this->operation, + 'support_code' => $this->support_code, + 'label_type_support' => $this->label_type_support, + 'order_date' => $this->order_date, + 'code_unique' => $this->code_unique, + 'code_on_pack' => $this->code_on_pack + ]; + } } diff --git a/src/Models/CrmClientModel.php b/src/Models/CrmClientModel.php index 8e06de5..4c9d754 100644 --- a/src/Models/CrmClientModel.php +++ b/src/Models/CrmClientModel.php @@ -3,6 +3,7 @@ namespace LDC\LDCCRM\Models; use Exception; +use JsonSerializable; use Kwaadpepper\Enum\BaseEnum; use LDC\LDCCRM\Enums\ArcadiaOrderType; use LDC\LDCCRM\Enums\Country; @@ -21,7 +22,7 @@ use TypeError; * @package LDCCrmClient * @subpackage models */ -abstract class CrmClientModel +abstract class CrmClientModel implements JsonSerializable { /** diff --git a/src/Models/Customer.php b/src/Models/Customer.php index 70a7da0..30f1352 100644 --- a/src/Models/Customer.php +++ b/src/Models/Customer.php @@ -581,8 +581,29 @@ class Customer extends CrmClientModel if ($e->getApiError()->equals(ApiError::authFailed())) { return false; } - throw $e; - } - return $response->status->equals(ApiStatus::OK()); + + /** + * Serialize this object to an array + * + * @return array + */ + public function jsonSerialize() + { + return [ + 'hashcode' => $this->hashcode, + 'email' => $this->email, + 'firstname' => $this->firstname, + 'lastname' => $this->lastname, + 'birth_date' => $this->birth_date, + 'phone' => $this->phone, + 'address' => $this->address, + 'address2' => $this->address2, + 'city' => $this->city, + 'postcode' => $this->postcode, + 'country' => $this->country, + 'opt_in' => $this->opt_in, + 'status' => $this->status, + 'last_connection' => $this->last_connection + ]; } } diff --git a/src/Models/Question.php b/src/Models/Question.php index ea5f845..20e3380 100644 --- a/src/Models/Question.php +++ b/src/Models/Question.php @@ -290,4 +290,19 @@ class Question extends CrmClientModel } return $out; } + + /** + * Serialize this object to an array + * + * @return array + */ + public function jsonSerialize() + { + return [ + 'id' => $this->id, + 'question' => $this->question, + 'type' => $this->type, + 'answers' => $this->answers + ]; + } }