first upload all files
This commit is contained in:
10
Modules/Sms/Exceptions/SmsException.php
Normal file
10
Modules/Sms/Exceptions/SmsException.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sms\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class SmsException extends Exception
|
||||
{
|
||||
//
|
||||
}
|
||||
29
Modules/Sms/Facades/Gateway.php
Normal file
29
Modules/Sms/Facades/Gateway.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sms\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Support\Collection all()
|
||||
* @method static array names()
|
||||
* @method static \Modules\Sms\GatewayInterface get(string $name)
|
||||
* @method static \Modules\Sms\GatewayManager register(string $name, callable|object $driver)
|
||||
* @method static int count()
|
||||
* @method static bool isEmpty()
|
||||
* @method static bool isNotEmpty()
|
||||
*
|
||||
* @see \Modules\Sms\GatewayManager
|
||||
*/
|
||||
class Gateway extends Facade
|
||||
{
|
||||
/**
|
||||
* Get the registered name of the component.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return \Modules\Sms\GatewayManager::class;
|
||||
}
|
||||
}
|
||||
10
Modules/Sms/GatewayInterface.php
Normal file
10
Modules/Sms/GatewayInterface.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sms;
|
||||
|
||||
interface GatewayInterface
|
||||
{
|
||||
public function client();
|
||||
|
||||
public function send(string $to, string $message);
|
||||
}
|
||||
10
Modules/Sms/GatewayManager.php
Normal file
10
Modules/Sms/GatewayManager.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sms;
|
||||
|
||||
use Modules\Support\Manager;
|
||||
|
||||
class GatewayManager extends Manager
|
||||
{
|
||||
//
|
||||
}
|
||||
31
Modules/Sms/Gateways/Twilio.php
Normal file
31
Modules/Sms/Gateways/Twilio.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sms\Gateways;
|
||||
|
||||
use Exception;
|
||||
use Twilio\Rest\Client;
|
||||
use Modules\Sms\GatewayInterface;
|
||||
use Modules\Sms\Exceptions\SmsException;
|
||||
|
||||
class Twilio implements GatewayInterface
|
||||
{
|
||||
public function client()
|
||||
{
|
||||
return new Client(setting('twilio_sid'), setting('twilio_token'));
|
||||
}
|
||||
|
||||
public function send(string $to, string $message)
|
||||
{
|
||||
try {
|
||||
$this->client()->messages->create(
|
||||
$to,
|
||||
[
|
||||
'from' => setting('sms_from'),
|
||||
'body' => $message,
|
||||
]
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
throw new SmsException('Twilio: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
31
Modules/Sms/Gateways/Vonage.php
Normal file
31
Modules/Sms/Gateways/Vonage.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sms\Gateways;
|
||||
|
||||
use Exception;
|
||||
use Vonage\Client;
|
||||
use Vonage\SMS\Message\SMS;
|
||||
use Modules\Sms\GatewayInterface;
|
||||
use Vonage\Client\Credentials\Basic;
|
||||
use Modules\Sms\Exceptions\SmsException;
|
||||
|
||||
class Vonage implements GatewayInterface
|
||||
{
|
||||
public function client()
|
||||
{
|
||||
return new Client(
|
||||
new Basic(setting('vonage_key'), setting('vonage_secret'))
|
||||
);
|
||||
}
|
||||
|
||||
public function send(string $to, string $message)
|
||||
{
|
||||
try {
|
||||
$text = new SMS($to, setting('sms_from'), $message);
|
||||
|
||||
$this->client()->sms()->send($text);
|
||||
} catch (Exception $e) {
|
||||
throw new SmsException('Vonage: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
26
Modules/Sms/Providers/SmsServiceProvider.php
Normal file
26
Modules/Sms/Providers/SmsServiceProvider.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sms\Providers;
|
||||
|
||||
use Modules\Sms\Facades\Gateway;
|
||||
use Modules\Sms\Gateways\Twilio;
|
||||
use Modules\Sms\Gateways\Vonage;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class SmsServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap the application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
if (! config('app.installed')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Gateway::register('vonage', new Vonage);
|
||||
Gateway::register('twilio', new Twilio);
|
||||
}
|
||||
}
|
||||
8
Modules/Sms/Resources/lang/en/messages.php
Normal file
8
Modules/Sms/Resources/lang/en/messages.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'welcome' => "Welcome :first_name,\nYour account has been created successfully.",
|
||||
'new_order' => 'A new order has been placed. The order id is #:order_id.',
|
||||
'order_has_been_placed' => "Hi :first_name,\nYour order #:order_id has been placed. Thanks for shopping with us.",
|
||||
'order_status_changed' => "Hi :first_name,\nYour order #:order_id status is changed to :status.",
|
||||
];
|
||||
6
Modules/Sms/Resources/lang/en/services.php
Normal file
6
Modules/Sms/Resources/lang/en/services.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'vonage' => 'Vonage',
|
||||
'twilio' => 'Twilio',
|
||||
];
|
||||
19
Modules/Sms/Sms.php
Normal file
19
Modules/Sms/Sms.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Sms;
|
||||
|
||||
use Modules\Sms\Facades\Gateway;
|
||||
|
||||
class Sms
|
||||
{
|
||||
public static function send($to, $message)
|
||||
{
|
||||
if (! setting('sms_service')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$gateway = Gateway::get(setting('sms_service'));
|
||||
|
||||
$gateway->send($to, $message);
|
||||
}
|
||||
}
|
||||
29
Modules/Sms/composer.json
Normal file
29
Modules/Sms/composer.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "fleetcart/sms",
|
||||
"description": "The FleetCart Sms Module.",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Envay Soft",
|
||||
"email": "envaysoft@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^8.0.2",
|
||||
"twilio/sdk": "^6.15",
|
||||
"vonage/client": "^2.3"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Modules\\Sms\\": ""
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
10
Modules/Sms/module.json
Normal file
10
Modules/Sms/module.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "Sms",
|
||||
"alias": "sms",
|
||||
"description": "The FleetCart Sms Module.",
|
||||
|
||||
"priority": 100,
|
||||
"providers": [
|
||||
"Modules\\Sms\\Providers\\SmsServiceProvider"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user