Awesome
GoSMS.GE Integration for Laravel
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
Key | Value |
---|---|
INVALID_API_KEY | 100 |
INVALID_BRAND_NAME | 101 |
NOT_ENOUGH_BALANCE | 102 |
MESSAGE_TOO_LONG | 103 |
Configuration
You can configure environment file with following variables:
Key | Type | Default | Meaning |
---|---|---|---|
GOSMS_DEBUG | bool | false | This value decides to log or not to log requests. |
GOSMS_API_KEY | string | This is the api key, which should be generated on gosms.ge. | |
GOSMS_API_URL | string | https://api.gosms.ge/api | This is the url provided gosms.ge api docs. |
GOSMS_BRAND | string | This is the brand name which you should have registered on gosms.ge. |
License
zgabievi/laravel-gosms is licensed under a MIT License.