Download the PHP package mane-olawale/laravel-termii without Composer
On this page you can find all versions of the php package mane-olawale/laravel-termii. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mane-olawale/laravel-termii
More information about mane-olawale/laravel-termii
Files in mane-olawale/laravel-termii
Package laravel-termii
Short Description A Laravel package for Termii SMS API.
License MIT
Homepage https://github.com/mane-olawale/laravel-termii
Informations about the package laravel-termii
Termii Laravel Package
A package for integrating termii services with your laravel application.
Uses Termii Client.
Requirements
- PHP ^7.2|8.0
- Termii Client ^1.2,
- Laravel ^6.0|^7.0|^8.0
Installation
Via Composer.
To get the latest version of Laravel Termii, simply run at the root of your laravel project.
After Composer has installed the Laravel termii package, you may run the termii:install
Artisan command. This command publishes the configuration file of the package named termii.php
:
Setup
Open your .env file and add your api key, sender id, channel and so on:
Basic usage
Send sms using the termii facade class
Services
You can access the client services directly by calling them as function on the facade class
Notification channel
This package provides you with a notification channel that enables you to send sms through the notification feature of laravel like so:
Create a notification class
Add termii channel to the notification
Add route to user So the notification channel can get the user`s phone number.
More on TermiiMessage
Working with the message content:
You can configure the sms sent through the notification channel by chaining methods to the TermiiMessage object like so:
Note
The default message type is unicode as at the time of writing, but you can use the
TermiiMessage::type()
method to set any type that may later be introduced.- If these configurations are not done the default configuration will be used.
Working with OTP
This package provides you with the appropriate tool to send and verify OTP in stateless or stateful request.
Stateful OTP
This package can send OTP within stateful requests, it relies on session to store the pin_id and other data by representing the it with a tag like so:
Note:
- You can chain these methods together.
- The Token::start() method will send the OTP and return
self
.
Stateless OTP
This package can send OTP within stateless requests, it relies on JWT to securely hold that data in an encrypted string:
Verifying OTP
Stateful OTP
Stateless OTP
In App OTP
You can create in app token by chaining the Token::inApp()
method to your token like so:
More on OTP
You can retrieve some token properties after calling the Token::start()
method:
Chaining methods
Testing
This package support TDD in so you can build fast with confidence.
Endpoint aliases
Endpoints are represented with aliases for easy mocking and asserting. these are the available aliases:
Alias | Endpoint |
---|---|
sender | api/sender-id |
request | api/sender-id/request |
send | api/sms/send |
number | api/sms/number/send |
template | api/send/template |
otp | api/sms/otp/send |
verify | api/sms/otp/verify |
inapp | api/sms/otp/generate |
balance | api/get-balance |
search | api/insight/number/query |
inbox | api/sms/inbox |
Mocking and Sequence
Sequence Sequence lets you create a collection of responses that will start from the first element when the list is excusted.
Mocking with sequence
The example below will mock the send
endpoint with a response.
Note: mocking works for all aliases and not only for
send
Asserting
Assert no sent
Note: This works for all aliases and not only for
send
Assert successful and Failed requests
In this example we will assert the endpoint responded with response code within the range of 100 - 299
or Not.
Note: This works for all aliases and not only for
send
Deep Assertion
You can assert the request and response object deeper using the Termii::assert()
method.
With Closure
Note:
- This works for all aliases and not only for
send
- This only assert the first pair of request and response so if you want more assertion use Sequence below.
With Sequence
Fallback response
If you do not mork the endpoint that will be invoked in your application, the default fallback response will be an empty successful json response. but you can change it using the Termii::fallbackResponse()
Note Testing is important in your application. Every part of your application should be tested, most especially the part integrating with other systems that you do not maintain. This is why i take the pain of providing this package with TDD support so you can create and assert the behaviour of your laravel application just to make sure everything is working as it should. ~ Olawale
All versions of laravel-termii with dependencies
mane-olawale/termii Version ^1.2
illuminate/notifications Version ^6.0|^7.0|^8.0|^9.0|^10.0
illuminate/support Version ^6.0|^7.0|^8.0|^9.0|^10.0