From 4f9644a078de721017e124ce3044512b3f395826 Mon Sep 17 00:00:00 2001 From: Netkas Date: Tue, 14 Feb 2023 14:29:23 -0500 Subject: [PATCH] Added \TgBotLib\Objects > EncryptedPassportElement --- .../Objects/EncryptedPassportElement.php | 257 ++++++++++++++++++ 1 file changed, 257 insertions(+) create mode 100644 src/TgBotLib/Objects/EncryptedPassportElement.php diff --git a/src/TgBotLib/Objects/EncryptedPassportElement.php b/src/TgBotLib/Objects/EncryptedPassportElement.php new file mode 100644 index 0000000..cc203d9 --- /dev/null +++ b/src/TgBotLib/Objects/EncryptedPassportElement.php @@ -0,0 +1,257 @@ +type; + } + + /** + * Optional. Base64-encoded encrypted Telegram Passport element data provided by the user, available for + * “personal_details”, “passport”, “driver_license”, “identity_card”, “internal_passport” and “address” types. + * Can be decrypted and verified using the accompanying EncryptedCredentials. + * + * @see https://core.telegram.org/bots/api#encryptedcredentials + * @return string|null + */ + public function getData(): ?string + { + return $this->data; + } + + /** + * Optional. User's verified phone number, available only for “phone_number” type + * + * @return string|null + */ + public function getPhoneNumber(): ?string + { + return $this->phone_number; + } + + /** + * Optional. User's verified email address, available only for “email” type + * + * @return string|null + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * Optional. Array of encrypted files with documents provided by the user, available for “utility_bill”, + * “bank_statement”, “rental_agreement”, “passport_registration” and “temporary_registration” types. Files can + * be decrypted and verified using the accompanying EncryptedCredentials. + * + * @see https://core.telegram.org/bots/api#encryptedcredentials + * @return PassportFile[]|null + */ + public function getFiles(): ?array + { + return $this->files; + } + + /** + * Optional. Encrypted file with the front side of the document, provided by the user. Available for “passport”, + * “driver_license”, “identity_card” and “internal_passport”. The file can be decrypted and verified using the + * accompanying EncryptedCredentials. + * + * @see https://core.telegram.org/bots/api#encryptedcredentials + * @return PassportFile[]|null + */ + public function getFrontSide(): ?array + { + return $this->front_side; + } + + /** + * Optional. Encrypted file with the reverse side of the document, provided by the user. Available for + * “driver_license” and “identity_card”. The file can be decrypted and verified using the accompanying + * EncryptedCredentials. + * + * @see https://core.telegram.org/bots/api#encryptedcredentials + * @return PassportFile[]|null + */ + public function getReverseSide(): ?array + { + return $this->reverse_side; + } + + /** + * Optional. Encrypted file with the selfie of the user holding a document, provided by the user; available for + * “passport”, “driver_license”, “identity_card” and “internal_passport”. The file can be decrypted and verified + * using the accompanying EncryptedCredentials. + * + * @see https://core.telegram.org/bots/api#encryptedcredentials + * @return PassportFile[]|null + */ + public function getSelfie(): ?array + { + return $this->selfie; + } + + /** + * Optional. Array of encrypted files with translated versions of documents provided by the user. Available if + * requested for “passport”, “driver_license”, “identity_card”, “internal_passport”, “utility_bill”, + * “bank_statement”, “rental_agreement”, “passport_registration” and “temporary_registration” types. Files can + * be decrypted and verified using the accompanying EncryptedCredentials. + * + * @see https://core.telegram.org/bots/api#encryptedcredentials + * @return PassportFile[]|null + */ + public function getTranslation(): ?array + { + return $this->translation; + } + + /** + * Base64-encoded element hash for using in PassportElementErrorUnspecified + * + * @see https://core.telegram.org/bots/api#passportelementerrorunspecified + * @return string + */ + public function getHash(): string + { + return $this->hash; + } + + /** + * Returns an array representation of the object. + * + * @return array + */ + public function toArray(): array + { + return [ + 'type' => $this->type, + 'data' => $this->data, + 'phone_number' => $this->phone_number, + 'email' => $this->email, + 'files' => array_map(function (PassportFile $file) + { + return $file->toArray(); + }, $this->files), + 'front_side' => array_map(function (PassportFile $file) + { + return $file->toArray(); + }, $this->front_side), + 'reverse_side' => array_map(function (PassportFile $file) + { + return $file->toArray(); + }, $this->reverse_side), + 'selfie' => array_map(function (PassportFile $file) + { + return $file->toArray(); + }, $this->selfie), + 'translation' => array_map(function (PassportFile $file) + { + return $file->toArray(); + }, $this->translation), + 'hash' => $this->hash, + ]; + } + + /** + * Constructs object from an array representation. + * + * @param array $data + * @return ObjectTypeInterface + */ + public static function fromArray(array $data): ObjectTypeInterface + { + $object = new static(); + + $object->type = $data['type']; + $object->data = $data['data'] ?? null; + $object->phone_number = $data['phone_number'] ?? null; + $object->email = $data['email'] ?? null; + $object->files = array_map(function (array $file) + { + return PassportFile::fromArray($file); + }, $data['files'] ?? []); + $object->front_side = array_map(function (array $file) + { + return PassportFile::fromArray($file); + }, $data['front_side'] ?? []); + $object->reverse_side = array_map(function (array $file) + { + return PassportFile::fromArray($file); + }, $data['reverse_side'] ?? []); + $object->selfie = array_map(function (array $file) + { + return PassportFile::fromArray($file); + }, $data['selfie'] ?? []); + $object->translation = array_map(function (array $file) + { + return PassportFile::fromArray($file); + }, $data['translation'] ?? []); + $object->hash = $data['hash']; + + return $object; + } +} \ No newline at end of file