fix: Accurate Nabeh OTP response parsing and live gateway error reporting
This commit is contained in:
@@ -90,9 +90,35 @@ class AuthController
|
||||
|
||||
// 4. Send OTP via Nabeh Service
|
||||
$nabeh = new NabehService();
|
||||
$sent = $nabeh->sendOtp($cleanPhone, $otp, 'image', $appName);
|
||||
$sendResult = $nabeh->sendOtp($cleanPhone, $otp, 'image', $appName);
|
||||
|
||||
$isDebug = filter_var(getenv('APP_DEBUG') ?: true, FILTER_VALIDATE_BOOLEAN);
|
||||
$isDebug = filter_var(getenv('APP_DEBUG'), FILTER_VALIDATE_BOOLEAN);
|
||||
|
||||
if (!$sendResult['success']) {
|
||||
$errorMsg = $sendResult['error'] ?? 'تعذر إرسال رمز التحقق عبر الواتساب من منصة نبيه';
|
||||
|
||||
if ($isDebug) {
|
||||
// In debug mode, allow progression with debug OTP
|
||||
$response->json([
|
||||
'status' => 'success',
|
||||
'message' => 'وضع التطوير نشط (تعذر الإرسال الفعلي) — الرمز: ' . $otp,
|
||||
'debug_otp' => $otp,
|
||||
'data' => [
|
||||
'phone_masked' => substr($cleanPhone, 0, 3) . '****' . substr($cleanPhone, -3),
|
||||
'expires_in' => 300,
|
||||
'gateway_error' => $sendResult
|
||||
]
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$response->status(502)->json([
|
||||
'status' => 'error',
|
||||
'message' => $errorMsg,
|
||||
'gateway_error' => $sendResult
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$resData = [
|
||||
'status' => 'success',
|
||||
@@ -103,12 +129,8 @@ class AuthController
|
||||
]
|
||||
];
|
||||
|
||||
// Expose OTP only in debug mode for seamless local testing
|
||||
if ($isDebug || !$sent) {
|
||||
if ($isDebug) {
|
||||
$resData['debug_otp'] = $otp;
|
||||
if (!$sent) {
|
||||
$resData['message'] = 'تم توليد رمز التحقق (بيئة التطوير / محاكاة الإرسال)';
|
||||
}
|
||||
}
|
||||
|
||||
$response->json($resData);
|
||||
|
||||
Reference in New Issue
Block a user