diff --git a/composer.json b/composer.json index 3ff61e8f..d4b42585 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "fig/http-message-util": "1.*", "ramsey/uuid": "^3 || ^4", "lcobucci/jwt": "^3.4.6 || ^4.0.4", + "lcobucci/clock": "~2.0.0 || ^2.1.0", "nesbot/carbon": "^2.52 || ^3.0.0", "ext-fileinfo": "*" }, diff --git a/src/AmoCRM/Client/AmoCRMApiRequest.php b/src/AmoCRM/Client/AmoCRMApiRequest.php index 7c6d0372..6507a161 100644 --- a/src/AmoCRM/Client/AmoCRMApiRequest.php +++ b/src/AmoCRM/Client/AmoCRMApiRequest.php @@ -36,7 +36,7 @@ class AmoCRMApiRequest public const CONNECT_TIMEOUT = 5; public const REQUEST_TIMEOUT = 20; //TODO Do not forget to change this on each release - public const LIBRARY_VERSION = '1.7.0'; + public const LIBRARY_VERSION = '1.7.2'; public const USER_AGENT = 'amoCRM-API-Library/' . self::LIBRARY_VERSION; public const SUCCESS_STATUSES = [ diff --git a/src/AmoCRM/Models/CustomFieldsValues/ValueModels/ItemsCustomFieldValueModel.php b/src/AmoCRM/Models/CustomFieldsValues/ValueModels/ItemsCustomFieldValueModel.php index f5a078ec..acf968a9 100644 --- a/src/AmoCRM/Models/CustomFieldsValues/ValueModels/ItemsCustomFieldValueModel.php +++ b/src/AmoCRM/Models/CustomFieldsValues/ValueModels/ItemsCustomFieldValueModel.php @@ -149,8 +149,11 @@ public static function fromArray($value): BaseCustomFieldValueModel ->setBonusPointsPerPurchase($val[self::FIELD_BONUS_POINTS_PER_PURCHASE] ?? null) ->setMetadata($val[self::FIELD_METADATA] ?? null) ->setIsDiscountRecalculated($val[self::FIELD_IS_DISCOUNT_RECALCULATED] ?? false) - ->setIsTotalSumRecalculated($val[self::FIELD_IS_TOTAL_SUM_RECALCULATED] ?? false) - ->setTotalSum($val[self::FIELD_TOTAL_SUM] ?? null); + ->setIsTotalSumRecalculated($val[self::FIELD_IS_TOTAL_SUM_RECALCULATED] ?? false); + + if (isset($val[self::FIELD_TOTAL_SUM])) { + $model->setTotalSum((float)$val[self::FIELD_TOTAL_SUM]); + } return $model; } @@ -392,7 +395,7 @@ public function setMetadata(?array $metadata): ItemsCustomFieldValueModel */ public function getIsDiscountRecalculated(): bool { - return $this->isDiscountRecalculated; + return $this->isDiscountRecalculated ?? false; } /** @@ -412,7 +415,7 @@ private function setIsDiscountRecalculated(bool $isDiscountRecalculated): ItemsC */ public function getIsTotalSumRecalculated(): bool { - return $this->isTotalSumRecalculated; + return $this->isTotalSumRecalculated ?? false; } /** @@ -432,7 +435,7 @@ private function setIsTotalSumRecalculated(bool $isTotalSumRecalculated): ItemsC */ public function getTotalSum(): float { - return $this->totalSum; + return $this->totalSum ?? 0; } /** diff --git a/src/AmoCRM/Models/Factories/NoteFactory.php b/src/AmoCRM/Models/Factories/NoteFactory.php index 3ea10f18..4609b80b 100644 --- a/src/AmoCRM/Models/Factories/NoteFactory.php +++ b/src/AmoCRM/Models/Factories/NoteFactory.php @@ -2,6 +2,7 @@ namespace AmoCRM\Models\Factories; +use AmoCRM\Models\NoteType\AiResultNote; use AmoCRM\Exceptions\InvalidArgumentException; use AmoCRM\Models\NoteModel; use AmoCRM\Models\NoteType\AmoMailMessageNote; @@ -58,6 +59,7 @@ class NoteFactory * Данное событие отличается от invoice_paid тем, что вызывает событие Счет оплачен в Digital Pipeline */ public const NOTE_TYPE_CODE_BILL_PAID = 'bill_paid'; + public const NOTE_TYPE_AI_RESULT = 'ai_result'; /** * @param string $type @@ -132,6 +134,8 @@ public static function createForType(string $type, array $note) case self::NOTE_TYPE_CODE_BILL_PAID: return (new BillPaidNote())->fromArray($note); break; + case self::NOTE_TYPE_AI_RESULT: + return (new AiResultNote())->fromArray($note); default: return (new NoteModel())->fromArray($note); break; diff --git a/src/AmoCRM/Models/NoteType/AiResultNote.php b/src/AmoCRM/Models/NoteType/AiResultNote.php new file mode 100644 index 00000000..44247d0d --- /dev/null +++ b/src/AmoCRM/Models/NoteType/AiResultNote.php @@ -0,0 +1,177 @@ +setText((string)$note['params']['text']); + } + + if (isset($note['params']['answer_id'])) { + $model->setAnswerId((string)$note['params']['answer_id']); + } + + if (isset($note['params']['talk_id'])) { + $model->setTalkId((int)$note['params']['text']); + } + + if (isset($note['params']['is_error'])) { + $model->setHasError((bool)$note['params']['is_error']); + } + + return $model; + } + + /** + * @inheritDoc + */ + public function toArray(): array + { + $result = parent::toArray(); + + $result['params']['text'] = $this->getText(); + $result['params']['answer_id'] = $this->getAnswerId(); + $result['params']['talk_id'] = $this->getTalkId(); + $result['params']['is_error'] = $this->hasError(); + + return $result; + } + + /** + * @param string|null $requestId + * @return array + */ + public function toApi(?string $requestId = "0"): array + { + $result = parent::toApi($requestId); + + $result['params']['text'] = $this->getText(); + $result['params']['answer_id'] = $this->getAnswerId(); + $result['params']['talk_id'] = $this->getTalkId(); + $result['params']['is_error'] = $this->hasError(); + + return $result; + } + + /** + * @return string + */ + public function getAnswerId(): string + { + return $this->answerId; + } + + /** + * @param string|null $answerId + * + * @return AiResultNote + */ + public function setAnswerId(string $answerId): AiResultNote + { + $this->answerId = $answerId; + + return $this; + } + + /** + * @return int + */ + public function getTalkId(): int + { + return $this->talkId; + } + + /** + * @param int $talkId + * + * @return AiResultNote + */ + public function setTalkId(int $talkId): AiResultNote + { + $this->talkId = $talkId; + + return $this; + } + + /** + * @return string + */ + public function getText(): string + { + return $this->text; + } + + /** + * @param string $text + * + * @return AiResultNote + */ + public function setText(string $text): AiResultNote + { + $this->text = $text; + + return $this; + } + + /** + * @return bool + */ + public function hasError(): bool + { + return $this->hasError; + } + + /** + * @param bool $hasError + * + * @return AiResultNote + */ + public function setHasError(bool $hasError): AiResultNote + { + $this->hasError = $hasError; + + return $this; + } +}