Skip to content

Commit

Permalink
Support Laravel 8
Browse files Browse the repository at this point in the history
  • Loading branch information
h-o-sein committed Nov 15, 2020
0 parents commit beb32d5
Show file tree
Hide file tree
Showing 19 changed files with 862 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/kavenegar-laravel.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

218 changes: 218 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@

# Kavenegar-Laravel

# <a href="http://kavenegar.com/rest.html">Kavenegar RESTful API Document</a>
If you need to future information about API document Please visit RESTful Document

## Installation
<p>
First of all, You need to make an account on Kavenegar from <a href="https://panel.kavenegar.com/Client/Membership/Register">Here</a>
</p>
<p>
After that you just need to pick API-KEY up from <a href="http://panel.kavenegar.com/Client/setting/index">My Account</a> section.
</p>
<hr>

Use in these ways :

```php
composer require h-o-sein/kavenegar-laravel
```

or add

```php
"kavenegar/php": "*"
```
And run following command to download extension using **composer**


```php
$ composer update
```


Usage
-----

Well, There is an example to Send SMS by PHP.

```php
require __DIR__ . '/vendor/autoload.php';

try{
$api = new \Kavenegar\KavenegarApi( "API Key" );
$sender = "10004346";
$message = "خدمات پیام کوتاه کاوه نگار";
$receptor = array("09123456789","09367891011");
$result = $api->Send($sender,$receptor,$message);
if($result){
foreach($result as $r){
echo "messageid = $r->messageid";
echo "message = $r->message";
echo "status = $r->status";
echo "statustext = $r->statustext";
echo "sender = $r->sender";
echo "receptor = $r->receptor";
echo "date = $r->date";
echo "cost = $r->cost";
}
}
}
catch(\Kavenegar\Exceptions\ApiException $e){
// در صورتی که خروجی وب سرویس 200 نباشد این خطا رخ می دهد
echo $e->errorMessage();
}
catch(\Kavenegar\Exceptions\HttpException $e){
// در زمانی که مشکلی در برقرای ارتباط با وب سرویس وجود داشته باشد این خطا رخ می دهد
echo $e->errorMessage();
}

/*
sample output
{
"return":
{
"status":200,
"message":"تایید شد"
},
"entries":
[
{
"messageid":8792343,
"message":"خدمات پیام کوتاه کاوه نگار",
"status":1,
"statustext":"در صف ارسال",
"sender":"10004346",
"receptor":"09123456789",
"date":1356619709,
"cost":120
},
{
"messageid":8792344,
"message":"خدمات پیام کوتاه کاوه نگار",
"status":1,
"statustext":"در صف ارسال",
"sender":"10004346",
"receptor":"09367891011",
"date":1356619709,
"cost":120
}
]
}
*/
```

Also you can use KavengarChannel for your notification:

create your notification:
``
php artisan make:notification InvoicePaid
``

extend your notification from KavenegarBaseNotification:

```php
class InvoicePaid extends KavenegarBaseNotification
{

}
```
overide the toKavengar function:
````php
class InvoicePaid extends KavenegarBaseNotification
{

public function __construct(Invoice $invoice)
{
$this->invoice = $invoice;
}

public function toKavenegar($notifiable)
{
return (new KavenegarMessage("فاکتور شما به شماره $invoice->id پرداخت شد."))->from('10004346');
}
}
````
you should add Notifiable trait and routeNotificationForKavenegar method in your model

````php
class User extends Authenticatable
{
use Notifiable;

public function routeNotificationForKavenegar($driver, $notification = null)
{
return $this->mobile;
}

}
````
<i><b>Notice: if you don't add routeNotificationForKavenegar in your notifiable model then you should set your receiver in your notification :
````php
class InvoicePaid extends KavenegarBaseNotification
{

public function toKavenegar($notifiable)
{
return (new KavenegarMessage('فاکتور شما به شماره ۱۲۳۴ پرداخت شد.'))->from('10004346')->to('092100000');
}
}
````
for send verify lookup message you should use verifyLookup method for set method name and tokens:

````php
class InvoicePaid extends KavenegarBaseNotification
{

public function toKavenegar($notifiable)
{
return (new KavenegarMessage())
->verifyLookup('verify_first',['token1','token2']);
}
}
````


## Contribution

Bug fixes, docs, and enhancements welcome! Please let us know <a href="mailto:support@kavenegar.com?Subject=SDK" target="_top">support@kavenegar.com</a>

<hr>

<div dir='rtl'>

## راهنما

### معرفی سرویس کاوه نگار

کاوه نگار یک وب سرویس ارسال و دریافت پیامک و تماس صوتی است که به راحتی میتوانید از آن استفاده نمایید.

### ساخت حساب کاربری

اگر در وب سرویس کاوه نگار عضو نیستید میتوانید از [لینک عضویت](http://panel.kavenegar.com/client/membership/register) ثبت نام و اکانت آزمایشی برای تست API دریافت نمایید.

### مستندات

برای مشاهده اطلاعات کامل مستندات [وب سرویس پیامک](http://kavenegar.com/وب-سرویس-پیامک.html) به صفحه [مستندات وب سرویس](http://kavenegar.com/rest.html) مراجعه نمایید.

### راهنمای فارسی

در صورتی که مایل هستید راهنمای فارسی کیت توسعه کاوه نگار را مطالعه کنید به صفحه [کد ارسال پیامک](http://kavenegar.com/sdk.html) مراجعه نمایید.

### اطالاعات بیشتر
برای مطالعه بیشتر به صفحه معرفی
[وب سرویس اس ام اس ](http://kavenegar.com)
کاوه نگار
مراجعه نمایید .

اگر در استفاده از کیت های سرویس کاوه نگار مشکلی یا پیشنهادی داشتید ما را با یک Pull Request یا ارسال ایمیل به support@kavenegar.com خوشحال کنید.

##
![http://kavenegar.com](http://kavenegar.com/public/images/logo.png)

[http://kavenegar.com](http://kavenegar.com)

</div>


36 changes: 36 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name":"h-o-sein/kavenegar-laravel",
"description":"Laravel 8 Kavenegar integration",
"type":"laravel-package",
"keywords":[
"laravel",
"kavenegar",
"sms",
"api"
],
"license":"MIT",
"authors":[
{
"name":"Kavenegar API Team",
"email":"support@kavenegar.com"
}
],
"require":{
"kavenegar/php":"*"
},
"autoload":{
"psr-4":{
"Kavenegar\\Laravel\\":"src/"
}
},
"extra": {
"laravel": {
"providers": [
"Kavenegar\\Laravel\\ServiceProvider"
],
"aliases": {
"Kavenegar":"Kavenegar\\Laravel\\Facade"
}
}
}
}
16 changes: 16 additions & 0 deletions src/Facade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Kavenegar\Laravel;

class Facade extends \Illuminate\Support\Facades\Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'kavenegar';
}
}
Loading

0 comments on commit beb32d5

Please sign in to comment.