-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kalyan Halder
committed
Feb 24, 2021
0 parents
commit 9696afa
Showing
14 changed files
with
773 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/node_modules | ||
/storage/*.key | ||
/vendor | ||
/.idea | ||
/.vagrant | ||
.env |
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,4 @@ | ||
language: php | ||
php: | ||
- '7.1' | ||
- '7.2' |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017 Crafted Systems <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,94 @@ | ||
# Laravel SMS BD | ||
|
||
|
||
This is a Laravel library to send SMS and switch between multiple SMS Gateways. | ||
|
||
## Installation | ||
|
||
You can install the package via composer: | ||
|
||
``` bash | ||
composer require kalyan312/laravel-sms-bd | ||
``` | ||
The package will register itself automatically. | ||
|
||
Then publish the package configuration file | ||
|
||
```bash | ||
php artisan vendor:publish --provider=Khbd\LaravelSmsBD\SMSServiceProvider | ||
``` | ||
|
||
## Usage | ||
|
||
Check the config file of all variables required, and then | ||
|
||
```php | ||
(new SMS())->send('01945602071','Test SMS'); | ||
``` | ||
or using Facade | ||
|
||
```php | ||
SMS::send('01945602071','Test SMS'); | ||
``` | ||
|
||
or using helper | ||
|
||
```php | ||
sms()->send('01945602071','Test SMS'); | ||
``` | ||
|
||
## Adding new Gateway | ||
|
||
use command | ||
```bash | ||
php artisan make:gateway MyGateway | ||
``` | ||
|
||
A class `MyGateway.php` will be generated under `App/Gateways` folder. | ||
|
||
The class extends the [SMSInterface]() | ||
|
||
Remember to `map` your gateway in the sms config file. | ||
|
||
### Changing Gateway | ||
|
||
Apart from declaring your default gateway on the sms config or env files, you can also change the gateway you want to use on the fly. e.g: | ||
|
||
```php | ||
SMS::gateway('mygateway')->send('254712345678','Test SMS'); | ||
``` | ||
|
||
### Checking SMS balance | ||
|
||
```php | ||
SMS::getBalance(); | ||
|
||
//or | ||
|
||
SMS::gateway('mygateway')->getBalance(); | ||
|
||
``` | ||
### Delivery Reports | ||
```php | ||
sms()->getDeliveryReports(Request $request); | ||
|
||
//or | ||
|
||
sms()->gateway('mygateway')->getDeliveryReports(Request $request); | ||
``` | ||
|
||
## Contributing | ||
|
||
Suggestions, pull requests , bug reporting and code improvements are all welcome. Feel free. | ||
|
||
## TODO | ||
|
||
Write Tests | ||
|
||
## Credits | ||
|
||
- [Kalyan Halder](https://github.com/kalyan312) | ||
|
||
## License | ||
|
||
The MIT License (MIT). Please see [License File](LICENSE) for more information. |
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,38 @@ | ||
{ | ||
"name": "khbd/laravel-sms-bd", | ||
"description": "Laravel sms BD is a Laravel Package for Sending out SMS from multiple Gateways", | ||
"license": "MIT", | ||
"type": "library", | ||
"require": { | ||
"php": "^7.2", | ||
"illuminate/support": "^6.0|^7.0|^8.0", | ||
"ixudra/curl": "6.*" | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Kalyan Halder", | ||
"email": "[email protected]", | ||
"homepage": "https://github.com/kalyan312", | ||
"role": "Developer" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"Khbd\\LaravelSmsBD\\": "src/" | ||
}, | ||
"files": [ | ||
"src/helpers.php" | ||
] | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Khbd\\LaravelSmsBD\\SMSServiceProvider" | ||
], | ||
"aliases": { | ||
"SMS": "Khbd\\LaravelSmsBD\\Facades\\SMS" | ||
} | ||
} | ||
}, | ||
"minimum-stability": "dev" | ||
} |
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,54 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Default Gateway | ||
|-------------------------------------------------------------------------- | ||
| | ||
| This value determines which of the following gateway to use. | ||
| You can switch to a different gateway at runtime. | ||
| | ||
*/ | ||
|
||
'default' => env('DEFAULT_SMS_GATEWAY', 'bangladesh_sms'), | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| List of Gateways | ||
|-------------------------------------------------------------------------- | ||
| | ||
| These are the list of gateways to use for this package. | ||
| You can change the name. Then you'll have to change | ||
| it in the map array too. | ||
| | ||
*/ | ||
|
||
'gateways' => [ | ||
|
||
'bangladesh_sms' => [ | ||
'username' => env('BANGLADESH_SMS_USERNAME'), | ||
'api_key' => env('BANGLADESH_SMS_API_KEY'), | ||
'from' => env('BANGLADESH_SMS_FROM'), | ||
], | ||
], | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Class Maps | ||
|-------------------------------------------------------------------------- | ||
| | ||
| This is the array of Classes that maps to Gateways above. | ||
| You can create your own driver if you like and add the | ||
| config in the drivers array and the class to use | ||
| here with the same name. You will have to implement | ||
| Khbd\LaravelSmsBD\Contracts\SMSContract in your gateway. | ||
| | ||
*/ | ||
|
||
'map' => [ | ||
'bangladesh_sms' => \Khbd\LaravelSmsBD\BangladeshSMS::class, | ||
|
||
], | ||
]; |
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,51 @@ | ||
<?php | ||
|
||
namespace Khbd\LaravelSmsBD\Console; | ||
|
||
use Illuminate\Console\GeneratorCommand; | ||
|
||
class MakeGatewayCommand extends GeneratorCommand | ||
{ | ||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'make:gateway'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create a new Gateway class for Laravel SMS'; | ||
|
||
/** | ||
* The type of class being generated. | ||
* | ||
* @var string | ||
*/ | ||
protected $type = 'Gateway'; | ||
|
||
/** | ||
* Get the stub file for the generator. | ||
* | ||
* @return string | ||
*/ | ||
protected function getStub() | ||
{ | ||
return __DIR__.'/stubs/gateway.stub'; | ||
} | ||
|
||
/** | ||
* Get the default namespace for the class. | ||
* | ||
* @param string $rootNamespace | ||
* | ||
* @return string | ||
*/ | ||
protected function getDefaultNamespace($rootNamespace) | ||
{ | ||
return $rootNamespace.'\Gateways'; | ||
} | ||
} |
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,108 @@ | ||
<?php | ||
|
||
namespace DummyNamespace; | ||
|
||
use Khbd\LaravelSmsBD\Interfaces\SMSInterface; | ||
use Illuminate\Http\Request; | ||
|
||
class DummyClass implements SMSInterface | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $settings; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
protected $is_success; | ||
|
||
/** | ||
* @var mixed | ||
*/ | ||
protected $message_id; | ||
|
||
/** | ||
* @var object | ||
*/ | ||
public $data; | ||
|
||
|
||
/** | ||
* @param $settings | ||
* @throws \Exception | ||
*/ | ||
public function __construct($settings) | ||
{ | ||
// initiate settings (username, api_key, etc) | ||
|
||
$this->settings = (object)$settings; | ||
} | ||
|
||
/** | ||
* @param $recipient | ||
* @param $message | ||
* @param null $params | ||
* @return object | ||
*/ | ||
public function send(string $recipient, string $message, $params = null) | ||
{ | ||
// implement the send sms method | ||
|
||
$this->is_success = ''; // define what determines success from the response | ||
$this->message_id = ''; // reference the message id here. auto generate if not available | ||
$arr = [ | ||
'is_success' => '', | ||
'message_id' => '' | ||
// e.t.c | ||
]; // the rest of data that is returned | ||
|
||
$this->data = (object)$arr; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* initialize the is_success parameter | ||
* @return bool | ||
*/ | ||
public function is_successful(): bool | ||
{ | ||
return $this->is_success; | ||
} | ||
|
||
/** | ||
* assign the message ID as received on the response,auto generate if not available | ||
* @return mixed | ||
*/ | ||
public function getMessageID() | ||
{ | ||
return $this->message_id; | ||
} | ||
|
||
/** | ||
* auto generate if not available | ||
*/ | ||
public function getBalance(): float | ||
{ | ||
// implement the get balance method | ||
} | ||
|
||
|
||
/** | ||
* @param Request $request | ||
* @return object | ||
*/ | ||
public function getDeliveryReports(Request $request) | ||
{ | ||
// implement the processing of delivery reports here. POST/PUSH implementation encouraged | ||
|
||
$data = [ | ||
'status' => '',//delivery report status (e.g DeliveredToTerminal,Success,Failed) | ||
'message_id' => '' //the message id for purpose of matching | ||
// e.t.c | ||
]; // the rest of data that is returned | ||
|
||
return (object)$data; | ||
} | ||
} |
Oops, something went wrong.