Added \TgBotLib\Objects > ShippingQuery
This commit is contained in:
parent
80afea0882
commit
30c8cb5ce1
1 changed files with 103 additions and 0 deletions
103
src/TgBotLib/Objects/ShippingQuery.php
Normal file
103
src/TgBotLib/Objects/ShippingQuery.php
Normal file
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
/** @noinspection PhpMissingFieldTypeInspection */
|
||||
|
||||
namespace TgBotLib\Objects;
|
||||
|
||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||
|
||||
class ShippingQuery implements ObjectTypeInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
private $from;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $invoice_payload;
|
||||
|
||||
/**
|
||||
* @var ShippingAddress
|
||||
*/
|
||||
private $shipping_address;
|
||||
|
||||
/**
|
||||
* Unique query identifier
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* User who sent the query
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function getFrom(): User
|
||||
{
|
||||
return $this->from;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bot specified invoice payload
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getInvoicePayload(): string
|
||||
{
|
||||
return $this->invoice_payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* User specified shipping address
|
||||
*
|
||||
* @return ShippingAddress
|
||||
*/
|
||||
public function getShippingAddress(): ShippingAddress
|
||||
{
|
||||
return $this->shipping_address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array representation of the object
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'from' => ($this->from instanceof User) ? $this->from->toArray() : $this->from,
|
||||
'invoice_payload' => $this->invoice_payload,
|
||||
'shipping_address' => ($this->shipping_address instanceof ShippingAddress) ? $this->shipping_address->toArray() : $this->shipping_address,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs object from an array representation
|
||||
*
|
||||
* @param array $data
|
||||
* @return ObjectTypeInterface
|
||||
*/
|
||||
public static function fromArray(array $data): ObjectTypeInterface
|
||||
{
|
||||
$object = new self();
|
||||
|
||||
$object->id = $data['id'];
|
||||
$object->from = User::fromArray($data['from']);
|
||||
$object->invoice_payload = $data['invoice_payload'];
|
||||
$object->shipping_address = ShippingAddress::fromArray($data['shipping_address']);
|
||||
|
||||
return $object;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue