PHP code example of mane-olawale / termii

1. Go to this page and download the library: Download mane-olawale/termii 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/ */

    

mane-olawale / termii example snippets




// This file is generated by Composer
 new Client instance
$client = new Client('{api_key}');

// Create a new Client instance and set options
$client = new Client('{api_key}', [
            'sender_id' => 'Olawale',
            'channel' => 'generic',
            "attempts" => 10,
            "time_to_live" => 30,
            "length" => 6,
            "placeholder" => '{token}',
            'pin_type' => 'ALPHANUMERIC',
            'message_type' => 'ALPHANUMERIC',
            'type' => 'plain',
        ]);

$client->sms->send('2347041945964', 'Hello World!');

// You can change any option later

$client->fillOptions([
            "attempts" => 5,
            "time_to_live" => 20,
            "length" => 4,
            "placeholder" => '{pin}',
        ]);




// This file is generated by Composer
ew Client('{api_key}');

$response = $client->sms->send('2347041945964', 'Hello World!');

// Check for success
if ($response->successful()) {
    // Do something
}

// Check for failed response
if ($response->failed()) {
    // Do something
}



// Run on success
$response->onSuccess(function ($response) {
    // Do something
});

// Run on error
$response->onError(function ($response) {
    // Do something
});


$message_id = $response['message_id'];



foreach ($response as $sender) {
    // Work with each sender data
}




// This file is generated by Composer
ew Client('{api_key}');

$client->sender->list();




// This file is generated by Composer
ew Client('{api_key}');

$client->sender->request('Olawale', 'Friendship based Notifications', 'Mane Olawale');




    // This file is generated by Composer
    ew Client('{api_key}', [
            'sender_id' => '{sender_id}',
            'channel' => '{channel}',
        ]);

    return $client->sms->send('2347041945964', 'Testing');




    // This file is generated by Composer
    ew Client('{api_key}', [
            'sender_id' => '{sender_id}',
            'channel' => '{channel}',
        ]);

    return $client->sms->send('2347041945964', 'Hello World', 'Olawale', 'generic');

    // OR probably omit sender id or channel

    return $client->sms->send('2347041945964', 'Hello World', null, 'generic');


    $client = new Client('{api_key}');

    $response = $client->sms->send('2347041945964', 'Testing');

    $message = $response->message();



    // This file is generated by Composer
    ew Client('{api_key}');

    return $client->sms->number('2347041945964', 'Hello World');




    // This file is generated by Composer
    ew Client('{api_key}');

    return $client->sms->template('2347041945964', '{template_id}', [
            'product_name' => 'Termii',
            'otp' => '120435',
            'expiry_time' => '10 minutes'
    ], '{device_id}');




    // This file is generated by Composer
    ew Client('{api_key}', [
            'sender_id' => '{sender_id}',
            'channel' => '{channel}',
        ]);

    // You can choose to omit the pin options if you have set them when creating the client instance
    return $client->token->sendToken('2347041945964', '{token} is your friendship verification token', [
        "attempts" => 10,
        "time_to_live" => 30,
        "length" => 6,
        "placeholder" => '{token}',
        'type' => 'NUMERIC',
    ]);




    // This file is generated by Composer
    ew Client('{api_key}', [
            'sender_id' => '{sender_id}',
            'channel' => '{channel}',
        ]);

    return $client->token->sendToken('2347041945964', '{token} is your friendship verification token', [
        "attempts" => 10,
        "time_to_live" => 30,
        "length" => 6,
        "placeholder" => '{token}',
        'type' => 'NUMERIC',
    ], 'Olawale', 'generic');

    // OR probably omit sender id or channel

    return $client->token->sendToken('2347041945964', '{token} is your friendship verification token', [
        "attempts" => 10,
        "time_to_live" => 30,
        "length" => 6,
        "placeholder" => '{token}',
        'type' => 'NUMERIC',
    ], null, 'generic');




    // This file is generated by Composer
    ew Client('{api_key}');

    return $client->token->verify('a2d671d7-e4fd-41d5-9b13-30c192309306', '123456');




    // This file is generated by Composer
    ew Client('{api_key}');

    // Returns True if token is verified else returns false
    return $client->token->verified('a2d671d7-e4fd-41d5-9b13-30c192309306', '123456');

    // Returns True if token fails to verify else returns false
    return $client->token->failed('a2d671d7-e4fd-41d5-9b13-30c192309306', '123456');

    // Returns True if token exists but has expired else returns false
    return $client->token->expired('a2d671d7-e4fd-41d5-9b13-30c192309306', '123456');


    $client = new Client('{api_key}');

    $response = $client->token->verify('a2d671d7-e4fd-41d5-9b13-30c192309306', '123456');

    // Check for verified
    if ($response->verified()) {
        // Do something
    }

    // Check for failed response
    if ($response->failed()) {
        // Do something
    }

    // Check for expired response
    if ($response->expired()) {
        // Do something
    }

    // Check for not found response
    if ($response->notFound()) {
        // Do something
    }

    $client = new Client('{api_key}');

    $response = $client->token->verify('a2d671d7-e4fd-41d5-9b13-30c192309306', '123456');

    // Run if verification was successful
    $response->onVerified(function ($response) {
        // Do something
    });

    // Run if verification failed
    $response->onFailed(function ($response) {
        // Do something
    });

    // Run if verification token expired
    $response->onExpired(function ($response) {
        // Do something
    });



    // This file is generated by Composer
    ew Client('{api_key}');

    return $client->token->sendInAppToken('2347041945964', [
        "attempts" => 10,
        "time_to_live" => 30,
        "length" => 6,
    ]);




    // This file is generated by Composer
    ew Client('{api_key}');

    return $client->insights->balance();




    // This file is generated by Composer
    ew Client('{api_key}');

    return $client->insights->inbox();

    /**
     * Get only the data of a specific message by passing its message_id
    */
    return $client->insights->inbox('43224343447041945964');




    // This file is generated by Composer
    ew Client('{api_key}');

    return $client->insights->search('2347041945964');




    // This file is generated by Composer
    ew Client('{api_key}');

    return $client->insights->isDnd('2347041945964');

    // OR

    return $client->insights->isNotDnd('2347041945964');


    $client = new Client('{api_key}');

    $response = $client->insights->search('2347041945964');;

    // Check if the number is dnd active or not
    if ($response->dnd()) {
        // Do something
    }



    // This file is generated by Composer
    ew Client('{api_key}');

    return $client->insights->number('2347041945964');




    namespace ManeOlawale\Termii\HttpClient;

    use Psr\Http\Message\ResponseInterface;

    interface HttpManagerInterface
    {
        /**
         * Handle GET method
         *
         * @since 1.2
         *
         * @param string $method
         * @param string $route
         * @param array $data
         * @return \Psr\Http\Message\ResponseInterface
         */
        public function request(string $method, string $route, array $data): ResponseInterface;
    }

    class GuzzleHttpManager implements HttpManagerInterface
    {
        //
    }




    use ManeOlawale\Termii\HttpClient\GuzzleHttpManager;

    $client = new Client('{api_key}', [/* Config */], new GuzzleHttpManager());




    use ManeOlawale\Termii\HttpClient\GuzzleHttpManager;

    $client = new Client('{api_key}', [/* Config */]);
    
    $client->setHttpManager(new GuzzleHttpManager());