Surface specific Jibit identity errors on profile update.
Map Shahkar mismatch, token, unreachable, and duplicate cases to clear Persian messages instead of a generic wait-for-admin toast. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -18,9 +18,11 @@ use Rooyesh\Wallet\models\Transaction;
|
||||
use App\Models\Setting;
|
||||
use App\Http\Controllers\Admin\TahesabController;
|
||||
use App\Services\ConfigService;
|
||||
use App\Services\JibitIdentityService;
|
||||
use App\Services\ReferralGiftService;
|
||||
use App\Services\WalletBalanceService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
@@ -207,9 +209,30 @@ class CustomerController extends Controller
|
||||
// $tah->store(["customer_id" => $customer->id]);
|
||||
$cfg = app(ConfigService::class);
|
||||
if (!$wasLegal && $cfg->isRegisterJibitVerifyEnabled()) {
|
||||
$response = $this->jibitNcode($customer->n_code, $customer->mobile);
|
||||
$nCodeError = JibitIdentityService::nationalCodeError($customer->n_code);
|
||||
if ($nCodeError !== null) {
|
||||
return response()->json([
|
||||
'message' => $nCodeError,
|
||||
'code' => 'invalid_national_code',
|
||||
], 422);
|
||||
}
|
||||
|
||||
if (isset($response['matched']) and $response['matched'] == true) {
|
||||
try {
|
||||
$response = $this->jibitNcode($customer->n_code, $customer->mobile);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('customer updateMe jibit unreachable', [
|
||||
'customer_id' => $customer->id,
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'ارتباط با سرویس احراز هویت جیبیت برقرار نشد. اطلاعات پروفایل ذخیره شد اما هویت تأیید نشد.',
|
||||
'code' => 'jibit_unreachable',
|
||||
], 422);
|
||||
}
|
||||
|
||||
$jibit = JibitIdentityService::interpretNationalMobileMatch($response);
|
||||
if ($jibit['ok']) {
|
||||
$customer->is_legal = 1;
|
||||
$customer->save();
|
||||
// واریز پاداش معرف مستقل از has_page_earn_money (آن فقط منوی اپ است)
|
||||
@@ -222,18 +245,18 @@ class CustomerController extends Controller
|
||||
true
|
||||
);
|
||||
} else {
|
||||
if (isset($response['matched']) && $response['matched'] === false) {
|
||||
return response()->json([
|
||||
'message' => 'کد ملی و شماره موبایل با یکدیگر مطابقت ندارند. لطفاً هر دو را با دقت بررسی کرده و دوباره ثبت کنید.',
|
||||
], 422);
|
||||
}
|
||||
Log::warning('customer updateMe jibit not verified', [
|
||||
'customer_id' => $customer->id,
|
||||
'code' => $jibit['code'],
|
||||
'jibit_code' => is_array($response) ? ($response['code'] ?? null) : null,
|
||||
'http_status' => is_array($response) ? ($response['http_status'] ?? null) : null,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'کد ملی ثبت شد، اما در حال حاضر سیستم نتوانست آن را تأیید کند. لطفاً منتظر بررسی و تأیید مدیر بمانید.',
|
||||
'message' => $jibit['message'],
|
||||
'code' => $jibit['code'],
|
||||
], 422);
|
||||
}
|
||||
|
||||
|
||||
} elseif (!$customer->is_legal && !$cfg->isRegisterJibitVerifyEnabled()) {
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
@@ -242,13 +265,47 @@ class CustomerController extends Controller
|
||||
]);
|
||||
}
|
||||
return response()->json(true);
|
||||
} catch (QueryException $e) {
|
||||
Log::error('customer updateMe failed', [
|
||||
'customer_id' => auth('customer')->id(),
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
$driverCode = (int) ($e->errorInfo[1] ?? 0);
|
||||
$sqlMessage = (string) ($e->errorInfo[2] ?? $e->getMessage());
|
||||
if ($driverCode === 1062) {
|
||||
if (str_contains($sqlMessage, 'n_code')) {
|
||||
return response()->json([
|
||||
'message' => 'این کد ملی قبلاً برای حساب دیگری ثبت شده است.',
|
||||
'code' => 'duplicate_national_code',
|
||||
], 422);
|
||||
}
|
||||
if (str_contains($sqlMessage, 'mobile')) {
|
||||
return response()->json([
|
||||
'message' => 'این شماره موبایل قبلاً برای حساب دیگری ثبت شده است.',
|
||||
'code' => 'duplicate_mobile',
|
||||
], 422);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'این مقدار قبلاً در سیستم ثبت شده و تکراری است.',
|
||||
'code' => 'duplicate_value',
|
||||
], 422);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'ذخیره اطلاعات در دیتابیس انجام نشد. جزئیات در لاگ سرور ثبت شد.',
|
||||
'code' => 'db_error',
|
||||
], 422);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('customer updateMe failed', [
|
||||
'customer_id' => auth('customer')->id(),
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return response()->json(['message' => 'خطا در ذخیره اطلاعات. لطفاً دوباره تلاش کنید.'], 422);
|
||||
return response()->json([
|
||||
'message' => 'خطا در ذخیره اطلاعات. لطفاً دوباره تلاش کنید.',
|
||||
'code' => 'update_failed',
|
||||
], 422);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user