Files
daragt-coupon/app/Helpers/helpers.php
2026-05-19 18:16:54 +05:00

56 lines
1.5 KiB
PHP

<?php
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
if (! function_exists('sendSMS')) {
/**
* Send a sms
*/
function sendSMS(string|int $phone, string|int $message): mixed
{
$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('http://216.250.14.144:3000/api/data', [
'phone' => '+993' . $phone,
'code' => $message,
]);
return $response->body();
}
}
if (! function_exists('unmask_phone')) {
/**
* Unmask Turkmenistan phone number from TM code +993 6X XX XX XX to 6xxxxxxx
*/
function unmask_phone(string $phone): string
{
// Keep digits only
$digits = preg_replace('/\D+/', '', $phone);
// Remove Turkmenistan country code if present
if (str_starts_with($digits, '993')) {
$digits = substr($digits, 3);
}
// Return only valid 8-digit TM mobile number
if (preg_match('/^6\d{7}$/', $digits)) {
return $digits;
}
return '';
}
}