zgabievi / laravel-gosms
GoSMS.GE Integration for Laravel
Installs: 21
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 1
Type:project
Requires
- php: ^7.2|^8.0
- ext-curl: *
- bensampo/laravel-enum: ^1.38|^2.1|^3.3
- illuminate/config: ^6.0|^7.0|^8.0
- illuminate/support: ^6.0|^7.0|^8.0
README
Table of Contents
Installation
To get started, you need to install package:
composer require zgabievi/laravel-gosms
If your laravel version is older than 5.5, then add this to your service providers in config/app.php:
'providers' => [ ... Zorb\GoSMS\GoSMSServiceProvider::class, ... ];
You can publish config file using this command:
php artisan vendor:publish --provider="Zorb\GoSMS\GoSMSServiceProvider"
This command will copy config file in your config directory.
Usage
Send Message
use Zorb\GoSMS\Facades\GoSMS; class MessageController extends Controller { // public function __invoke() { // recipient who should get sms $mobile_number = '9955XXXXXXXX'; // content of the message $message = 'Welcome, you are getting this message from integration'; // brand name, if empty, config value will be used $brand = 'MY_BRAND'; $result = GoSMS::send($mobile_number, $message, $brand); if ($result->success) { // $result->success // $result->messageId // $result->from // $result->to // $result->text // $result->sendAt // $result->balance // $result->encode // $result->segment // $result->smsCharacters } else { // message was not sent } } }
Check Status
use Zorb\GoSMS\Facades\GoSMS; class MessageController extends Controller { // public function __invoke() { // message id provided by send method $message_id = 0000; $result = GoSMS::status($message_id); if ($result->success) { // $result->success // $result->messageId // $result->from // $result->to // $result->text // $result->sendAt // $result->encode // $result->segment // $result->smsCharacters // $result->status if ($result->status === 'DELIVERED') { // message has been delivered } } else { // message status check failed } } }
Send OTP
use Zorb\GoSMS\Facades\GoSMS; class MessageController extends Controller { // public function __invoke() { // recipient who should get sms $mobile_number = '9955XXXXXXXX'; $result = GoSMS::sendOTP($mobile_number); if ($result->success) { // $result->success // $result->hash // $result->to // $result->sendAt // $result->encode // $result->segment // $result->smsCharacters } else { // message wasn't sent } } }
Verify OTP
use Zorb\GoSMS\Facades\GoSMS; class MessageController extends Controller { // public function __invoke() { // recipient who should get sms $mobile_number = '9955XXXXXXXX'; // hash was received from otp send method $hash = 'asd987asd76fds6f5sd7fsdf'; // otp code from user input $code = '1234'; $result = GoSMS::verifyOTP($mobile_number, $hash, $code); if ($result->success) { // $result->success // $result->verify if ($result->verify) { // otp has been verified } } else { // otp couldn't be checked } } }
Check Balance
use Zorb\GoSMS\Facades\GoSMS; class MessageController extends Controller { // public function __invoke() { $result = GoSMS::balance(); if ($result->success) { // $result->success // $result->balance } else { // balance couldn't be checked } } }
Notification
You can use this package as notification channel.
use Illuminate\Notifications\Notification; use Zorb\GoSMS\Notifications\SMSMessage; use Zorb\GoSMS\Channels\GoSMSChannel; class WelcomeNotification extends Notification { // public function via($notifiable) { return [GoSMSChannel::class]; } // public function toGoSMS($notifiable): SMSMessage { return (new SMSMessage()) ->content('Your message goes here.') ->recipient($notifiable->phone); } }
Additional Information
Errors
Errors has its own enum Zorb\GoSMS\Enums\Errors
Configuration
You can configure environment file with following variables:
License
zgabievi/laravel-gosms is licensed under a MIT License.