setName($name); } if ($email) { $this->setEmail($email); } if ($phone) { $this->setPhone($phone); } if ($inn) { $this->setInn($inn); } } /** * Возвращает имя покупателя. Тег ФФД - 1227. * * @return string */ public function getName() { return $this->name; } /** * Устанавливает имя покупателя * Тег ФФД - 1227. * * @param string $name * @return $this * @throws AtolNameTooLongException */ public function setName(string $name) { $name = trim($name); if (strlen($name) > 256) { throw new AtolNameTooLongException($name, 256); } $this->name = $name; return $this; } /** * Возвращает телефон покупателя. * Тег ФФД - 1008. * * @return string */ public function getPhone() { return $this->phone ?? ''; } /** * Устанавливает телефон покупателя. * Тег ФФД - 1008. * Входная строка лишается всех знаков, кроме цифр и знака '+'. * * @param string $phone * @return $this * @throws AtolPhoneTooLongException */ public function setPhone(string $phone) { $phone = preg_replace("/[^0-9+]/", '', $phone); if (strlen($phone) > 64) { throw new AtolPhoneTooLongException($phone, 64); } $this->phone = $phone; return $this; } /** * @inheritDoc */ public function jsonSerialize() { $json = []; if ($this->getName()) { $json['name'] = $this->getName() ?? ''; } if ($this->getEmail()) { $json['email'] = $this->getEmail() ?? ''; } if ($this->getPhone()) { $json['phone'] = $this->getPhone() ?? ''; } if ($this->getInn()) { $json['inn'] = $this->getInn() ?? ''; } return $json; } }