Download the PHP package kwidoo/sms-verification without Composer
On this page you can find all versions of the php package kwidoo/sms-verification. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kwidoo/sms-verification
More information about kwidoo/sms-verification
Files in kwidoo/sms-verification
Package sms-verification
Short Description A flexible SMS verification package supporting multiple providers
License MIT
Homepage https://github.com/kwidoo/sms-verification
Informations about the package sms-verification
Laravel SMS Verification
A Laravel package for sending and validating SMS-based verification codes through multiple providers (e.g., Twilio, Vonage, or any custom provider**).
Overview
- Round Robin Support: Optionally cycle through multiple providers.
- Pluggable Architecture: Implement your own custom verifier(s).
- Abstracted Interface: A single interface for
create()
(sending code) andvalidate()
(checking code).
Table of Contents
- Installation
- Configuration
- Usage
- Basic Usage
- Round Robin Usage
- Custom Verifiers
- Console Command
- Example Code
- Credits
- License
- TODO
Installation
-
Require via Composer:
-
Publish Config (Optional):
This will publish
sms-verification.php
into your Laravelconfig
directory. -
Configure Environment Variables:
In your
.env
file, make sure to set the appropriate credentials for your desired providers. For example:
Configuration
The default configuration file sms-verification.php
looks like this:
default
: Indicates the default SMS provider if one is not explicitly specified.round_robin
: An array of provider keys to use in a rotating fashion whenRoundRobinVerifier
is requested.round_robin_cache_key
: Cache key used to persist the index in the round-robin cycle.twilio
,vonage
: Provider-specific credentials and settings.
Usage
Basic Usage
If you only want to use one provider (e.g., Twilio) for all verifications:
- Set
'default' => 'twilio'
insms-verification.php
. - In your code, you can do something like:
Round Robin Usage
If you want to rotate between providers (e.g., Twilio → Vonage → Twilio → Vonage…), you can request the round-robin verifier:
round_robin
is an array of strings referencing your verifiers:['twilio', 'vonage']
.- In your code, you might do:
The round-robin verifier will:
- On
create()
, pick the next provider in a cycle, send the verification code, and remember which provider was used for that phone number. - On
validate()
, retrieve that same provider to check the code.
Custom Verifiers
You can create your own SMS verifier by:
- Creating a class that implements
VerifierInterface
(or extend the baseVerifier
class). - Register it in the container or simply reference its FQN in
sms-verification.verifiers
.
Example:
Then, in sms-verification.php
:
And in code:
Console Command
This package includes a console command to generate new custom verifiers from a stub:
If you omit {name}
, the command will prompt you to enter the verifier’s class name. It also asks for the client class (namespace) that the verifier should inject.
The newly generated file will be placed in app/Verifiers/{Name}.php
. You can customize paths or logic within the command class CreateSmsVerifier
.
Example Code
Here’s a quick example to tie it all together:
Credits
- Twilio for their robust Verify service.
- Vonage (formerly Nexmo) for their Verify APIs.
- Sinch for their SMS verification service.
- Telnyx for their Verify API.
- Plivo for their SMS verification service.
- seven.io for their SMS verification service.
- Telesign for their SMS verification service.
- Laravel community for a great framework to extend.
License
This package is open-sourced software licensed under the MIT license.
TODO
- [ ] Make more round-robin strategies (e.g., Weighted Round Robin, Random, etc.).
- [ ] Implement a “fallback” approach (try one provider; if it fails, try another).
- [x] Add tests.
- [ ] Add webhook support to better handle fails
- [ ] Add support for other SMS providers:
- [x] Plivo
- [x] Sinch
- [x] seven.io
- [x] Telesign
- [ ] ClickSend
- [ ] Textmagic
- [ ] SlickText
- [ ] Infobip
- [ ] Routee
- [x] Telnyx
All versions of sms-verification with dependencies
twilio/sdk Version ^8.3
vonage/client Version ^4.1
telnyx/telnyx-php Version ^3.0
plivo/plivo-php Version ^4.66.5
seven.io/api Version 6.0.0