PHP code example of mfiyalka / telegram-passport

1. Go to this page and download the library: Download mfiyalka/telegram-passport library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mfiyalka / telegram-passport example snippets


composer 

...
"    "mfiyalka/telegram-passport": "*"
    }
...



use Mfiyalka\TelegramPassport\TelegramPassport;

$passportData = new TelegramPassport($passportData);

// Identity //
// Personal Details
$personalDetails = $passportData->getPersonalDetails();
$firstName = $personalDetails->firstName ?? null;
$lastName = $personalDetails->lastName ?? null;
$birthDate = $personalDetails->birthDate ?? null;
$gender = $personalDetails->gender ?? null;
$countryCode = $personalDetails->countryCode ?? null;
$residenceCountryCode = $personalDetails->residenceCountryCode ?? null;

// Passport
$passport = $passportData->getPassport();
$passportDocumentNo = $passport->idDocumentData()->documentNo ?? null;
$passportExpiryDate = $passport->idDocumentData()->expiryDate ?? null;
$passportFrontSide = null;
if ($passport->frontSide) {
    $toURL = __DIR__ . '/../../../public/img/';
    $passportFrontSide = $passport->getFrontSide($toURL);
}
$passportSelfie = null;
if ($passport->selfie) {
    $toURL = __DIR__ . '/../../../public/img/';
    $passportSelfie = $passport->getSelfie($toURL);
}

// Drive License
$driveLicense = $passportData->getDriveLicense();
$driveLicenseDocumentNo = $driveLicense->idDocumentData()->documentNo ?? null;
$driveLicenseExpiryDate = $driveLicense->idDocumentData()->expiryDate ?? null;
$driveLicenseFrontSide = null;
if ($driveLicense->frontSide) {
    $toURL = __DIR__ . '/../../../public/img/';
    $driveLicenseFrontSide = $driveLicense->getFrontSide($toURL);
}
$driveLicenseReverseSide = null;
if ($driveLicense->reverseSide) {
    $toURL = __DIR__ . '/../../../public/img/';
    $driveLicenseReverseSide = $driveLicense->getReverseSide($toURL);
}
$driveLicenseSelfie = null;
if ($driveLicense->selfie) {
    $toURL = __DIR__ . '/../../../public/img/';
    $driveLicenseSelfie = $driveLicense->getSelfie($toURL);
}

// Identity Card
$identityCard = $passportData->getIdentityCard();
$identityCardDocumentNo = $identityCard->idDocumentData()->documentNo ?? null;
$identityCardExpiryDate = $identityCard->idDocumentData()->expiryDate ?? null;
$identityCardFrontSide = null;
if ($identityCard->frontSide) {
    $toURL = __DIR__ . '/../../../public/img/';
    $identityCardFrontSide = $identityCard->getFrontSide($toURL);
}
$identityCardReverseSide = null;
if ($identityCard->reverseSide) {
    $toURL = __DIR__ . '/../../../public/img/';
    $identityCardReverseSide = $identityCard->getReverseSide($toURL);
}
$identityCardSelfie = null;
if ($identityCard->selfie) {
    $toURL = __DIR__ . '/../../../public/img/';
    $identityCardSelfie = $identityCard->getSelfie($toURL);
}

// Internal Passport
$internalPassportCard = $passportData->getInternalPassport();
$internalPassportDocumentNo = $internalPassportCard->idDocumentData()->documentNo ?? null;
$internalPassportExpiryDate = $internalPassportCard->idDocumentData()->expiryDate ?? null;
$internalPassportFrontSide = null;
if ($internalPassportCard->frontSide) {
    $toURL = __DIR__ . '/../../../public/img/';
    $internalPassportFrontSide = $internalPassportCard->getFrontSide($toURL);
}
$internalPassportSelfie = null;
if ($internalPassportCard->selfie) {
    $toURL = __DIR__ . '/../../../public/img/';
    $internalPassportSelfie = $internalPassportCard->getSelfie($toURL);
}

// Address //
// Residential Address
$residentialAddress = $passportData->getAddress();
$streetLine1 = $residentialAddress->streetLine1 ?? null;
$streetLine2 = $residentialAddress->streetLine2 ?? null;
$city = $residentialAddress->city ?? null;
$state = $residentialAddress->state ?? null;
$addresCountryCode = $residentialAddress->countryCode ?? null;
$postCode = $residentialAddress->postCode ?? null;

// Utility Bill
$utilityBill = $passportData->getUtilityBill();
$utilityBillFiles = null;
if (!is_null($utilityBill->files)) {
    $files = $utilityBill->files;
    $toURL = __DIR__ . '/../../../public/img/';

    $utilityBillFiles = [];
    foreach ($files as $key => $item) {
        $utilityBillFiles[] = $utilityBill->getFile($key, $toURL);
    }
}

// Contact //
$phoneNumber = $passportData->getPhoneNumber()->phoneNumber ?? null;
$email = $passportData->getEmail()->email ?? null;