first upload all files

This commit is contained in:
NW
2023-06-11 13:14:03 +01:00
parent f14dbc52b5
commit c08b36d1b6
1705 changed files with 106852 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
<?php
namespace Modules\Sms\Exceptions;
use Exception;
class SmsException extends Exception
{
//
}

View 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;
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace Modules\Sms;
interface GatewayInterface
{
public function client();
public function send(string $to, string $message);
}

View File

@@ -0,0 +1,10 @@
<?php
namespace Modules\Sms;
use Modules\Support\Manager;
class GatewayManager extends Manager
{
//
}

View 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());
}
}
}

View 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());
}
}
}

View 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);
}
}

View 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.",
];

View File

@@ -0,0 +1,6 @@
<?php
return [
'vonage' => 'Vonage',
'twilio' => 'Twilio',
];

19
Modules/Sms/Sms.php Normal file
View 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
View 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
View File

@@ -0,0 +1,10 @@
{
"name": "Sms",
"alias": "sms",
"description": "The FleetCart Sms Module.",
"priority": 100,
"providers": [
"Modules\\Sms\\Providers\\SmsServiceProvider"
]
}