Initial commit - WASL Digital Wallet
This commit is contained in:
45
Backend/app/Support/helpers.php
Normal file
45
Backend/app/Support/helpers.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
if (!function_exists('normalize_phone_number')) {
|
||||
/**
|
||||
* Normalize phone numbers to E.164 format or standard format.
|
||||
* For Syria: +963xxxxxxxx or standard digits.
|
||||
*/
|
||||
function normalize_phone_number(string $phone): string
|
||||
{
|
||||
// Remove non-numeric characters except +
|
||||
$cleaned = preg_replace('/[^\d+]/', '', $phone);
|
||||
|
||||
// Remove leading double zeros
|
||||
if (str_starts_with($cleaned, '00')) {
|
||||
$cleaned = '+' . substr($cleaned, 2);
|
||||
}
|
||||
|
||||
// If it starts with local 09, convert to +9639
|
||||
if (str_starts_with($cleaned, '09') && strlen($cleaned) === 10) {
|
||||
$cleaned = '+963' . substr($cleaned, 1);
|
||||
}
|
||||
|
||||
return $cleaned;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('hash_phone')) {
|
||||
/**
|
||||
* Generate SHA-256 hash of a normalized phone number for fast lookup.
|
||||
*/
|
||||
function hash_phone(string $phone): string
|
||||
{
|
||||
return hash('sha256', normalize_phone_number($phone));
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('hash_national_id')) {
|
||||
/**
|
||||
* Generate SHA-256 hash of a national ID for fast lookup.
|
||||
*/
|
||||
function hash_national_id(string $nationalId): string
|
||||
{
|
||||
return hash('sha256', trim($nationalId));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user