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.
(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,
],
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
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!');
}
}
You can define a receiver of the message in different ways (listed in order of priority):
-
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'); }
-
Define the receiver with
routeNotificationForZonerSmsGateway
method in your Notifiable:public function routeNotificationForZonerSmsGateway() { return $this->phone; }
-
As the last resort the channel looks for a
phone_number
attribute in the Notifiable.
__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.
Please see CHANGELOG for more information what has changed recently.
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.
If you discover any security related issues, please email info@wysiwyg.fi instead of using the issue tracker.
Please see CONTRIBUTING for details.
- Jarno Antikainen (https://github.com/jarnoan)
- All Contributors
The MIT License (MIT). Please see License File for more information.