PHP code example of sawolabs / sawo-laravel

1. Go to this page and download the library: Download sawolabs/sawo-laravel 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/ */

    

sawolabs / sawo-laravel example snippets

config/sawo.php
 php


return [
    /*
    |--------------------------------------------------------------------------
    | Configure Sawo defaults
    |--------------------------------------------------------------------------
    |
    | Supported Identifier Types: "phone_number_sms", "email"
    |
    */

    'api_key' => env('SAWO_API_KEY', ''),

    'api_secret_key' => env('SAWO_SECRET_KEY', ''),

    'identifier_type' => env('SAWO_IDENTIFIER_TYPE', 'email'),

    'redirect_url' => env('SAWO_REDIRECT', ''),
];

 php
use SawoLabs\Laravel\Sawo;

Route::get('/sawo/callback', function () {
    $userData = $request->only('user_id', 'created_on', 'identifier', 'identifier_type', 'verification_token');

    $isVerified = Sawo::validateToken($userData['user_id'], $userData['verification_token']);

    // If user is identifying via phone
    if ('phone_number_sms' == $userData['identifier_type']) {
        $user = User::where('phone', $userData['identifier'])->first();
    } elseif ('email' == $userData['identifier_type']) {
        $user = User::where('email', $userData['identifier'])->first();
    }

    if (empty($user)) {
        $user = new \App\Models\User();
        $user->phone = $userData['identifier'];
        $user->email = $userData['identifier'];
        $user->password = bcrypt($userData['verification_token']);
    }
    
});