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