From 7ea986a55535a5a8511c6b7b2989d8c0200d59cf Mon Sep 17 00:00:00 2001 From: netkas Date: Wed, 27 Nov 2024 19:28:56 -0500 Subject: [PATCH] Add PassportElementError handling classes --- .../Types/PassportElementErrorSourceType.php | 16 ++ .../Enums/Types/PassportElementErrorType.php | 13 ++ src/TgBotLib/Objects/PassportElementError.php | 73 +++++++++ .../PassportElementErrorDataField.php | 139 ++++++++++++++++++ .../PassportElementErrorFile.php | 114 ++++++++++++++ .../PassportElementErrorFiles.php | 115 +++++++++++++++ .../PassportElementErrorFrontSide.php | 114 ++++++++++++++ .../PassportElementErrorReverseSide.php | 110 ++++++++++++++ .../PassportElementErrorSelfie.php | 114 ++++++++++++++ .../PassportElementErrorTranslationFile.php | 116 +++++++++++++++ .../PassportElementErrorTranslationFiles.php | 110 ++++++++++++++ .../PassportElementErrorUnspecified.php | 111 ++++++++++++++ 12 files changed, 1145 insertions(+) create mode 100644 src/TgBotLib/Enums/Types/PassportElementErrorSourceType.php create mode 100644 src/TgBotLib/Enums/Types/PassportElementErrorType.php create mode 100644 src/TgBotLib/Objects/PassportElementError.php create mode 100644 src/TgBotLib/Objects/PassportElementError/PassportElementErrorDataField.php create mode 100644 src/TgBotLib/Objects/PassportElementError/PassportElementErrorFile.php create mode 100644 src/TgBotLib/Objects/PassportElementError/PassportElementErrorFiles.php create mode 100644 src/TgBotLib/Objects/PassportElementError/PassportElementErrorFrontSide.php create mode 100644 src/TgBotLib/Objects/PassportElementError/PassportElementErrorReverseSide.php create mode 100644 src/TgBotLib/Objects/PassportElementError/PassportElementErrorSelfie.php create mode 100644 src/TgBotLib/Objects/PassportElementError/PassportElementErrorTranslationFile.php create mode 100644 src/TgBotLib/Objects/PassportElementError/PassportElementErrorTranslationFiles.php create mode 100644 src/TgBotLib/Objects/PassportElementError/PassportElementErrorUnspecified.php diff --git a/src/TgBotLib/Enums/Types/PassportElementErrorSourceType.php b/src/TgBotLib/Enums/Types/PassportElementErrorSourceType.php new file mode 100644 index 0000000..322ed13 --- /dev/null +++ b/src/TgBotLib/Enums/Types/PassportElementErrorSourceType.php @@ -0,0 +1,16 @@ +source = PassportElementErrorSourceType::UNSPECIFIED; + return; + } + + $this->source = PassportElementErrorSourceType::tryFrom($data['source'] ?? null); + } + + /** + * The error source + * + * @return PassportElementErrorSourceType + */ + public function getSource(): PassportElementErrorSourceType + { + return $this->source; + } + + /** + * @inheritDoc + */ + public function toArray(): ?array + { + return null; + } + + /** + * @inheritDoc + */ + public static function fromArray(?array $data): ?PassportElementError + { + return match(PassportElementErrorSourceType::tryFrom($data['source'])) + { + PassportElementErrorSourceType::DATA => PassportElementErrorDataField::fromArray($data), + PassportElementErrorSourceType::FILE => PassportElementErrorFile::fromArray($data), + PassportElementErrorSourceType::FILES => PassportElementErrorFiles::fromArray($data), + PassportElementErrorSourceType::FRONT_SIDE => PassportElementErrorFrontSide::fromArray($data), + PassportElementErrorSourceType::REVERSE_SIDE => PassportElementErrorReverseSide::fromArray($data), + PassportElementErrorSourceType::SELFIE => PassportElementErrorSelfie::fromArray($data), + PassportElementErrorSourceType::TRANSLATION_FILE => PassportElementErrorTranslationFile::fromArray($data), + PassportElementErrorSourceType::TRANSLATION_FILES => PassportElementErrorTranslationFiles::fromArray($data), + PassportElementErrorSourceType::UNSPECIFIED => PassportElementErrorUnspecified::fromArray($data), + }; + } + } \ No newline at end of file diff --git a/src/TgBotLib/Objects/PassportElementError/PassportElementErrorDataField.php b/src/TgBotLib/Objects/PassportElementError/PassportElementErrorDataField.php new file mode 100644 index 0000000..038ca2f --- /dev/null +++ b/src/TgBotLib/Objects/PassportElementError/PassportElementErrorDataField.php @@ -0,0 +1,139 @@ +type = PassportElementErrorType::tryFrom($data['type'] ?? null); + $this->fieldName = $data['field_name']; + $this->dataHash = $data['data_hash']; + $this->message = $data['message']; + } + + /** + * The section of the user's Telegram Passport which has the error, + * one of “personal_details”, “passport”, “driver_license”, “identity_card”, “internal_passport”, “address” + * + * @return PassportElementErrorType + */ + public function getType(): PassportElementErrorType + { + return $this->type; + } + + /** + * The section of the user's Telegram Passport which has the error, + * one of “personal_details”, “passport”, “driver_license”, “identity_card”, “internal_passport”, “address” + * + * @param PassportElementErrorType $type + * @return PassportElementErrorDataField + */ + public function setType(PassportElementErrorType $type): PassportElementErrorDataField + { + $this->type = $type; + return $this; + } + + /** + * Name of the data field which has the error + * + * @return string + */ + public function getFieldName(): string + { + return $this->fieldName; + } + + /** + * Name of the data field which has the error + * + * @param string $fieldName + * @return PassportElementErrorDataField + */ + public function setFieldName(string $fieldName): PassportElementErrorDataField + { + $this->fieldName = $fieldName; + return $this; + } + + /** + * Base64-encoded data hash + * + * @return string + */ + public function getDataHash(): string + { + return $this->dataHash; + } + + /** + * Base64-encoded data hash + * + * @param string $dataHash + * @return PassportElementErrorDataField + */ + public function setDataHash(string $dataHash): PassportElementErrorDataField + { + $this->dataHash = $dataHash; + return $this; + } + + /** + * Error message + * + * @return string + */ + public function getMessage(): string + { + return $this->message; + } + + /** + * Error message + * + * @param string $message + * @return PassportElementErrorDataField + */ + public function setMessage(string $message): PassportElementErrorDataField + { + $this->message = $message; + return $this; + } + + /** + * @inheritDoc + */ + public function toArray(): ?array + { + return [ + 'source' => $this->getSource()->value, + 'type' => $this->type->value, + 'field_name' => $this->fieldName, + 'data_hash' => $this->dataHash, + 'message' => $this->message + ]; + } + } \ No newline at end of file diff --git a/src/TgBotLib/Objects/PassportElementError/PassportElementErrorFile.php b/src/TgBotLib/Objects/PassportElementError/PassportElementErrorFile.php new file mode 100644 index 0000000..36c90e1 --- /dev/null +++ b/src/TgBotLib/Objects/PassportElementError/PassportElementErrorFile.php @@ -0,0 +1,114 @@ +type = PassportElementErrorType::tryFrom($data['type'] ?? null); + $this->fileHash = $data['file_hash']; + $this->message = $data['message']; + } + + /** + * The section of the user's Telegram Passport which has the issue, + * one of “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration” + * + * @return PassportElementErrorType + */ + public function getType(): PassportElementErrorType + { + return $this->type; + } + + /** + * The section of the user's Telegram Passport which has the issue, + * one of “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration” + * + * @param PassportElementErrorType $type + * @return $this + */ + public function setType(PassportElementErrorType $type): PassportElementErrorFile + { + $this->type = $type; + return $this; + } + + /** + * Base64-encoded file hash + * + * @return string + */ + public function getFileHash(): string + { + return $this->fileHash; + } + + /** + * Base64-encoded file hash + * + * @param string $fileHash + * @return $this + */ + public function setFileHash(string $fileHash): PassportElementErrorFile + { + $this->fileHash = $fileHash; + return $this; + } + + /** + * Error message + * + * @return string + */ + public function getMessage(): string + { + return $this->message; + } + + /** + * Error message + * + * @param string $message + * @return $this + */ + public function setMessage(string $message): PassportElementErrorFile + { + $this->message = $message; + return $this; + } + + /** + * @inheritDoc + */ + public function toArray(): ?array + { + return [ + 'source' => $this->getSource()->value, + 'type' => $this->type->value, + 'file_hash' => $this->fileHash, + 'message' => $this->message + ]; + } + } \ No newline at end of file diff --git a/src/TgBotLib/Objects/PassportElementError/PassportElementErrorFiles.php b/src/TgBotLib/Objects/PassportElementError/PassportElementErrorFiles.php new file mode 100644 index 0000000..2997bc3 --- /dev/null +++ b/src/TgBotLib/Objects/PassportElementError/PassportElementErrorFiles.php @@ -0,0 +1,115 @@ +type = PassportElementErrorType::tryFrom($data['type'] ?? null); + $this->fileHashes = $data['file_hashes']; + $this->message = $data['message']; + } + + /** + * List of base64-encoded file hashes + * + * @return PassportElementErrorType + */ + public function getType(): PassportElementErrorType + { + return $this->type; + } + + /** + * List of base64-encoded file hashes + * + * @param PassportElementErrorType $type + * @return $this + */ + public function setType(PassportElementErrorType $type): PassportElementErrorFiles + { + $this->type = $type; + return $this; + } + + /** + * List of base64-encoded file hashes + * + * @return string[] + */ + public function getFileHashes(): array + { + return $this->fileHashes; + } + + /** + * List of base64-encoded file hashes + * + * @param array $fileHashes + * @return $this + */ + public function setFileHashes(array $fileHashes): PassportElementErrorFiles + { + $this->fileHashes = $fileHashes; + return $this; + } + + /** + * Error message + * + * @return string + */ + public function getMessage(): string + { + return $this->message; + } + + /** + * Error message + * + * @param string $message + * @return $this + */ + public function setMessage(string $message): PassportElementErrorFiles + { + $this->message = $message; + return $this; + } + + /** + * @inheritDoc + */ + public function toArray(): ?array + { + return [ + 'source' => $this->getSource()->value, + 'type' => $this->type->value, + 'file_hashes' => $this->fileHashes, + 'message' => $this->message + ]; + } + } \ No newline at end of file diff --git a/src/TgBotLib/Objects/PassportElementError/PassportElementErrorFrontSide.php b/src/TgBotLib/Objects/PassportElementError/PassportElementErrorFrontSide.php new file mode 100644 index 0000000..dfb6dcd --- /dev/null +++ b/src/TgBotLib/Objects/PassportElementError/PassportElementErrorFrontSide.php @@ -0,0 +1,114 @@ +type = PassportElementErrorType::tryFrom($data['type'] ?? null); + $this->fileHash = $data['file_hash']; + $this->message = $data['message']; + } + + /** + * The section of the user's Telegram Passport which has the issue, + * one of “passport”, “driver_license”, “identity_card”, “internal_passport” + * + * @return PassportElementErrorType + */ + public function getType(): PassportElementErrorType + { + return $this->type; + } + + /** + * The section of the user's Telegram Passport which has the issue, + * one of “passport”, “driver_license”, “identity_card”, “internal_passport” + * + * @param PassportElementErrorType $type + * @return PassportElementErrorFrontSide + */ + public function setType(PassportElementErrorType $type): PassportElementErrorFrontSide + { + $this->type = $type; + return $this; + } + + /** + * Base64-encoded hash of the file with the front side of the document + * + * @return string + */ + public function getFileHash(): string + { + return $this->fileHash; + } + + /** + * Base64-encoded hash of the file with the front side of the document + * + * @param string $fileHash + * @return $this + */ + public function setFileHash(string $fileHash): PassportElementErrorFrontSide + { + $this->fileHash = $fileHash; + return $this; + } + + /** + * Error message + * + * @return string + */ + public function getMessage(): string + { + return $this->message; + } + + /** + * Error message + * + * @param string $message + * @return PassportElementErrorFrontSide + */ + public function setMessage(string $message): PassportElementErrorFrontSide + { + $this->message = $message; + return $this; + } + + /** + * @inheritDoc + */ + public function toArray(): ?array + { + return [ + 'source' => $this->getSource()->value, + 'type' => $this->type->value, + 'file_hash' => $this->fileHash, + 'message' => $this->message + ]; + } + } \ No newline at end of file diff --git a/src/TgBotLib/Objects/PassportElementError/PassportElementErrorReverseSide.php b/src/TgBotLib/Objects/PassportElementError/PassportElementErrorReverseSide.php new file mode 100644 index 0000000..d069a97 --- /dev/null +++ b/src/TgBotLib/Objects/PassportElementError/PassportElementErrorReverseSide.php @@ -0,0 +1,110 @@ +type = PassportElementErrorType::tryFrom($data['type'] ?? null); + $this->fileHash = $data['file_hash']; + $this->message = $data['message']; + } + + /** + * The section of the user's Telegram Passport which has the issue, one of “driver_license”, “identity_card” + * + * @return PassportElementErrorType + */ + public function getType(): PassportElementErrorType + { + return $this->type; + } + + /** + * The section of the user's Telegram Passport which has the issue, one of “driver_license”, “identity_card” + * + * @param PassportElementErrorType $type + * @return PassportElementErrorReverseSide + */ + public function setType(PassportElementErrorType $type): PassportElementErrorReverseSide + { + $this->type = $type; + return $this; + } + + /** + * Base64-encoded hash of the file with the reverse side of the document + * + * @return string + */ + public function getFileHash(): string + { + return $this->fileHash; + } + + /** + * Base64-encoded hash of the file with the reverse side of the document + * + * @param string $fileHash + * @return PassportElementErrorReverseSide + */ + public function setFileHash(string $fileHash): PassportElementErrorReverseSide + { + $this->fileHash = $fileHash; + return $this; + } + + /** + * Error message + * + * @return string + */ + public function getMessage(): string + { + return $this->message; + } + + /** + * @param string $message + * @return PassportElementErrorReverseSide + */ + public function setMessage(string $message): PassportElementErrorReverseSide + { + $this->message = $message; + return $this; + } + + /** + * @inheritDoc + */ + public function toArray(): ?array + { + return [ + 'source' => $this->getSource()->value, + 'type' => $this->type->value, + 'file_hash' => $this->fileHash, + 'message' => $this->message + ]; + } + } \ No newline at end of file diff --git a/src/TgBotLib/Objects/PassportElementError/PassportElementErrorSelfie.php b/src/TgBotLib/Objects/PassportElementError/PassportElementErrorSelfie.php new file mode 100644 index 0000000..1a92f32 --- /dev/null +++ b/src/TgBotLib/Objects/PassportElementError/PassportElementErrorSelfie.php @@ -0,0 +1,114 @@ +type = PassportElementErrorType::tryFrom($data['type'] ?? null); + $this->fileHash = $data['file_hash']; + $this->message = $data['message']; + } + + /** + * The section of the user's Telegram Passport which has the issue, + * one of “passport”, “driver_license”, “identity_card”, “internal_passport” + * + * @return PassportElementErrorType + */ + public function getType(): PassportElementErrorType + { + return $this->type; + } + + /** + * The section of the user's Telegram Passport which has the issue, + * one of “passport”, “driver_license”, “identity_card”, “internal_passport” + * + * @param PassportElementErrorType $type + * @return $this + */ + public function setType(PassportElementErrorType $type): PassportElementErrorSelfie + { + $this->type = $type; + return $this; + } + + /** + * Base64-encoded hash of the file with the selfie + * + * @return string + */ + public function getFileHash(): string + { + return $this->fileHash; + } + + /** + * Base64-encoded hash of the file with the selfie + * + * @param string $fileHash + * @return $this + */ + public function setFileHash(string $fileHash): PassportElementErrorSelfie + { + $this->fileHash = $fileHash; + return $this; + } + + /** + * Error message + * + * @return string + */ + public function getMessage(): string + { + return $this->message; + } + + /** + * Error message + * + * @param string $message + * @return $this + */ + public function setMessage(string $message): PassportElementErrorSelfie + { + $this->message = $message; + return $this; + } + + /** + * @inheritDoc + */ + public function toArray(): ?array + { + return [ + 'source' => $this->getSource()->value, + 'type' => $this->type->value, + 'file_hash' => $this->fileHash, + 'message' => $this->message + ]; + } + } \ No newline at end of file diff --git a/src/TgBotLib/Objects/PassportElementError/PassportElementErrorTranslationFile.php b/src/TgBotLib/Objects/PassportElementError/PassportElementErrorTranslationFile.php new file mode 100644 index 0000000..53ee8c7 --- /dev/null +++ b/src/TgBotLib/Objects/PassportElementError/PassportElementErrorTranslationFile.php @@ -0,0 +1,116 @@ +type = PassportElementErrorType::tryFrom($data['type'] ?? null); + $this->fileHash = $data['file_hash']; + $this->message = $data['message']; + } + + /** + * Type of element of the user's Telegram Passport which has the issue, + * one of “passport”, “driver_license”, “identity_card”, “internal_passport”, “utility_bill”, “bank_statement”, + * “rental_agreement”, “passport_registration”, “temporary_registration” + * + * @return PassportElementErrorType + */ + public function getType(): PassportElementErrorType + { + return $this->type; + } + + /** + * Type of element of the user's Telegram Passport which has the issue, + * one of “passport”, “driver_license”, “identity_card”, “internal_passport”, “utility_bill”, “bank_statement”, + * “rental_agreement”, “passport_registration”, “temporary_registration” + * + * @param PassportElementErrorType $type + * @return $this + */ + public function setType(PassportElementErrorType $type): PassportElementErrorTranslationFile + { + $this->type = $type; + return $this; + } + + /** + * Base64-encoded file hash + * + * @return string + */ + public function getFileHash(): string + { + return $this->fileHash; + } + + /** + * Base64-encoded file hash + * + * @param string $fileHash + * @return $this + */ + public function setFileHash(string $fileHash): PassportElementErrorTranslationFile + { + $this->fileHash = $fileHash; + return $this; + } + + /** + * Error message + * + * @return string + */ + public function getMessage(): string + { + return $this->message; + } + + /** + * Error message + * + * @param string $message + * @return $this + */ + public function setMessage(string $message): PassportElementErrorTranslationFile + { + $this->message = $message; + return $this; + } + + /** + * @inheritDoc + */ + public function toArray(): ?array + { + return [ + 'source' => $this->getSource()->value, + 'type' => $this->type->value, + 'file_hash' => $this->fileHash, + 'message' => $this->fileHash + ]; + } + } \ No newline at end of file diff --git a/src/TgBotLib/Objects/PassportElementError/PassportElementErrorTranslationFiles.php b/src/TgBotLib/Objects/PassportElementError/PassportElementErrorTranslationFiles.php new file mode 100644 index 0000000..c4aed7e --- /dev/null +++ b/src/TgBotLib/Objects/PassportElementError/PassportElementErrorTranslationFiles.php @@ -0,0 +1,110 @@ +type; + } + + /** + * Type of element of the user's Telegram Passport which has the issue, one of “passport”, “driver_license”, + * “identity_card”, “internal_passport”, “utility_bill”, “bank_statement”, “rental_agreement”, + * “passport_registration”, “temporary_registration” + * + * @param PassportElementErrorType $type + * @return $this + */ + public function setType(PassportElementErrorType $type): PassportElementErrorTranslationFiles + { + $this->type = $type; + return $this; + } + + /** + * List of base64-encoded file hashes + * + * @return string[] + */ + public function getFileHashes(): array + { + return $this->fileHashes; + } + + /** + * List of base64-encoded file hashes + * + * @param array $fileHashes + * @return $this + */ + public function setFileHashes(array $fileHashes): PassportElementErrorTranslationFiles + { + $this->fileHashes = $fileHashes; + return $this; + } + + /** + * Error message + * + * @return string + */ + public function getMessage(): string + { + return $this->message; + } + + /** + * Error message + * + * @param string $message + * @return $this + */ + public function setMessage(string $message): PassportElementErrorTranslationFiles + { + $this->message = $message; + return $this; + } + + /** + * @inheritDoc + */ + public function toArray(): ?array + { + return [ + 'source' => $this->getSource()->value, + 'type' => $this->type->value, + 'file_hashes' => $this->fileHashes, + 'message' => $this->message + ]; + } + } \ No newline at end of file diff --git a/src/TgBotLib/Objects/PassportElementError/PassportElementErrorUnspecified.php b/src/TgBotLib/Objects/PassportElementError/PassportElementErrorUnspecified.php new file mode 100644 index 0000000..33d450c --- /dev/null +++ b/src/TgBotLib/Objects/PassportElementError/PassportElementErrorUnspecified.php @@ -0,0 +1,111 @@ +type = PassportElementErrorType::tryFrom($data['type'] ?? null); + $this->elementHash = $data['element_hash']; + $this->message = $data['message']; + } + + /** + * Type of element of the user's Telegram Passport which has the issue + * + * @return PassportElementErrorType + */ + public function getType(): PassportElementErrorType + { + return $this->type; + } + + /** + * Type of element of the user's Telegram Passport which has the issue + * + * @param PassportElementErrorType $type + * @return $this + */ + public function setType(PassportElementErrorType $type): PassportElementErrorUnspecified + { + $this->type = $type; + return $this; + } + + /** + * Base64-encoded element hash + * + * @return string + */ + public function getElementHash(): string + { + return $this->elementHash; + } + + /** + * Base64-encoded element hash + * + * @param string $elementHash + * @return $this + */ + public function setElementHash(string $elementHash): PassportElementErrorUnspecified + { + $this->elementHash = $elementHash; + return $this; + } + + /** + * Error message + * + * @return string + */ + public function getMessage(): string + { + return $this->message; + } + + /** + * Error message + * + * @param string $message + * @return $this + */ + public function setMessage(string $message): PassportElementErrorUnspecified + { + $this->message = $message; + return $this; + } + + /** + * @inheritDoc + */ + public function toArray(): ?array + { + return [ + 'source' => $this->getSource()->value, + 'type' => $this->type->value, + 'element_hash' => $this->elementHash, + 'message' => $this->message + ]; + } + } \ No newline at end of file