Skip to content

wysiwygoy/zoner-sms-gateway

 
 

Repository files navigation

Zoner SMS Gateway Notifications Channel for Laravel 5.4

Latest Version on Packagist Software License Build Status StyleCI SensioLabsInsight Quality Score Code Coverage Total Downloads

This package makes it easy to send notifications using Zoner SMS-Gateway with Laravel 5.4. Zoner SMS-Gateway is mainly targeted for Finnish customers.

This is an unofficial package and not developed or endorsed by Zoner.

Contents

Installation

(Once we get it there) You can install the package via composer:

composer require laravel-notification-channels/zoner-sms-gateway

You must install the service provider:

// config/app.php
'providers' => [
    ...
    NotificationChannels\ZonerSmsGateway\ZonerSmsGatewayServiceProvider::class,
],

Setting up the Zoner SMS-Gateway service

In order to use Zoner SMS-Gateway service you need to have an account and some credits on the account.

Then, configure your Zoner SMS-Gateway credentials:

// config/services.php
...
'zoner-sms-gateway' => [
    'username' => env('ZONER_USERNAME'),
    'password' => env('ZONER_PASSWORD'),
    'sender' => env('ZONER_SENDER'), // Default sender number or name
],
...
# .env
ZONER_USERNAME=myusername
ZONER_PASSWORD=mypassword
ZONER_SENDER=mysender

Usage

You can now use the channel in your via() method inside the Notification class.

use NotificationChannels\ZonerSmsGateway\ZonerSmsGatewayChannel;
use NotificationChannels\ZonerSmsGateway\ZonerSmsGatewayMessage;
use Illuminate\Notifications\Notification;

class InvoicePaid extends Notification
{
    public function via($notifiable)
    {
        return [ZonerSmsGatewayChannel::class];
    }

    public function toZonerSmsGateway($notifiable)
    {
        return new ZonerSmsGatewayMessage('One of your invoices has been paid!');
    }
}

Routing a message

You can define a receiver of the message in different ways (listed in order of priority):

  1. Set the receiver in the message (in toZonerSmsGateway method of your Notification):

        public function toZonerSmsGateway($notifiable)
        {
            return new ZonerSmsGatewayMessage('One of your invoices has been paid!')
                ->receiver('3580123456789');
        }
  2. Define the receiver with routeNotificationForZonerSmsGateway method in your Notifiable:

        public function routeNotificationForZonerSmsGateway()
        {
            return $this->phone;
        }
  3. As the last resort the channel looks for a phone_number attribute in the Notifiable.

Available Message methods

  • __construct(string $content = null): Constructs a new message, with optional content.
  • content(string $content): Sets the content of the message.
  • receiver(string $number): Sets the receiver phone number.
  • sender(string $numberOrName): Sets the sender phone number or name.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

Running the unit tests:

$ composer test

Running the integration test:

$ composer test tests-integration

This expects a tests-integration/.env file with ZONER_USERNAME, ZONER_PASSWORD and ZONER_TEST_RECEIVER variables defined.

The test sends a real SMS message via Zoner SMS-Gateway, so it uses your credits. Be careful with the receiver phone number.

Security

If you discover any security related issues, please email info@wysiwyg.fi instead of using the issue tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Laravel notification channel for Zoner SMS Gateway.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 99.5%
  • Shell 0.5%