|
6 | 6 | [](https://github.com/codebar-ag/laravel-twilio-verify/actions/workflows/psalm.yml) |
7 | 7 | [](https://github.com/codebar-ag/laravel-twilio-verify/actions/workflows/php-cs-fixer.yml) |
8 | 8 |
|
9 | | -This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. |
| 9 | +This package was developed to give you a quick start to communicate start and |
| 10 | +check a verification with Twilio Verify. |
10 | 11 |
|
11 | | -## Installation |
| 12 | +⚠️ This package is not designed as a replacement of the official |
| 13 | +[Twilio REST API](https://www.twilio.com/docs/verify/api). |
| 14 | +See the documentation if you need further functionality. ⚠️ |
| 15 | + |
| 16 | +## 💡 What is Twilio Verify? |
| 17 | +An elegant third-party integration to validate users with SMS, Voice, Email and |
| 18 | +Push. Add verification to any step of your user‘s journey with a single API. |
| 19 | + |
| 20 | +## 🛠 Requirements |
| 21 | + |
| 22 | +- PHP: `^8.0` |
| 23 | +- Laravel: `^8.12` |
| 24 | +- Twilio Account |
| 25 | + |
| 26 | +## ⚙️ Installation |
12 | 27 |
|
13 | 28 | You can install the package via composer: |
14 | 29 |
|
15 | 30 | ```bash |
16 | | -composer require codebar-ag/laravel_twilio_verify |
| 31 | +composer require codebar-ag/laravel-twilio-verify |
17 | 32 | ``` |
18 | 33 |
|
19 | | -You can publish and run the migrations with: |
| 34 | +Add the following environment variables to your `.env` file: |
20 | 35 |
|
21 | 36 | ```bash |
22 | | -php artisan vendor:publish --provider="CodebarAg\TwilioVerify\TwilioVerifyServiceProvider" --tag="laravel_twilio_verify-migrations" |
23 | | -php artisan migrate |
| 37 | +TWILIO_ACCOUNT_SID=ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
| 38 | +TWILIO_AUTH_TOKEN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
| 39 | +TWILIO_SERVICE_SID=VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
| 40 | +``` |
| 41 | + |
| 42 | +## 🏗 Usage |
| 43 | + |
| 44 | +```php |
| 45 | +use CodebarAg\TwilioVerify\Facades\TwilioVerify; |
| 46 | + |
| 47 | +/** |
| 48 | + * Start a new SMS verification to the phone number. |
| 49 | + */ |
| 50 | +$verificationStart = TwilioVerify::start(to: '+12085059915'); |
| 51 | + |
| 52 | +/** |
| 53 | + * Check a verification code. |
| 54 | + */ |
| 55 | +$verificationCheck = TwilioVerify::check(to: '+12085059915', code: '1337'); |
24 | 56 | ``` |
25 | 57 |
|
| 58 | +### 🔢 Verification Code Limits |
| 59 | + |
| 60 | +- The generated code is valid for (10 minutes)[ https://www.twilio.com/docs/verify/api/rate-limits-and-timeouts]. |
| 61 | +- You have attempted to send the verification code more than 5 times and have |
| 62 | + (reached the limit)[https://www.twilio.com/docs/api/errors/60203]. |
| 63 | + |
| 64 | +## 🏋️ DTO showcase |
| 65 | + |
| 66 | +```php |
| 67 | +CodebarAg\TwilioVerify\DTO\SendCodeAttempt { |
| 68 | + +time: Illuminate\Support\Carbon // Carbon |
| 69 | + +channel: "sms" // string |
| 70 | + +attempt_sid: "VLMn1NOnmIVWMITO4FbVGxNmEMJ72KKaB2" // string |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +```php |
| 75 | +CodebarAg\TwilioVerify\DTO\Lookup { |
| 76 | + +carrier: CodebarAg\TwilioVerify\DTO\Carrier { |
| 77 | + +error_code: null // ?string |
| 78 | + +name: "Carrier Name" // string |
| 79 | + +mobile_country_code: "310" // string |
| 80 | + +mobile_network_code: "150" // string |
| 81 | + +type: "150" // string |
| 82 | + } |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +```php |
| 87 | +CodebarAg\TwilioVerify\DTO\VerificationStart |
| 88 | + +sid: "VEkEJNNkLugY4hietPDbcqUUZz3G5NoTTZ" // string |
| 89 | + +service_sid: "VAssMsB84NdN0aJJceYsExX1223qAmrubx" // string |
| 90 | + +account_sid: "ACizUsoInA3dbKR5LA9tOqqA0O3NFSHSNc" // string |
| 91 | + +to: "+41795555825" // string |
| 92 | + +channel: "sms" // string |
| 93 | + +status: "pending" // string |
| 94 | + +valid: false // bool |
| 95 | + +created_at: Illuminate\Support\Carbon // Carbon |
| 96 | + +updated_at: Illuminate\Support\Carbon // Carbon |
| 97 | + +lookup: CodebarAg\TwilioVerify\DTO\Lookup {...} // Lookup |
| 98 | + +send_code_attempts: Illuminate\Support\Collection { // Collection |
| 99 | + 0 => CodebarAg\TwilioVerify\DTO\SendCodeAttempt { |
| 100 | + +time: Illuminate\Support\Carbon // Carbon |
| 101 | + +channel: "sms" // string |
| 102 | + +attempt_sid: "VLTvj9jhh76cI78Hc1x0c3UORWJwwqVeTN" // string |
| 103 | + } |
| 104 | + ] |
| 105 | + } |
| 106 | + +url: "https://verify.twilio.com/v2/Services/VAssMsB84NdN0aJJceYsExX1223qAmrubx/Verifications" // string |
| 107 | +} |
| 108 | +``` |
| 109 | + |
| 110 | +```php |
| 111 | +CodebarAg\TwilioVerify\DTO\VerificationCheck { |
| 112 | + +sid: "VEvRzh4hPUqmAjeC6li092VNT0yfd23lag" // string |
| 113 | + +service_sid: "VAxSR0Wq91djjG9PAYtrtjt11f0I4lqdwa" // string |
| 114 | + +account_sid: "ACcI5zbEYvLr0vPIUTQzWkTpP5DPqTCYDK" // string |
| 115 | + +to: "+41795555825" // string |
| 116 | + +channel: "sms" // string |
| 117 | + +status: "approved" // string |
| 118 | + +valid: true // bool |
| 119 | + +created_at: Illuminate\Support\Carbon // Carbon |
| 120 | + +updated_at: Illuminate\Support\Carbon // Carbon |
| 121 | +} |
| 122 | +``` |
| 123 | + |
| 124 | +## 🔧 Configuration file |
| 125 | + |
26 | 126 | You can publish the config file with: |
27 | 127 | ```bash |
28 | | -php artisan vendor:publish --provider="CodebarAg\TwilioVerify\TwilioVerifyServiceProvider" --tag="laravel_twilio_verify-config" |
| 128 | +php artisan vendor:publish --provider="CodebarAg\TwilioVerify\TwilioVerifyServiceProvider" --tag="laravel-twilio-verify-config" |
29 | 129 | ``` |
30 | 130 |
|
31 | 131 | This is the contents of the published config file: |
32 | 132 |
|
33 | 133 | ```php |
| 134 | + |
34 | 135 | return [ |
| 136 | + |
| 137 | + /* |
| 138 | + |-------------------------------------------------------------------------- |
| 139 | + | Twilio Verify Configuration |
| 140 | + |-------------------------------------------------------------------------- |
| 141 | + | |
| 142 | + | You can find your Account SID and Auth Token in the Console Dashboard. |
| 143 | + | Additionally you should create a new Verify service and paste it in |
| 144 | + | here. Afterwards you are ready to communicate with Twilio Verify. |
| 145 | + | |
| 146 | + */ |
| 147 | + |
| 148 | + 'url' => env('TWILIO_URL', 'https://verify.twilio.com/v2/Services'), |
| 149 | + 'account_sid' => env('TWILIO_ACCOUNT_SID', 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'), |
| 150 | + 'auth_token' => env('TWILIO_AUTH_TOKEN', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'), |
| 151 | + 'service_sid' => env('TWILIO_SERVICE_SID', 'VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'), |
| 152 | + |
35 | 153 | ]; |
36 | 154 | ``` |
37 | 155 |
|
38 | | -## Usage |
| 156 | +## ✨ Events |
39 | 157 |
|
40 | | -```php |
41 | | -$laravel_twilio_verify = new CodebarAg\TwilioVerify(); |
42 | | -echo $laravel_twilio_verify->echoPhrase('Hello, Spatie!'); |
| 158 | +Following events are fired: |
| 159 | + |
| 160 | +```php |
| 161 | +use CodebarAg\TwilioVerify\Events\TwilioVerifyResponseLog; |
| 162 | + |
| 163 | +// Log each response from the Twilio REST API. |
| 164 | +TwilioVerifyResponseLog::class => [ |
| 165 | + // |
| 166 | +], |
| 167 | +``` |
| 168 | + |
| 169 | +## 🚧 Testing |
| 170 | + |
| 171 | +Copy your own phpunit.xml-file. |
| 172 | +```bash |
| 173 | +cp phpunit.xml.dist phpunit.xml |
43 | 174 | ``` |
44 | 175 |
|
45 | | -## Testing |
| 176 | +Modify environment variables in the phpunit.xml-file: |
| 177 | +```xml |
| 178 | +<env name="TWILIO_ACCOUNT_SID" value="ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"/> |
| 179 | +<env name="TWILIO_AUTH_TOKEN" value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"/> |
| 180 | +<env name="TWILIO_SERVICE_SID" value="VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"/> |
| 181 | +``` |
46 | 182 |
|
| 183 | +Run the tests: |
47 | 184 | ```bash |
48 | 185 | composer test |
49 | 186 | ``` |
50 | 187 |
|
51 | | -## Changelog |
| 188 | +## 📝 Changelog |
52 | 189 |
|
53 | 190 | Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. |
54 | 191 |
|
55 | | -## Contributing |
| 192 | +## ✏️ Contributing |
56 | 193 |
|
57 | 194 | Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details. |
58 | 195 |
|
59 | | -## Security Vulnerabilities |
| 196 | +## 🧑💻 Security Vulnerabilities |
60 | 197 |
|
61 | 198 | Please review [our security policy](../../security/policy) on how to report security vulnerabilities. |
62 | 199 |
|
63 | | -## Credits |
| 200 | +## 🙏 Credits |
64 | 201 |
|
65 | 202 | - [Ruslan Steiger](https://github.com/SuddenlyRust) |
66 | 203 | - [All Contributors](../../contributors) |
| 204 | +- [Skeleton Repository from Spatie](https://github.com/spatie/package-skeleton-laravel) |
| 205 | +- [Laravel Package Training from Spatie](https://spatie.be/videos/laravel-package-training) |
67 | 206 |
|
68 | 207 | ## License |
69 | 208 |
|
|
0 commit comments