-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from sajaddp/master
Support Laravel 9
- Loading branch information
Showing
4 changed files
with
135 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,51 @@ | ||
|
||
# Kavenegar Laravel | ||
|
||
**First of all you will ned an [API Key](http://panel.kavenegar.com/client/setting/account "API Key") . You can get one [Here](https://panel.kavenegar.com/Client/Membership/Register).** | ||
|
||
##### Supported Laravel Versions: | ||
* V.4 | ||
* V.5 | ||
* V.6 | ||
* V.7 | ||
* **V.8** | ||
> We highly recomment you to always use the latest version of laravel | ||
|
||
- V.4 | ||
- V.5 | ||
- V.6 | ||
- V.7 | ||
- V.8 | ||
- **V.9** | ||
> We highly recomment you to always use the latest version of laravel | ||
# Installation | ||
|
||
## Step 1 - Install the package | ||
* **Method 1**: | ||
You can install kavenegar/laravel with Composer directly in your project: | ||
|
||
- **Method 1**: | ||
You can install kavenegar/laravel with Composer directly in your project: | ||
|
||
```php | ||
composer require kavenegar/laravel | ||
``` | ||
|
||
* **Method 2**: | ||
Add this line to **Composer.json** file in your project | ||
- **Method 2**: | ||
Add this line to **Composer.json** file in your project | ||
|
||
```php | ||
"kavenegar/php": "*" | ||
``` | ||
Then run following command to download extension using **composer** | ||
|
||
Then run following command to download extension using **composer** | ||
|
||
```php | ||
$ composer update | ||
``` | ||
|
||
## Step 2 | ||
|
||
Head to **config/app.php** and add this line to the end of **providers** Array: | ||
|
||
```php | ||
Kavenegar\Laravel\ServiceProvider::class, | ||
``` | ||
|
||
So that array must me something like this: | ||
|
||
```php | ||
'providers' => [ | ||
/* | ||
|
@@ -50,57 +59,70 @@ So that array must me something like this: | |
``` | ||
|
||
Then in the **config/app.php** and add this line to the end of **aliases** Array: | ||
|
||
```php | ||
'Kavenegar' => Kavenegar\Laravel\Facade::class, | ||
``` | ||
|
||
## Step 3 - Publish | ||
|
||
Run this command in your project dirctory: | ||
|
||
``` | ||
php artisan vendor:publish | ||
``` | ||
|
||
In the message appear, find the number of Kavenegar, enter the related number then hit Enter. for Example in the below case you must enter **8** then enter: | ||
|
||
> Which provider or tag's files would you like to publish?: | ||
[0 ] Publish files from all providers and tags listed below | ||
[1 ] Provider: Facade\Ignition\IgnitionServiceProvider | ||
[2 ] Provider: Fideloper\Proxy\TrustedProxyServiceProvider | ||
[3 ] Provider: Fruitcake\Cors\CorsServiceProvider | ||
[4 ] Provider: Illuminate\Foundation\Providers\FoundationServiceProvider | ||
[5 ] Provider: Illuminate\Mail\MailServiceProvider | ||
[6 ] Provider: Illuminate\Notifications\NotificationServiceProvider | ||
[7 ] Provider: Illuminate\Pagination\PaginationServiceProvider | ||
*** [8 ] Provider: Kavenegar\Laravel\ServiceProviderLaravel8*** | ||
. | ||
. | ||
. | ||
In the message appear, find the number of Kavenegar, enter the related number then hit Enter. for Example in the below case you must enter **9** then enter: | ||
|
||
```bash | ||
Which provider or tag files would you like to publish?: | ||
[0 ] Publish files from all providers and tags listed below | ||
[1 ] Provider: Facade\Ignition\IgnitionServiceProvider | ||
[2 ] Provider: Fideloper\Proxy\TrustedProxyServiceProvider | ||
[3 ] Provider: Fruitcake\Cors\CorsServiceProvider | ||
[4 ] Provider: Illuminate\Foundation\Providers\FoundationServiceProvider | ||
[5 ] Provider: Illuminate\Mail\MailServiceProvider | ||
[6 ] Provider: Illuminate\Notifications\NotificationServiceProvider | ||
[7 ] Provider: Illuminate\Pagination\PaginationServiceProvider | ||
**_ [8 ] Provider: Kavenegar\Laravel\ServiceProviderLaravel9_** | ||
. | ||
. | ||
. | ||
``` | ||
|
||
## Step 4 - Api-Key | ||
Now you must define your [API Key](http://panel.kavenegar.com/client/setting/account "API Key") to project. for this head to **config/kavenegar.php** then put your API KEY in the code: | ||
|
||
Now you must define your [API Key](http://panel.kavenegar.com/client/setting/account "API Key") to project. for this head to **config/kavenegar.php** then put your API KEY in the code: | ||
|
||
``` | ||
<?php | ||
<?php | ||
return [ | ||
'apikey' => ' ', | ||
]; | ||
``` | ||
|
||
### All Set | ||
|
||
# Usage | ||
|
||
You can use the package where ever you want. | ||
* First use the class: | ||
|
||
- First use the class: | ||
|
||
```php | ||
use Kavenegar; | ||
``` | ||
|
||
Then use this pattern to send SMS: | ||
|
||
```php | ||
try{ | ||
$sender = "10004346"; //This is the Sender number | ||
$sender = "10004346"; //This is the Sender number | ||
|
||
$message = "خدمات پیام کوتاه کاوه نگار"; //The body of SMS | ||
|
||
$receptor = array("09361234567","09191234567"); //Receptors numbers | ||
|
||
$result = Kavenegar::Send($sender,$receptor,$message); | ||
if($result){ | ||
foreach($result as $r){ | ||
|
@@ -112,7 +134,7 @@ try{ | |
echo "receptor = $r->receptor"; | ||
echo "date = $r->date"; | ||
echo "cost = $r->cost"; | ||
} | ||
} | ||
} | ||
} | ||
catch(\Kavenegar\Exceptions\ApiException $e){ | ||
|
@@ -124,13 +146,15 @@ catch(\Kavenegar\Exceptions\HttpException $e){ | |
echo $e->errorMessage(); | ||
} | ||
``` | ||
|
||
Use this pattern to send VerifyLookup SMS: | ||
|
||
```php | ||
try{ | ||
$receptor = "09123456789"; | ||
$token = "123"; | ||
$token2 = "456"; | ||
$token3 = "789"; | ||
$token = "123"; | ||
$token2 = "456"; | ||
$token3 = "789"; | ||
$template="verify"; | ||
//Send null for tokens not defined in the template | ||
//Pass token10 and token20 as parameter 6th and 7th | ||
|
@@ -145,7 +169,7 @@ try{ | |
echo "receptor = $r->receptor"; | ||
echo "date = $r->date"; | ||
echo "cost = $r->cost"; | ||
} | ||
} | ||
} | ||
} | ||
catch(\Kavenegar\Exceptions\ApiException $e){ | ||
|
@@ -157,12 +181,15 @@ catch(\Kavenegar\Exceptions\HttpException $e){ | |
echo $e->errorMessage(); | ||
} | ||
``` | ||
|
||
You can find all the **Error handlings** and **API parameters** and **Usage methods** in the [KaveNegar](https://kavenegar.com) website. | ||
|
||
# Usage in Notifications | ||
|
||
Also you can use KavengarChannel for your notification: | ||
|
||
create your notification: | ||
|
||
``` | ||
php artisan make:notification InvoicePaid | ||
``` | ||
|
@@ -175,25 +202,28 @@ class InvoicePaid extends KavenegarBaseNotification | |
|
||
} | ||
``` | ||
|
||
overide the toKavengar function: | ||
````php | ||
class InvoicePaid extends KavenegarBaseNotification | ||
{ | ||
|
||
public function __construct(Invoice $invoice) | ||
```php | ||
class InvoicePaid extends KavenegarBaseNotification | ||
{ | ||
|
||
public function __construct(Invoice $invoice) | ||
{ | ||
$this->invoice = $invoice; | ||
} | ||
|
||
public function toKavenegar($notifiable) | ||
{ | ||
$this->invoice = $invoice; | ||
return (new KavenegarMessage("فاکتور شما به شماره $invoice->id پرداخت شد."))->from('10004346'); | ||
} | ||
|
||
public function toKavenegar($notifiable) | ||
{ | ||
return (new KavenegarMessage("فاکتور شما به شماره $invoice->id پرداخت شد."))->from('10004346'); | ||
} | ||
} | ||
```` | ||
} | ||
``` | ||
|
||
you should add Notifiable trait and routeNotificationForKavenegar method in your model | ||
|
||
````php | ||
```php | ||
class User extends Authenticatable | ||
{ | ||
use Notifiable; | ||
|
@@ -204,8 +234,10 @@ class User extends Authenticatable | |
} | ||
|
||
} | ||
```` | ||
** *Notice: IF you DO NOT add routeNotificationForKavenegar in your notifiable model then you should set your receiver in your notification :* ** | ||
``` | ||
|
||
** _Notice: IF you DO NOT add routeNotificationForKavenegar in your notifiable model then you should set your receiver in your notification :_ ** | ||
|
||
```php | ||
class InvoicePaid extends KavenegarBaseNotification | ||
{ | ||
|
@@ -216,9 +248,10 @@ class InvoicePaid extends KavenegarBaseNotification | |
} | ||
} | ||
``` | ||
|
||
for send verify lookup message you should use verifyLookup method for set method name and tokens: | ||
|
||
````php | ||
```php | ||
class InvoicePaid extends KavenegarBaseNotification | ||
{ | ||
|
||
|
@@ -228,8 +261,7 @@ class InvoicePaid extends KavenegarBaseNotification | |
->verifyLookup('verify_first',['token1','token2']); | ||
} | ||
} | ||
```` | ||
|
||
``` | ||
|
||
## Contribution | ||
|
||
|
@@ -244,24 +276,25 @@ Bug fixes, docs, and enhancements welcome! Please let us know [support@kavenegar | |
|
||
### ساخت حساب کاربری | ||
|
||
اگر در وب سرویس کاوه نگار عضو نیستید میتوانید از [لینک عضویت](http://panel.kavenegar.com/client/membership/register) ثبت نام و اکانت آزمایشی برای تست API دریافت نمایید. | ||
اگر در وب سرویس کاوه نگار عضو نیستید میتوانید از [لینک عضویت](http://panel.kavenegar.com/client/membership/register) ثبت نام و اکانت آزمایشی برای تست API دریافت نمایید. | ||
|
||
### مستندات | ||
|
||
برای مشاهده اطلاعات کامل مستندات [وب سرویس پیامک](http://kavenegar.com/وب-سرویس-پیامک.html) به صفحه [مستندات وب سرویس](http://kavenegar.com/rest.html) مراجعه نمایید. | ||
برای مشاهده اطلاعات کامل مستندات [وب سرویس پیامک](http://kavenegar.com/وب-سرویس-پیامک.html) به صفحه [مستندات وب سرویس](http://kavenegar.com/rest.html) مراجعه نمایید. | ||
|
||
### راهنمای فارسی | ||
|
||
در صورتی که مایل هستید راهنمای فارسی کیت توسعه کاوه نگار را مطالعه کنید به صفحه [کد ارسال پیامک](http://kavenegar.com/sdk.html) مراجعه نمایید. | ||
|
||
### اطالاعات بیشتر | ||
|
||
برای مطالعه بیشتر به صفحه معرفی | ||
[وب سرویس اس ام اس ](http://kavenegar.com) | ||
کاوه نگار | ||
مراجعه نمایید . | ||
|
||
اگر در استفاده از کیت های سرویس کاوه نگار مشکلی یا پیشنهادی داشتید ما را با یک Pull Request یا ارسال ایمیل به [email protected] خوشحال کنید. | ||
</div> | ||
------------ | ||
اگر در استفاده از کیت های سرویس کاوه نگار مشکلی یا پیشنهادی داشتید ما را با یک Pull Request یا ارسال ایمیل به [email protected] خوشحال کنید. | ||
|
||
## </div> | ||
|
||
[http://kavenegar.com](http://kavenegar.com) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
"email":"[email protected]" | ||
} | ||
], | ||
"minimum-stability":"dev", | ||
"require":{ | ||
"kavenegar/php":"*" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Kavenegar\Laravel; | ||
|
||
use Kavenegar\KavenegarApi as KavenegarApi; | ||
use Illuminate\Support\Facades\Notification; | ||
use Kavenegar\Laravel\Channel\KavenegarChannel; | ||
|
||
class ServiceProviderLaravel9 extends \Illuminate\Support\ServiceProvider | ||
{ | ||
/** | ||
* Bootstrap the application events. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
$this->publishes([__DIR__ . '/config/config.php' => config_path('kavenegar.php')]); | ||
} | ||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->mergeConfigFrom(__DIR__ . '/config/config.php', 'kavenegar'); | ||
$this->app->singleton('kavenegar', function ($app) { | ||
return new KavenegarApi($app['config']->get('kavenegar.apikey')); | ||
}); | ||
Notification::resolved(function ($service) { | ||
$service->extend('kavenegar', function ($app) { | ||
return new KavenegarChannel($app->make('kavenegar')); | ||
}); | ||
}); | ||
} | ||
} |