PHP code example of vipertecpro / otp-autofill

1. Go to this page and download the library: Download vipertecpro/otp-autofill 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/ */

    

vipertecpro / otp-autofill example snippets


use Native\Mobile\Attributes\On;
use Native\Mobile\Edge\NativeComponent;
use Vipertecpro\OtpAutofill\Events\OtpFailed;
use Vipertecpro\OtpAutofill\Events\OtpReceived;
use Vipertecpro\OtpAutofill\Facades\OtpAutofill;

class VerifyPhone extends NativeComponent
{
    public string $code = '';
    public string $error = '';

    public function sendCode(): void
    {
        Http::post(config('services.api.url').'/verify/send', ['phone' => $this->phone]);

        OtpAutofill::start(['length' => 6]);      // Android starts listening; iOS: "keyboard"
    }

    #[On(OtpReceived::class)]
    public function onCode(string $code): void
    {
        $this->code = $code;                      // fills the boxes
        $this->verify($code);
    }

    #[On(OtpFailed::class)]
    public function onFailed(string $reason): void
    {
        $this->error = $reason === 'denied' ? '' : 'Type the code from the SMS.';
    }

    public function verify(string $code): void
    {
        // check it with your API
    }
}

OtpAutofill::start();                                     // consent, any sender, 4–8 digits
OtpAutofill::start(['sender' => '+15550100', 'length' => 6]);
OtpAutofill::start(['mode' => 'retriever', 'length' => 6]);
OtpAutofill::stop();

OtpAutofill::appHash();   // "FA+9qCX9VSu" — Android only, null on iOS

OtpAutofill::start(array $options = []): string;   // mode, sender, length
OtpAutofill::stop(): void;
OtpAutofill::appHash(): ?string;
OtpAutofill::extractCode(string $message, ?int $length = null): ?string;