Skip to content

Commit

Permalink
Merge branch 'master' of git.amocrm.ru:amocrm/amocrm-api-php into fea…
Browse files Browse the repository at this point in the history
…ture/AC-875
  • Loading branch information
egrigorev committed Apr 26, 2024
2 parents 7d14e4e + b7a3ca0 commit 48e72fc
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 6 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*"
},
Expand Down
2 changes: 1 addition & 1 deletion src/AmoCRM/Client/AmoCRMApiRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -392,7 +395,7 @@ public function setMetadata(?array $metadata): ItemsCustomFieldValueModel
*/
public function getIsDiscountRecalculated(): bool
{
return $this->isDiscountRecalculated;
return $this->isDiscountRecalculated ?? false;
}

/**
Expand All @@ -412,7 +415,7 @@ private function setIsDiscountRecalculated(bool $isDiscountRecalculated): ItemsC
*/
public function getIsTotalSumRecalculated(): bool
{
return $this->isTotalSumRecalculated;
return $this->isTotalSumRecalculated ?? false;
}

/**
Expand All @@ -432,7 +435,7 @@ private function setIsTotalSumRecalculated(bool $isTotalSumRecalculated): ItemsC
*/
public function getTotalSum(): float
{
return $this->totalSum;
return $this->totalSum ?? 0;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/AmoCRM/Models/Factories/NoteFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
177 changes: 177 additions & 0 deletions src/AmoCRM/Models/NoteType/AiResultNote.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php

declare(strict_types=1);

namespace AmoCRM\Models\NoteType;

use AmoCRM\Models\Factories\NoteFactory;
use AmoCRM\Models\NoteModel;

class AiResultNote extends NoteModel
{
protected $modelClass = AiResultNote::class;

/**
* @var string
*/
protected $text;

/**
* @var string
*/
protected $answerId;

/**
* @var int
*/
protected $talkId;

/**
* @var bool
*/
protected $hasError;

public function getNoteType(): string
{
return NoteFactory::NOTE_TYPE_AI_RESULT;
}

/**
* @param array $note
*
* @return self
*/
public function fromArray(array $note): NoteModel
{
$model = parent::fromArray($note);

if (isset($note['params']['text'])) {
$model->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;
}
}

0 comments on commit 48e72fc

Please sign in to comment.