feat: Enable Image OTP Card by default with Nabeh and enhanced portal sync

This commit is contained in:
Hamza-Ayed
2026-08-26 23:15:31 +03:00
parent f3c5f4161e
commit e386716ed5
+8 -10
View File
@@ -18,7 +18,7 @@ class NabehService
$this->sendUrl = (string)getenv('NABEH_SEND_URL');
$this->email = (string)getenv('NABEH_EMAIL');
$this->password = (string)getenv('NABEH_PASSWORD');
$this->defaultType = (string)(getenv('NABEH_OTP_TYPE') ?: 'text');
$this->defaultType = (string)(getenv('NABEH_OTP_TYPE') ?: 'image'); // Default: Luxury Image Card
$missing = [];
if (empty($this->authUrl)) $missing[] = 'NABEH_AUTH_URL';
@@ -97,8 +97,7 @@ class NabehService
}
/**
* Send OTP via Nabeh JWT Auth Gateway (WhatsApp text/image OTP)
* Text mode is ultra-fast (1-2s). Image mode generates dynamic card (10-25s).
* Send OTP via Nabeh JWT Auth Gateway (WhatsApp image/text OTP)
*/
public function sendOtp(string $receiver, string $otp, ?string $method = null, string $appName = 'منصة صَقِل'): array
{
@@ -118,24 +117,23 @@ class NabehService
$phoneRaw = '962' . $phoneRaw;
}
// Selected type: provided method > defaultType > 'text'
$selectedType = $method ?: $this->defaultType;
if (!in_array($selectedType, ['text', 'voice', 'image'], true)) {
$selectedType = 'text';
$selectedType = 'image';
}
// 1. First attempt with selected type (text or image)
// 1. Attempt with selected type (image card)
$result = $this->attemptSend($phoneRaw, $selectedType, $otp, $appName, $bearerToken);
if ($result['success']) {
return $result;
}
// 2. If image failed or timed out, fallback to instant text OTP
// 2. If image failed, fallback to text mode
if ($selectedType === 'image') {
error_log("ℹ️ [Nabeh OTP Fallback] Image mode failed/timed out for {$phoneRaw}. Retrying instantly with Text mode...");
error_log("ℹ️ [Nabeh OTP Fallback] Image card attempt failed for {$phoneRaw}. Retrying with text mode...");
$textResult = $this->attemptSend($phoneRaw, 'text', $otp, $appName, $bearerToken);
if ($textResult['success']) {
$textResult['note'] = 'Image OTP timed out, delivered via fast text fallback';
$textResult['note'] = 'Delivered via text fallback';
return $textResult;
}
return $textResult;
@@ -153,7 +151,7 @@ class NabehService
'message' => "رمز التحقق الخاص بك لمنصة {$appName} هو: *{$otp}* \n الرجاء عدم مشاركته مع أي شخص لحماية حسابك.",
]);
$timeout = ($type === 'image') ? 50 : 25; // 50s for image rendering, 25s for text
$timeout = ($type === 'image') ? 45 : 20;
$ch = curl_init($this->sendUrl);
curl_setopt_array($ch, [