PHP code example of tooma / laravel-sms-api

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

    

tooma / laravel-sms-api example snippets

config/app.php

php artisan vendor:publish --provider="Tooma\Laravel\Api\Providers\ToomaServiceProvider"
config/tooma-api.php
config/tooma-api.php

 app()->tooma->onSuccess(function($response,$pagination){
          // Logic when Login is successfull
          $apiKey = $response->data->token;

       })->onError(function($response)
       {
           // Logic on Error 
       })->login(['username'=>'YOUR_USERNAME_OR_EMAIL','password'=>'YOUR_PASSWORD']);

 

 $parcel=[
	   ['to'=>'+254XXXXXXXXX','message'=>'Greetings from Tooma'],
	   ......
	];
 app()->tooma->onSuccess(function($response,$pagination){
          // Logic sending is successfull

       })->onError(function($response)
       {
           // Logic on Error 
       })->sendSms($parcel);
  

 $parcel=[
	   ['to'=>'+254XXXXXXXXX','message'=>'Dear XXX Greetings from Tooma'],
	   ['to'=>'+254YYYYYYYYY','message'=>'Dear YYY Greetings from Tooma'],
	   ......
	];
 app()->tooma->onSuccess(function($response,$pagination){
          // Logic sending is successfull
        

       })->onError(function($response)
       {
           // Logic on Error 
       })->sendSms($parcel);
  

 app()->tooma->onSuccess(function($response,$pagination){
          // Logic sending is successfull
           echo "Your balance is $response->data->balance";

       })->onError(function($response)
       {
           // Logic on Error 
       })->balance();
 

  $csvPath = "path/to/your/csv.csv";

  app()->tooma->onSuccess(function($response,$pagination){
          // Logic sending is successfull
           echo "Your balance is $response->data->balance";

       })->onError(function($response)
       {
           // Logic on Error 
       })->withCsv($csvPath)
         ->withPhoneColumn('phone') //name of column with phone
         ->withTemplate('Dear :username_column_name your account balance is :balance_column_name')
         ->sendCsv();
 

  $parcel=[
	   ['to'=>'+254XXXXXXXXX','message'=>'Greetings from Tooma'],
	   ......
	];
  app()->tooma->onSuccess(function($response,$pagination){
          // Logic sending is successfull
           echo "Your balance is $response->data->balance";

       })->onError(function($response)
       {
           // Logic on Error 
       })->schedule("FORMART")
         ->sendSms($parcel);