Skip to content

Commit 40760f7

Browse files
committed
WIP: Passport implementation
1 parent 2feeaac commit 40760f7

File tree

12 files changed

+442
-2
lines changed

12 files changed

+442
-2
lines changed

src/Abstracts/TelegramTypes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final protected function populateObject(array $data = []): TelegramTypes
3434
{
3535
foreach ($data as $key => $value) {
3636
$candidateKey = null;
37-
if (is_array($value)) {
37+
if (\is_array($value)) {
3838
$this->logger->debug('Array detected, mapping subobjects for key', ['key' => $key]);
3939
$candidateKey = $this->mapSubObjects($key, $value);
4040
}
@@ -73,7 +73,7 @@ protected function mapSubObjects(string $key, array $data): TelegramTypes
7373
$key,
7474
'https://github.com/unreal4u/telegram-api/issues'
7575
), [
76-
'object' => get_class($this),
76+
'object' => \get_class($this),
7777
'data' => $data,
7878
]);
7979
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace unreal4u\TelegramAPI\Telegram\Methods;
6+
7+
use Psr\Log\LoggerInterface;
8+
use unreal4u\TelegramAPI\Abstracts\TelegramMethods;
9+
use unreal4u\TelegramAPI\Abstracts\TelegramTypes;
10+
use unreal4u\TelegramAPI\InternalFunctionality\TelegramRawData;
11+
use unreal4u\TelegramAPI\Telegram\Types\Custom\ResultBoolean;
12+
use unreal4u\TelegramAPI\Telegram\Types\Passport\PassportElementError;
13+
14+
/**
15+
* Use this method to change the title of a chat. Titles can't be changed for private chats. The bot must be an
16+
* administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success
17+
*
18+
* Note: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’ setting is
19+
* off in the target group
20+
*
21+
* Objects defined as-is july 2017
22+
*
23+
* @see https://core.telegram.org/bots/api#setchattitle
24+
*/
25+
class SetPassportDataErrors extends TelegramMethods
26+
{
27+
/**
28+
* User identifier
29+
* @var string
30+
*/
31+
public $user_id = 0;
32+
33+
/**
34+
* A JSON-serialized array describing the errors
35+
* @var PassportElementError[]
36+
*/
37+
public $errors = [];
38+
39+
public static function bindToObject(TelegramRawData $data, LoggerInterface $logger): TelegramTypes
40+
{
41+
return new ResultBoolean($data->getResultBoolean(), $logger);
42+
}
43+
44+
public function getMandatoryFields(): array
45+
{
46+
return [
47+
'user_id',
48+
'errors',
49+
];
50+
}
51+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace unreal4u\TelegramAPI\Telegram\Types\Custom;
6+
7+
use unreal4u\TelegramAPI\Abstracts\CustomType;
8+
use unreal4u\TelegramAPI\Telegram\Types\Passport\PassportFile;
9+
use unreal4u\TelegramAPI\Telegram\Types\PhotoSize;
10+
use unreal4u\TelegramAPI\Interfaces\CustomArrayType;
11+
use Psr\Log\LoggerInterface;
12+
13+
/**
14+
* Mockup class to generate a real telegram update representation
15+
*/
16+
class PassportFileArray extends CustomType implements CustomArrayType
17+
{
18+
public function __construct(array $data = null, LoggerInterface $logger = null)
19+
{
20+
if (count($data) !== 0) {
21+
foreach ($data as $id => $passportFile) {
22+
$this->data[$id] = new PassportFile($passportFile, $logger);
23+
}
24+
}
25+
}
26+
27+
/**
28+
* Traverses through our $data, yielding the result set
29+
*
30+
* @return PhotoSize[]
31+
*/
32+
public function traverseObject(): \Generator
33+
{
34+
foreach ($this->data as $passportFile) {
35+
yield $passportFile;
36+
}
37+
}
38+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace unreal4u\TelegramAPI\Telegram\Types\Passport\ElementError;
6+
7+
use unreal4u\TelegramAPI\Telegram\Types\Passport\PassportElementError;
8+
9+
/**
10+
* This object represents information about an order
11+
*
12+
* Objects defined as-is may 2017
13+
*
14+
* @see https://core.telegram.org/bots/api#orderinfo
15+
*/
16+
class DataField extends PassportElementError
17+
{
18+
public $source = 'data';
19+
20+
/**
21+
* Name of the data field which has the error
22+
* @var string
23+
*/
24+
public $field_name = '';
25+
26+
/**
27+
* Base64-encoded data hash
28+
* @var string
29+
*/
30+
public $data_hash = '';
31+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace unreal4u\TelegramAPI\Telegram\Types\Passport\ElementError;
6+
7+
use unreal4u\TelegramAPI\Telegram\Types\Passport\PassportElementError;
8+
9+
/**
10+
* This object represents information about an order
11+
*
12+
* Objects defined as-is may 2017
13+
*
14+
* @see https://core.telegram.org/bots/api#orderinfo
15+
*/
16+
class FrontSide extends PassportElementError
17+
{
18+
public $source = 'front_side';
19+
20+
/**
21+
* Base64-encoded hash of the file with the front side of the document
22+
* @var string
23+
*/
24+
public $file_hash = '';
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace unreal4u\TelegramAPI\Telegram\Types\Passport\ElementError;
6+
7+
use unreal4u\TelegramAPI\Telegram\Types\Passport\PassportElementError;
8+
9+
/**
10+
* This object represents information about an order
11+
*
12+
* Objects defined as-is may 2017
13+
*
14+
* @see https://core.telegram.org/bots/api#orderinfo
15+
*/
16+
class ReverseSide extends PassportElementError
17+
{
18+
public $source = 'reverse_side';
19+
20+
/**
21+
* Base64-encoded hash of the file with the front side of the document
22+
* @var string
23+
*/
24+
public $file_hash = '';
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace unreal4u\TelegramAPI\Telegram\Types\Passport\ElementError;
6+
7+
use unreal4u\TelegramAPI\Telegram\Types\Passport\PassportElementError;
8+
9+
/**
10+
* This object represents information about an order
11+
*
12+
* Objects defined as-is july 2018
13+
*
14+
* @see https://core.telegram.org/bots/api#passportelementerrorselfie
15+
*/
16+
class Selfie extends PassportElementError
17+
{
18+
public $source = 'selfie';
19+
20+
/**
21+
* Base64-encoded hash of the file with the front side of the document
22+
* @var string
23+
*/
24+
public $file_hash = '';
25+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace unreal4u\TelegramAPI\Telegram\Types\Passport;
6+
7+
use unreal4u\TelegramAPI\Abstracts\TelegramTypes;
8+
9+
/**
10+
* This object represents information about an order
11+
*
12+
* Objects defined as-is may 2017
13+
*
14+
* @see https://core.telegram.org/bots/api#orderinfo
15+
*/
16+
class EncryptedCredentials extends TelegramTypes
17+
{
18+
/**
19+
* Base64-encoded encrypted JSON-serialized data with unique user's payload, data hashes and secrets required for
20+
* EncryptedPassportElement decryption and authentication
21+
* @var string
22+
*/
23+
public $data = '';
24+
25+
/**
26+
* Base64-encoded data hash for data authentication
27+
* @var string
28+
*/
29+
public $hash = '';
30+
31+
/**
32+
* Base64-encoded secret, encrypted with the bot's public RSA key, required for data decryption
33+
* @var string
34+
*/
35+
public $secret = '';
36+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace unreal4u\TelegramAPI\Telegram\Types\Passport;
6+
7+
use unreal4u\TelegramAPI\Abstracts\TelegramTypes;
8+
use unreal4u\TelegramAPI\Telegram\Types\Custom\PassportFileArray;
9+
10+
/**
11+
* This object represents information about an order
12+
*
13+
* Objects defined as-is may 2017
14+
*
15+
* @see https://core.telegram.org/bots/api#orderinfo
16+
*/
17+
class EncryptedPassportElement extends TelegramTypes
18+
{
19+
/**
20+
* Element type. One of "personal_details", "passport", "driver_license", "identity_card", "internal_passport",
21+
* "address", "utility_bill", "bank_statement", "rental_agreement", "passport_registration",
22+
* "temporary_registration", "phone_number", "email".
23+
* @var string
24+
*/
25+
public $type = '';
26+
27+
/**
28+
* Optional. Base64-encoded encrypted Telegram Passport element data provided by the user, available for
29+
* "personal_details", "passport", "driver_license", "identity_card", "identity_passport" and "address" types. Can
30+
* be decrypted and verified using the accompanying EncryptedCredentials.
31+
* @var string
32+
*/
33+
public $data = '';
34+
35+
/**
36+
* Optional. User's verified phone number, available only for "phone_number" type
37+
* @var string
38+
*/
39+
public $phone_number = '';
40+
41+
/**
42+
* Optional. User's verified email address, available only for "email" type
43+
* @var string
44+
*/
45+
public $email = '';
46+
47+
/**
48+
* Optional. Array of encrypted files with documents provided by the user, available for "utility_bill",
49+
* "bank_statement", "rental_agreement", "passport_registration" and "temporary_registration" types. Files can be
50+
* decrypted and verified using the accompanying EncryptedCredentials.
51+
* @var PassportFileArray
52+
*/
53+
public $files;
54+
55+
/**
56+
* Optional. Encrypted file with the front side of the document, provided by the user. Available for "passport",
57+
* "driver_license", "identity_card" and "internal_passport". The file can be decrypted and verified using the
58+
* accompanying EncryptedCredentials.
59+
* @var PassportFile
60+
*/
61+
public $front_side;
62+
63+
/**
64+
* Optional. Encrypted file with the reverse side of the document, provided by the user. Available for
65+
* "driver_license" and "identity_card". The file can be decrypted and verified using the accompanying
66+
* EncryptedCredentials.
67+
* @var PassportFile
68+
*/
69+
public $reverse_side;
70+
71+
/**
72+
* Optional. Encrypted file with the selfie of the user holding a document, provided by the user; available for
73+
* "passport", "driver_license", "identity_card" and "internal_passport". The file can be decrypted and verified
74+
* using the accompanying EncryptedCredentials.
75+
* @var PassportFile
76+
*/
77+
public $selfie;
78+
79+
public function getMandatoryFields(): array
80+
{
81+
return [
82+
'type',
83+
];
84+
}
85+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace unreal4u\TelegramAPI\Telegram\Types\Passport;
6+
7+
use unreal4u\TelegramAPI\Abstracts\TelegramTypes;
8+
9+
/**
10+
* This object represents information about an order
11+
*
12+
* Objects defined as-is may 2017
13+
*
14+
* @see https://core.telegram.org/bots/api#orderinfo
15+
*/
16+
class PassportData extends TelegramTypes
17+
{
18+
/**
19+
* Array with information about documents and other Telegram Passport elements that was shared with the bot
20+
* @var string
21+
*/
22+
public $data;
23+
24+
/**
25+
* Encrypted credentials required to decrypt the data
26+
* @var EncryptedCredentials
27+
*/
28+
public $credentials;
29+
30+
protected function mapSubObjects(string $key, array $data): TelegramTypes
31+
{
32+
switch ($key) {
33+
case 'data':
34+
// TODO
35+
case 'credentials':
36+
return new EncryptedCredentials($data, $this->logger);
37+
}
38+
39+
return parent::mapSubObjects($key, $data);
40+
}
41+
}

0 commit comments

Comments
 (0)