aasanakey / smsonline
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^7.0
- illuminate/notifications: ^8.0|^9.0|^10.0
- illuminate/support: ^8.0|^9.0|^10.0
Requires (Dev)
- orchestra/testbench: ^6.0|^7.0|^8.13
- phpunit/phpunit: ^10.1.0
Suggests
- guzzlehttp/guzzle: Required to use the HTTP Client (^7.6).
README
Send Laravel Notifications via the smsonline GH SMS API
Installation
You can install the package via composer:
composer require aasanakey/smsonline
First you must install the service provider (skip for Laravel>=5.5):
// config/app.php 'providers' => [ ... \Aasanakey\Smsonline\SmsonlineServiceProvider::class, ],
You can publish the config file with:
php artisan vendor:publish --tag=smsonline-config
or
php artisan vendor:publish --provider="Aasanakey\Smsonline\SmsonlineServiceProvider" --tag="smsonline-config"
Configuration
Add your smsonline Gh api access key, api host, sender Id/sender name.
Set your smsonline Gh api keys in your .env file.
SMSONLINE_HOST=Sms online api host
Or
Add api host to your config/smsonline.php
:
// config/services.php ... "host" => env('SMSONLINE_HOST','api.smsonlinegh.com'), ...
Set your smsonline Gh api keys in your .env file.
SMSONLINE_API_KEY=your smsonline api key
Or
Add your API Key to your config/smsonline.php
:
// config/services.php ... "api_key" => env('SMSONLINE_API_KEY',null), ...
For your smsonline API Key visit SMS API
Set your smsonline Gh sender Id in your .env file.
SMSONLINE_SENDER_ID=your sender ID
Or
Add your Send Id to your config/smsonline.php
:
// config/services.php ... "sender_id" => env('SMSONLINE_SENDER_ID',null), ...
For your smsonline API Key visit Sender Name
Usage
Now you can use the channel in your via()
method inside the notification as well as send an sms notification using the smsonline api:
use Illuminate\Notifications\Notification; use Aasanakey\Smsonline\SmsonlineSmsMessage; class SMSNotification extends Notification { public function via($notifiable) { return ['smsonlinegh']; } public function toSmsonline($notifiable) { return (new SmsonlineSmsMessage) ->sender('Sender ID') ->content('Your account was approved!') ->personalisedValues("List of data for personnalised message content"); // call this method if content has message variables placeholders } }
Check balance
To check your sms balance use the checkBalance()
method on SMSAPI object:
use Aasanakey\Smsonline\Sms; $sms = new Sms(); $balance = $api->balance(); // returns balance info object $amount = $balance->ammount // returns balance ammount $currencyName = $balance->currencyName // returns the balance currency name $currencyCode = $balance->currencyCode // return the balance ccurrency code