From 6a7f1b3cad6f0add82692890da596ef58352dcc4 Mon Sep 17 00:00:00 2001 From: egrigorev Date: Thu, 28 Mar 2024 23:50:20 +0300 Subject: [PATCH 01/12] add new type note ai result --- src/AmoCRM/Models/Factories/NoteFactory.php | 4 + src/AmoCRM/Models/NoteType/AiResultNote.php | 177 ++++++++++++++++++++ 2 files changed, 181 insertions(+) create mode 100644 src/AmoCRM/Models/NoteType/AiResultNote.php 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; + } +} From 716d48d839bcad98ea5a2d0693cfb6c8288e25d2 Mon Sep 17 00:00:00 2001 From: egrigorev Date: Fri, 29 Mar 2024 00:18:30 +0300 Subject: [PATCH 02/12] fix version --- src/AmoCRM/Client/AmoCRMApiRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AmoCRM/Client/AmoCRMApiRequest.php b/src/AmoCRM/Client/AmoCRMApiRequest.php index 53e5adea..fc686bcf 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.1'; public const USER_AGENT = 'amoCRM-API-Library/' . self::LIBRARY_VERSION; public const SUCCESS_STATUSES = [ From b3e9e62be9ee80fd6c3cb888cd784cb17b6d4dec Mon Sep 17 00:00:00 2001 From: bmoiseenko Date: Tue, 2 Apr 2024 12:43:21 +0300 Subject: [PATCH 03/12] nullable params --- .../ValueModels/ItemsCustomFieldValueModel.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/AmoCRM/Models/CustomFieldsValues/ValueModels/ItemsCustomFieldValueModel.php b/src/AmoCRM/Models/CustomFieldsValues/ValueModels/ItemsCustomFieldValueModel.php index f5a078ec..d95068ae 100644 --- a/src/AmoCRM/Models/CustomFieldsValues/ValueModels/ItemsCustomFieldValueModel.php +++ b/src/AmoCRM/Models/CustomFieldsValues/ValueModels/ItemsCustomFieldValueModel.php @@ -388,9 +388,9 @@ public function setMetadata(?array $metadata): ItemsCustomFieldValueModel } /** - * @return bool + * @return bool|null */ - public function getIsDiscountRecalculated(): bool + public function getIsDiscountRecalculated(): ?bool { return $this->isDiscountRecalculated; } @@ -408,9 +408,9 @@ private function setIsDiscountRecalculated(bool $isDiscountRecalculated): ItemsC } /** - * @return bool + * @return bool|null */ - public function getIsTotalSumRecalculated(): bool + public function getIsTotalSumRecalculated(): ?bool { return $this->isTotalSumRecalculated; } @@ -428,19 +428,19 @@ private function setIsTotalSumRecalculated(bool $isTotalSumRecalculated): ItemsC } /** - * @return float + * @return float|null */ - public function getTotalSum(): float + public function getTotalSum(): ?float { return $this->totalSum; } /** - * @param float $totalSum + * @param float|null $totalSum * * @return ItemsCustomFieldValueModel */ - private function setTotalSum(float $totalSum): ItemsCustomFieldValueModel + private function setTotalSum(?float $totalSum): ItemsCustomFieldValueModel { $this->totalSum = $totalSum; From 25a7d3e7789c38db1bc9de8c800a1428f0038096 Mon Sep 17 00:00:00 2001 From: bmoiseenko Date: Wed, 3 Apr 2024 16:54:18 +0300 Subject: [PATCH 04/12] audit fix --- .../ItemsCustomFieldValueModel.php | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/AmoCRM/Models/CustomFieldsValues/ValueModels/ItemsCustomFieldValueModel.php b/src/AmoCRM/Models/CustomFieldsValues/ValueModels/ItemsCustomFieldValueModel.php index d95068ae..92eaa282 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; } @@ -388,11 +391,11 @@ public function setMetadata(?array $metadata): ItemsCustomFieldValueModel } /** - * @return bool|null + * @return bool */ - public function getIsDiscountRecalculated(): ?bool + public function getIsDiscountRecalculated(): bool { - return $this->isDiscountRecalculated; + return $this->isDiscountRecalculated ?? false; } /** @@ -408,11 +411,11 @@ private function setIsDiscountRecalculated(bool $isDiscountRecalculated): ItemsC } /** - * @return bool|null + * @return bool */ - public function getIsTotalSumRecalculated(): ?bool + public function getIsTotalSumRecalculated(): bool { - return $this->isTotalSumRecalculated; + return $this->isTotalSumRecalculated ?? false; } /** @@ -440,7 +443,7 @@ public function getTotalSum(): ?float * * @return ItemsCustomFieldValueModel */ - private function setTotalSum(?float $totalSum): ItemsCustomFieldValueModel + private function setTotalSum(float $totalSum): ItemsCustomFieldValueModel { $this->totalSum = $totalSum; From 3478e25be2e2915665cce34dac44dee270a20a5b Mon Sep 17 00:00:00 2001 From: bmoiseenko Date: Wed, 3 Apr 2024 16:55:32 +0300 Subject: [PATCH 05/12] audit fix --- .../ValueModels/ItemsCustomFieldValueModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AmoCRM/Models/CustomFieldsValues/ValueModels/ItemsCustomFieldValueModel.php b/src/AmoCRM/Models/CustomFieldsValues/ValueModels/ItemsCustomFieldValueModel.php index 92eaa282..8ca3abb2 100644 --- a/src/AmoCRM/Models/CustomFieldsValues/ValueModels/ItemsCustomFieldValueModel.php +++ b/src/AmoCRM/Models/CustomFieldsValues/ValueModels/ItemsCustomFieldValueModel.php @@ -439,7 +439,7 @@ public function getTotalSum(): ?float } /** - * @param float|null $totalSum + * @param float $totalSum * * @return ItemsCustomFieldValueModel */ From 934c30eac9b8e54a2eee39d457ea8e66de991ff4 Mon Sep 17 00:00:00 2001 From: bmoiseenko Date: Thu, 4 Apr 2024 16:23:58 +0300 Subject: [PATCH 06/12] audit fix --- .../ValueModels/ItemsCustomFieldValueModel.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/AmoCRM/Models/CustomFieldsValues/ValueModels/ItemsCustomFieldValueModel.php b/src/AmoCRM/Models/CustomFieldsValues/ValueModels/ItemsCustomFieldValueModel.php index 8ca3abb2..acf968a9 100644 --- a/src/AmoCRM/Models/CustomFieldsValues/ValueModels/ItemsCustomFieldValueModel.php +++ b/src/AmoCRM/Models/CustomFieldsValues/ValueModels/ItemsCustomFieldValueModel.php @@ -431,11 +431,11 @@ private function setIsTotalSumRecalculated(bool $isTotalSumRecalculated): ItemsC } /** - * @return float|null + * @return float */ - public function getTotalSum(): ?float + public function getTotalSum(): float { - return $this->totalSum; + return $this->totalSum ?? 0; } /** From 41b2d2fb137cc088c478d8da30d7ca9e334594dc Mon Sep 17 00:00:00 2001 From: bmoiseenko Date: Tue, 16 Apr 2024 13:24:13 +0300 Subject: [PATCH 07/12] valid at constraint fix --- src/AmoCRM/OAuth/AmoCRMOAuth.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/AmoCRM/OAuth/AmoCRMOAuth.php b/src/AmoCRM/OAuth/AmoCRMOAuth.php index 2a60ff80..f8e19876 100755 --- a/src/AmoCRM/OAuth/AmoCRMOAuth.php +++ b/src/AmoCRM/OAuth/AmoCRMOAuth.php @@ -32,6 +32,7 @@ use Lcobucci\JWT\Validation\Constraint\PermittedFor; use Lcobucci\JWT\Validation\Constraint\SignedWith; use Lcobucci\JWT\Validation\Constraint\LooseValidAt; +use Lcobucci\JWT\Validation\Constraint\ValidAt; use Lcobucci\JWT\Validation\ConstraintViolation; use League\OAuth2\Client\Grant\AuthorizationCode; use League\OAuth2\Client\Grant\RefreshToken; @@ -466,13 +467,20 @@ public function parseDisposableToken(string $token): DisposableTokenModel $clientBaseUri = new Uri($this->redirectUri); $clientBaseUri = sprintf('%s://%s', $clientBaseUri->getScheme(), $clientBaseUri->getHost()); + + if (PHP_MAJOR_VERSION < 8) { + $validAtConstraint = new ValidAt(FrozenClock::fromUTC()); + } else { + $validAtConstraint = new LooseValidAt(FrozenClock::fromUTC()); + } + $constraints = [ // Проверка подписи new SignedWith($signer, $key), // Проверим наш ли адресат new PermittedFor($clientBaseUri), // Проверка жизни токена - new LooseValidAt(FrozenClock::fromUTC()), + $validAtConstraint, ]; $configuration = Configuration::forSymmetricSigner($signer, $key); From 259f359850839f77ed3c48d31abbbb52893b3e47 Mon Sep 17 00:00:00 2001 From: bmoiseenko Date: Tue, 16 Apr 2024 13:32:19 +0300 Subject: [PATCH 08/12] downgrade lcobucci/clock for lower php --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 3ff61e8f..1d2d94ec 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", "nesbot/carbon": "^2.52 || ^3.0.0", "ext-fileinfo": "*" }, From 7064c565d5e49cf0f2112e5cf3fc02f2b00cd9ad Mon Sep 17 00:00:00 2001 From: bmoiseenko Date: Tue, 16 Apr 2024 13:39:12 +0300 Subject: [PATCH 09/12] self version upgrade --- src/AmoCRM/Client/AmoCRMApiRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AmoCRM/Client/AmoCRMApiRequest.php b/src/AmoCRM/Client/AmoCRMApiRequest.php index fc686bcf..4e940993 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.1'; + public const LIBRARY_VERSION = '1.7.2'; public const USER_AGENT = 'amoCRM-API-Library/' . self::LIBRARY_VERSION; public const SUCCESS_STATUSES = [ From ca91ffe7123426b64e99d1db624a833afb56d827 Mon Sep 17 00:00:00 2001 From: bmoiseenko Date: Tue, 16 Apr 2024 14:38:49 +0300 Subject: [PATCH 10/12] rollback php version condition --- src/AmoCRM/OAuth/AmoCRMOAuth.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/AmoCRM/OAuth/AmoCRMOAuth.php b/src/AmoCRM/OAuth/AmoCRMOAuth.php index f8e19876..82c0c38d 100755 --- a/src/AmoCRM/OAuth/AmoCRMOAuth.php +++ b/src/AmoCRM/OAuth/AmoCRMOAuth.php @@ -468,19 +468,13 @@ public function parseDisposableToken(string $token): DisposableTokenModel $clientBaseUri = new Uri($this->redirectUri); $clientBaseUri = sprintf('%s://%s', $clientBaseUri->getScheme(), $clientBaseUri->getHost()); - if (PHP_MAJOR_VERSION < 8) { - $validAtConstraint = new ValidAt(FrozenClock::fromUTC()); - } else { - $validAtConstraint = new LooseValidAt(FrozenClock::fromUTC()); - } - $constraints = [ // Проверка подписи new SignedWith($signer, $key), // Проверим наш ли адресат new PermittedFor($clientBaseUri), // Проверка жизни токена - $validAtConstraint, + new LooseValidAt(FrozenClock::fromUTC()), ]; $configuration = Configuration::forSymmetricSigner($signer, $key); From 5999dce3380bf94899592567fe90005a16e48de6 Mon Sep 17 00:00:00 2001 From: bmoiseenko Date: Tue, 16 Apr 2024 14:39:38 +0300 Subject: [PATCH 11/12] whitespace --- src/AmoCRM/OAuth/AmoCRMOAuth.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/AmoCRM/OAuth/AmoCRMOAuth.php b/src/AmoCRM/OAuth/AmoCRMOAuth.php index 82c0c38d..2a60ff80 100755 --- a/src/AmoCRM/OAuth/AmoCRMOAuth.php +++ b/src/AmoCRM/OAuth/AmoCRMOAuth.php @@ -32,7 +32,6 @@ use Lcobucci\JWT\Validation\Constraint\PermittedFor; use Lcobucci\JWT\Validation\Constraint\SignedWith; use Lcobucci\JWT\Validation\Constraint\LooseValidAt; -use Lcobucci\JWT\Validation\Constraint\ValidAt; use Lcobucci\JWT\Validation\ConstraintViolation; use League\OAuth2\Client\Grant\AuthorizationCode; use League\OAuth2\Client\Grant\RefreshToken; @@ -467,7 +466,6 @@ public function parseDisposableToken(string $token): DisposableTokenModel $clientBaseUri = new Uri($this->redirectUri); $clientBaseUri = sprintf('%s://%s', $clientBaseUri->getScheme(), $clientBaseUri->getHost()); - $constraints = [ // Проверка подписи new SignedWith($signer, $key), From 11ad841aa34731c0e0e3add142e3d6234d0ce8c6 Mon Sep 17 00:00:00 2001 From: bmoiseenko Date: Tue, 16 Apr 2024 19:01:07 +0300 Subject: [PATCH 12/12] audit fix --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1d2d94ec..d4b42585 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "fig/http-message-util": "1.*", "ramsey/uuid": "^3 || ^4", "lcobucci/jwt": "^3.4.6 || ^4.0.4", - "lcobucci/clock": "2.0.0", + "lcobucci/clock": "~2.0.0 || ^2.1.0", "nesbot/carbon": "^2.52 || ^3.0.0", "ext-fileinfo": "*" },