jbit better messages

This commit is contained in:
2026-06-06 13:59:49 +03:30
parent e22ce8b737
commit 08f2f475ed
4 changed files with 14424 additions and 50 deletions
@@ -8,7 +8,6 @@ use App\Http\Controllers\Controller;
use App\Models\Address;
use App\Models\Customer;
use App\Models\User;
use App\Models\Cnt;
use App\Models\TransactionsAdmin;
use App\Models\Withdraw;
use Illuminate\Http\Request;
@@ -16,10 +15,9 @@ use Rooyesh\Wallet\interfaces\TransactionInterface;
use Rooyesh\Wallet\interfaces\WalletInterface;
use Rooyesh\Wallet\models\Wallet;
use Rooyesh\Wallet\models\Transaction;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Http;
use App\Models\Setting;
use App\Http\Controllers\Admin\TahesabController;
use App\Services\ConfigService;
use Illuminate\Support\Facades\Schema;
@@ -161,45 +159,9 @@ class CustomerController extends Controller
// $tah = new TahesabController();
// $tah->store(["customer_id" => $customer->id]);
if (!$customer->is_legal) {
$counter = Cnt::where('key', 'jibit_counter')->first();
if(empty($counter)){
$counter = new Cnt();
$counter->key = "jibit_counter";
$counter->value = 0;
$counter->save();
}
$nationalCode = $customer->n_code;
$mobileNumber = $customer->mobile;
// Storage::put('accessTokenGibit', ['accessToken']);
// Storage::put('refreshTokenGibit', ['refreshToken']);
$response = Http::withoutVerifying()->withToken(Storage::get('accessTokenGibit'))
->get("https://napi.jibit.ir/ide/v1/services/matching?nationalCode=".$nationalCode."&mobileNumber=".$mobileNumber)->json();
if (isset($response['code']) && $response['code']== "forbidden"){
$response = Http::withoutVerifying()->withToken(Storage::get('refreshTokenGibit'))
->post("https://napi.jibit.ir/ide/v1/tokens/generate",[
'apiKey' => "J5WxrPxPOg",
'secretKey' => "7dgeE70xQXsQL7r36j3wif6X9",
])->json();
Storage::put('accessTokenGibit', $response['accessToken']);
Storage::put('refreshTokenGibit', $response['refreshToken']);
$response = Http::withoutVerifying()->withToken(Storage::get('accessTokenGibit'))
->get("https://napi.jibit.ir/ide/v1/services/matching?nationalCode=".$nationalCode."&mobileNumber=".$mobileNumber)->json();
}
//update jibit counter
$counter->value = (int)$counter->value + 1;
$counter->save();
// $response = Http::withHeaders([
// 'Authorization' => 'Bearer mob83EBzqU7GWBmnc-6gXIp6r2G57P_94',
// 'Content-Type' => 'application/json',
// ])->post('http://185.97.116.24:20205/check_user', [
// 'number' => $customer->mobile,
// 'national' => $customer->n_code,
// 'host' => $_SERVER['HTTP_HOST'],
// ]);
$cfg = app(ConfigService::class);
if (!$customer->is_legal && $cfg->getBool('register_jibit_verify', false)) {
$response = $this->jibitNcode($customer->n_code, $customer->mobile);
if (isset($response['matched']) and $response['matched'] == true) {
$customer->is_legal = 1;
@@ -324,17 +286,22 @@ class CustomerController extends Controller
}
} else {
// This block will handle the case where the code doesn't match
// if (isset($response['code']) and $response['code'] === 'mobileNumber.not_valid') {
// return response()->json(['message' => "کد ملی تطابق ندارد",'response' =>$response], 422);
// } else {
// // This block will handle other errors from the $response variable
// return response()->json(['response' => $response], 422);
// }
return response()->json(['message' => "کد ملی ثبت شد، اما در حال حاضر سیستم نتوانست آن را تأیید کند. لطفاً منتظر بررسی و تأیید مدیر بمانید.",'response' =>$response], 422);
if (isset($response['matched']) && $response['matched'] === false) {
return response()->json([
'message' => 'کد ملی و شماره موبایل با یکدیگر مطابقت ندارند. لطفاً هر دو را با دقت بررسی کرده و دوباره ثبت کنید.',
], 422);
}
return response()->json([
'message' => 'کد ملی ثبت شد، اما در حال حاضر سیستم نتوانست آن را تأیید کند. لطفاً منتظر بررسی و تأیید مدیر بمانید.',
], 422);
}
} elseif (!$customer->is_legal && !$cfg->getBool('register_jibit_verify', false)) {
return response()->json([
'message' => 'اطلاعات شما با موفقیت ثبت شد. تأیید خودکار هویت در این سامانه فعال نیست؛ لطفاً برای تکمیل احراز هویت با پشتیبانی یا مدیر سامانه تماس بگیرید.',
], 422);
}
return response()->json(true);
} catch (\Exception $e) {