zgabievi/laravel-gosms

GoSMS.GE Integration for Laravel

0.1.2 2022-02-05 16:11 UTC

This package is auto-updated.

Last update: 2024-09-05 22:03:19 UTC


README

Packagist Packagist license

laravel-gosms

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.