install
This commit is contained in:
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user