From 4f47c0ad1da1a9fd8130af20efad418051dd91b0 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Tue, 21 Jul 2026 19:28:08 +0300 Subject: [PATCH] Update: 2026-07-21 19:28:08 --- backend/auth/otp/providers.php | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/backend/auth/otp/providers.php b/backend/auth/otp/providers.php index 9abcc1ae..fd0b791c 100644 --- a/backend/auth/otp/providers.php +++ b/backend/auth/otp/providers.php @@ -155,9 +155,31 @@ function sendNabehOtp(string $receiver, string $otp, string $method = '', string $appName = 'سيرو للخدمات'; } + // First attempt with the chosen type + $result = _nabehOtpAttempt($phoneRaw, $type, $otp, $appName, $bearerToken); + if ($result) { + return true; + } + + // Fallback: if image failed, retry with text + if ($type === 'image') { + error_log("ℹ️ [Nabeh OTP Fallback] Image failed, retrying with text type..."); + $result = _nabehOtpAttempt($phoneRaw, 'text', $otp, $appName, $bearerToken); + if ($result) { + return true; + } + } + + return false; +} + +/** + * Internal helper: single OTP send attempt to Nabeh + */ +function _nabehOtpAttempt(string $phone, string $type, string $otp, string $appName, string $bearerToken): bool { $apiUrl = 'https://nabeh.intaleqapp.com/api/otp/send'; $payload = [ - 'phone' => $phoneRaw, + 'phone' => $phone, 'type' => $type, 'code' => $otp, 'message' => "رمز التحقق الخاص بك لتطبيق {$appName} هو: *{code}* \n الرجاء عدم مشاركته مع أي شخص." @@ -170,7 +192,7 @@ function sendNabehOtp(string $receiver, string $otp, string $method = '', string if ($response) { $decoded = json_decode($response, true); - error_log("ℹ️ [Nabeh OTP Response] " . $response); + error_log("ℹ️ [Nabeh OTP Response type=$type] " . $response); if ($decoded) { $statusStr = strtolower((string)($decoded['status'] ?? '')); $msgStr = strtolower((string)($decoded['message'] ?? '')); @@ -189,11 +211,11 @@ function sendNabehOtp(string $receiver, string $otp, string $method = '', string return true; } } - $msg = "❌ [Nabeh OTP Response Failed] Raw: " . $response; + $msg = "❌ [Nabeh OTP type=$type] Response: " . $response; $GLOBALS['last_otp_error'] = $msg; error_log($msg); } else { - $msg = "❌ [Nabeh OTP cURL Failed] Empty response from cURL."; + $msg = "❌ [Nabeh OTP type=$type] Empty cURL response."; $GLOBALS['last_otp_error'] = $msg; error_log($msg); }