install
This commit is contained in:
5
app/Modules/Sms/Configs/sms-config.php
Normal file
5
app/Modules/Sms/Configs/sms-config.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'url' => 'http://216.250.14.144:3000/api/data',
|
||||
];
|
||||
40
app/Modules/Sms/Repositories/SmsRepository.php
Normal file
40
app/Modules/Sms/Repositories/SmsRepository.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Sms\Repositories;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class SmsRepository
|
||||
{
|
||||
/**
|
||||
* Send a sms
|
||||
*/
|
||||
public static function sendSMS(string|int $phone, string|int $message): mixed
|
||||
{
|
||||
if (app()->environment('local')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$response = Http::retry(
|
||||
times: 3,
|
||||
sleepMilliseconds: 50,
|
||||
throw: false,
|
||||
when: function (Exception $exception, PendingRequest $request) {
|
||||
Log::error('Exception: ', [
|
||||
'message' => $exception->getMessage(),
|
||||
'line' => $exception->getLine(),
|
||||
]);
|
||||
|
||||
return true;
|
||||
})
|
||||
->post(config()->string('module.sms.url'), [
|
||||
'phone' => '+993'.$phone,
|
||||
'code' => $message,
|
||||
]);
|
||||
|
||||
return $response->body();
|
||||
}
|
||||
}
|
||||
72
app/Modules/Sms/SmsModule.php
Normal file
72
app/Modules/Sms/SmsModule.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Sms;
|
||||
|
||||
use App\Modules\Core\ModulePackage;
|
||||
use App\Modules\Core\ModulePackageType;
|
||||
use App\Modules\Makeable;
|
||||
use App\Modules\ModuleContract;
|
||||
|
||||
class SmsModule implements ModuleContract
|
||||
{
|
||||
use Makeable;
|
||||
|
||||
/**
|
||||
* Module is enabled
|
||||
*/
|
||||
protected bool $enabled = true;
|
||||
|
||||
/**
|
||||
* Check if is module enabled
|
||||
*/
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable module
|
||||
*/
|
||||
public function disable(): void
|
||||
{
|
||||
$this->enabled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable module
|
||||
*/
|
||||
public function enable(): void
|
||||
{
|
||||
$this->enabled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if module has a filament resource
|
||||
*/
|
||||
public function hasFilamentResource(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get module composer requirements
|
||||
*/
|
||||
public function getComposerRequirements(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get module composer suggestions
|
||||
*/
|
||||
public function getComposerSuggestions(): array
|
||||
{
|
||||
return [
|
||||
new ModulePackage(
|
||||
type: ModulePackageType::MODULE,
|
||||
name: 'OtpVerification',
|
||||
message: 'For sending sms verification codes.',
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
11
app/Modules/Sms/sms-helpers.php
Normal file
11
app/Modules/Sms/sms-helpers.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Sms\Repositories\SmsRepository;
|
||||
|
||||
/**
|
||||
* Send a sms
|
||||
*/
|
||||
function sendSMS(string|int $phone, string|int $message): mixed
|
||||
{
|
||||
return SmsRepository::sendSMS($phone, $message);
|
||||
}
|
||||
Reference in New Issue
Block a user