*/ public function toArray(): array { return [ 'accountnumber' => $this->accountNumber, 'testmode' => $this->testMode, 'fiscalization' => $this->fiscalization, 'vat' => $this->vat->value, 'receipt' => $this->receipt->toArray(), 'description' => $this->description, 'subscriberid' => $this->subscriberId, ]; } public function toJson(): string { return json_encode($this->toArray(), JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE); } /** * @param array $data */ public static function fromArray(array $data): self { return new self( accountNumber: (string) ($data['accountnumber'] ?? ''), testMode: (bool) ($data['testmode'] ?? false), fiscalization: (bool) ($data['fiscalization'] ?? false), vat: Vat::from((string) ($data['vat'] ?? '')), receipt: Receipt::fromArray(is_array($data['receipt'] ?? null) ? $data['receipt'] : []), description: (string) ($data['description'] ?? ''), subscriberId: (string) ($data['subscriberid'] ?? ''), ); } public static function fromJson(string $json): self { $data = json_decode($json, true, 512, JSON_THROW_ON_ERROR); if (!is_array($data)) { throw new InvalidArgumentException('Снимок заказа повреждён.'); } return self::fromArray($data); } /** * Совпадение реквизитов и чека; описание не сравнивается — оно не влияет * на оплату и не должно плодить заказы. */ public function equals(self $other): bool { $mine = $this->toArray(); $theirs = $other->toArray(); unset($mine['description'], $theirs['description']); return $mine === $theirs; } }