2023-02-14 15:02:20 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/** @noinspection PhpMissingFieldTypeInspection */
|
|
|
|
|
2023-02-14 17:41:38 -05:00
|
|
|
namespace TgBotLib\Objects\Telegram;
|
2023-02-14 15:02:20 -05:00
|
|
|
|
|
|
|
use TgBotLib\Interfaces\ObjectTypeInterface;
|
|
|
|
|
|
|
|
class OrderInfo implements ObjectTypeInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string|null
|
|
|
|
*/
|
|
|
|
private $name;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string|null
|
|
|
|
*/
|
|
|
|
private $phone_number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string|null
|
|
|
|
*/
|
|
|
|
private $email;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ShippingAddress|null
|
|
|
|
*/
|
|
|
|
private $shipping_address;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Optional. User name
|
|
|
|
*
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
public function getName(): ?string
|
|
|
|
{
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Optional. User's phone number
|
|
|
|
*
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
public function getPhoneNumber(): ?string
|
|
|
|
{
|
|
|
|
return $this->phone_number;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Optional. User email
|
|
|
|
*
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
public function getEmail(): ?string
|
|
|
|
{
|
|
|
|
return $this->email;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Optional. User shipping address
|
|
|
|
*
|
|
|
|
* @return ShippingAddress|null
|
|
|
|
*/
|
|
|
|
public function getShippingAddress(): ?ShippingAddress
|
|
|
|
{
|
|
|
|
return $this->shipping_address;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array representation of the object
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toArray(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'name' => $this->name,
|
|
|
|
'phone_number' => $this->phone_number,
|
|
|
|
'email' => $this->email,
|
|
|
|
'shipping_address' => ($this->shipping_address instanceof ShippingAddress) ? $this->shipping_address->toArray() : null,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs object from an array representation
|
|
|
|
*
|
|
|
|
* @param array $data
|
2023-02-16 15:27:57 -05:00
|
|
|
* @return OrderInfo
|
2023-02-14 15:02:20 -05:00
|
|
|
*/
|
2023-02-16 15:27:57 -05:00
|
|
|
public static function fromArray(array $data): self
|
2023-02-14 15:02:20 -05:00
|
|
|
{
|
|
|
|
$object = new self();
|
|
|
|
|
|
|
|
$object->name = $data['name'] ?? null;
|
|
|
|
$object->phone_number = $data['phone_number'] ?? null;
|
|
|
|
$object->email = $data['email'] ?? null;
|
|
|
|
$object->shipping_address = ($data['shipping_address'] ?? null) instanceof ShippingAddress ? $data['shipping_address'] : ShippingAddress::fromArray($data['shipping_address'] ?? []);
|
|
|
|
|
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
}
|