From 30c8cb5ce13d58157449294a34026d18cafb0d3a Mon Sep 17 00:00:00 2001 From: Netkas Date: Tue, 14 Feb 2023 15:17:16 -0500 Subject: [PATCH] Added \TgBotLib\Objects > ShippingQuery --- src/TgBotLib/Objects/ShippingQuery.php | 103 +++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 src/TgBotLib/Objects/ShippingQuery.php diff --git a/src/TgBotLib/Objects/ShippingQuery.php b/src/TgBotLib/Objects/ShippingQuery.php new file mode 100644 index 0000000..b47513e --- /dev/null +++ b/src/TgBotLib/Objects/ShippingQuery.php @@ -0,0 +1,103 @@ +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; + } + } \ No newline at end of file