|
| 1 | +# Laravel service provider for MSG91 |
| 2 | + |
| 3 | +_This library requires a minimum PHP version of 7.1_ |
| 4 | + |
| 5 | +This is a **[laravel](https://laravel.com) service provider** for [MSG91 APIs](https://docs.msg91.com/collection/msg91-api-integration/5/pages/139). It wraps the [msg91-php][client] client and provides the same functionality for Laravel applications by exposing a Service Provider and Facade. |
| 6 | + |
| 7 | +> **NOTE**: The project is under active development and so, some apis are subjected to change before of `v1.0.0` release. |
| 8 | +
|
| 9 | +## Table of Contents |
| 10 | + |
| 11 | +- [Installation](#installation) |
| 12 | +- [Configuration](#configuration) |
| 13 | +- [Usage](#usage) |
| 14 | +- [Examples](#examples) |
| 15 | + - [Create a Client](#create-a-client) |
| 16 | + - [Managing OTPs](#managing-otps) |
| 17 | + - [Send OTP](#send-otp) |
| 18 | + - [Verify OTP](#verify-otp) |
| 19 | + - [Resend OTP](#resend-otp) |
| 20 | + |
| 21 | +## Installation |
| 22 | + |
| 23 | +The packages is available on [Packagist](https://packagist.org/packages/craftsys/msg91-laravel) and can be installed via [Composer](https://getcomposer.org/) by executing following command in shell. |
| 24 | + |
| 25 | +```bash |
| 26 | +composer require creaftsys/msg91-laravel |
| 27 | +``` |
| 28 | + |
| 29 | +### Laravel 5.5+ |
| 30 | + |
| 31 | +If you're using Laravel 5.5 or above, the package will automatically register the `Craftsys\Laravel\MSGClient91\MSG91ServiceProvider` provider and aliases `Craftsys\Laravel\MSGClient91\Facade` facade to `MSG91`. |
| 32 | + |
| 33 | +### Laravel 5.4 and below |
| 34 | + |
| 35 | +Add `Craftsys\Laravel\MSGClient91\MSG91ServiceProvider` to the `providers` array in your `config/app.php`: |
| 36 | + |
| 37 | +```php |
| 38 | +'providers' => [ |
| 39 | + // Other service providers... |
| 40 | + Craftsys\Laravel\MSGClient91\MSG91ServiceProvider::class, |
| 41 | +], |
| 42 | +``` |
| 43 | + |
| 44 | +If you want to use the facade interface, you can `use` the facade class when needed: |
| 45 | + |
| 46 | +```php |
| 47 | +use Craftsys\Laravel\MSGClient91\Facade; |
| 48 | +``` |
| 49 | + |
| 50 | +Or add an alias in your `config/app.php` |
| 51 | + |
| 52 | +```php |
| 53 | +'aliases' => [ |
| 54 | + // other aliases here |
| 55 | + 'MSG91' => Craftsys\Laravel\MSGClient91\Facade::class, |
| 56 | +], |
| 57 | +``` |
| 58 | + |
| 59 | +## Configuration |
| 60 | + |
| 61 | +As the [msg91-php][client] offers configuration that are similar to Laravel's configuration, this package simply ports the Laravel's configuration to the msg91-php client. |
| 62 | + |
| 63 | +The package can be configured by providing a `msg91` key inside your `config/services.php` configuration file. |
| 64 | + |
| 65 | +```php |
| 66 | +<?php |
| 67 | + |
| 68 | +return [ |
| 69 | + // along with other services |
| 70 | + "msg91": [ |
| 71 | + 'key' => env("MSG91_KEY"), |
| 72 | + ], |
| 73 | +]; |
| 74 | +``` |
| 75 | + |
| 76 | +and update the `.env` file to get the desired values e.g. `MSG91_KEY`. |
| 77 | + |
| 78 | +Please visit [msg91-php configuration][client-configuration] for a detailed description about the available options and their default values. |
| 79 | + |
| 80 | +## Usage |
| 81 | + |
| 82 | +Once you have [Configured](#configuration) the Laravel/Lumen application to use the service provider and have aliased the facade to `MSG91`, you will have to [msg91-php][client] client `Craftsys\MSG91\Client`'s instance. |
| 83 | + |
| 84 | +```php |
| 85 | +MSG91::otp() |
| 86 | + ->to(919999999999) |
| 87 | + ->send() |
| 88 | +``` |
| 89 | + |
| 90 | +Next, follow along with [examples](#examples) to learn more |
| 91 | + |
| 92 | +## Examples |
| 93 | + |
| 94 | +### Managing OTPs |
| 95 | + |
| 96 | +OTP services like sending, verifying, and resending etc, can be accessed via `otp` method on the client instance e.g. `MGS91::otp()`. |
| 97 | + |
| 98 | +> For a detailed usage, please visit [msg91-php's documentation][client-managing-otps] on managing OTPs. |
| 99 | +
|
| 100 | +#### Send OTP |
| 101 | + |
| 102 | +```php |
| 103 | +MGS91::otp() |
| 104 | + ->to(912343434312) // phone number with country code |
| 105 | + ->send(); // send the otp |
| 106 | +``` |
| 107 | + |
| 108 | +### Verify OTP |
| 109 | + |
| 110 | +```php |
| 111 | +MSG91::otp(1234) // OTP to be verified |
| 112 | + ->to(912343434312) // phone number with country code |
| 113 | + ->verify(); // Verify |
| 114 | +``` |
| 115 | + |
| 116 | +### Resend OTP |
| 117 | + |
| 118 | +```php |
| 119 | +MSG91::otp() |
| 120 | + ->to(912343434312) // set the mobile with country code |
| 121 | + ->via("text") // way of retry |
| 122 | + ->resend(); // resend otp |
| 123 | +``` |
| 124 | + |
| 125 | +> For all the examples and options, please consult [msg91-php examples section][client-examples] |
| 126 | +
|
| 127 | +[client]: https://github.com/craftsys/msg91-php |
| 128 | +[client-configuration]: https://github.com/craftsys/msg91-php#configuration |
| 129 | +[client-examples]: https://github.com/craftsys/msg91-php#examples |
| 130 | +[client-managing-otps]: https://github.com/craftsys/msg91-php#managing-otps |
0 commit comments