NASER add jibit and send admin messages to bale
This commit is contained in:
@@ -10,8 +10,11 @@ use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
|
||||
|
||||
|
||||
class Controller extends BaseController
|
||||
@@ -69,7 +72,10 @@ class Controller extends BaseController
|
||||
"telegram" => [
|
||||
"token" => self::Config('telegram_bot_token')
|
||||
],
|
||||
|
||||
"bale" => [
|
||||
"token" => self::Config('bale_bot_token')
|
||||
// "token" => Setting::where('key', 'bale_bot_token')->where('is_active', true)->first()->value ?? null
|
||||
],
|
||||
"sms" => [
|
||||
'user_name' => 'ysms1362',
|
||||
'password' => 'tL4w0PfNy2()',
|
||||
@@ -79,7 +85,7 @@ class Controller extends BaseController
|
||||
$platforms = [];
|
||||
$send_sms = true;
|
||||
$user = User::where('mobile', $to)->first() ?: Customer::where('mobile', $to)->first();
|
||||
// if ($user) {
|
||||
if ($user) {
|
||||
//
|
||||
// // Telegram
|
||||
// if (isset($credentials['telegram']) && $user->telegram) {
|
||||
@@ -98,20 +104,20 @@ class Controller extends BaseController
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Bale
|
||||
// if (isset($credentials['bale']) && $user->bale) {
|
||||
// try {
|
||||
// Http::get("https://api.wwwapp.ir/bale_send.php", [
|
||||
// 'botToken' => $credentials['bale']['token'],
|
||||
// 'chatId' => $user->bale,
|
||||
// 'message' => "جناب {$user->name} {$msg}",
|
||||
// ]);
|
||||
// $platforms[] = "bale:{$user->bale}";
|
||||
// $send_sms = false;
|
||||
// } catch (\Exception $e) {
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// Bale
|
||||
if (isset($credentials['bale']) && $user->bale) {
|
||||
try {
|
||||
Http::withoutVerifying()->get("https://tapi.bale.ai/{$credentials['bale']['token']}/sendMessage", [
|
||||
'chat_id' => $user->bale,
|
||||
'text' => "جناب {$user->name} {$msg}",
|
||||
]);
|
||||
$platforms[] = "bale:{$user->bale}";
|
||||
$send_sms = false;
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//SMS
|
||||
if ($send_sms or $force_method=="sms") {
|
||||
@@ -170,4 +176,32 @@ class Controller extends BaseController
|
||||
//
|
||||
// return $settingValue;
|
||||
}
|
||||
|
||||
public static function jibit($method, $p1 = null, $p2 = null, $p3 = null)
|
||||
{
|
||||
$apiData['refresh'] = Http::withoutVerifying()->withoutVerifying()->withToken(Storage::get('refreshTokenGibit'))
|
||||
->post("https://napi.jibit.ir/ide/v1/tokens/generate", ['apiKey' => "J5WxrPxPOg", 'secretKey' => "7dgeE70xQXsQL7r36j3wif6X9",])->json();
|
||||
Storage::put('accessTokenGibit', $apiData['refresh']['accessToken']);
|
||||
|
||||
if (!Storage::exists('accessTokenGibit') || !Storage::exists('refreshTokenGibit')) {
|
||||
Storage::put('accessTokenGibit', 'توکن اولیه');
|
||||
Storage::put('refreshTokenGibit', 'توکن رفرش اولیه');
|
||||
}
|
||||
|
||||
$apiData['cartMatching'] = Http::withoutVerifying()->withToken(Storage::get('accessTokenGibit'))->get("https://napi.jibit.ir/ide/v1/services/matching?cardNumber=$p1&nationalCode=$p2&birthDate=$p3")->json();
|
||||
if ((isset($apiData['cartMatching']['code'])) and $apiData['cartMatching']['code'] == "forbidden") {
|
||||
$apiData['refresh'] = Http::withoutVerifying()->withToken(Storage::get('refreshTokenGibit'))
|
||||
->post("https://napi.jibit.ir/ide/v1/tokens/generate", ['apiKey' => "J5WxrPxPOg", 'secretKey' => "7dgeE70xQXsQL7r36j3wif6X9",])->json();
|
||||
Storage::put('accessTokenGibit', $apiData['refresh']['accessToken']);
|
||||
Storage::put('refreshTokenGibit', $apiData['refresh']['refreshToken']);
|
||||
$apiData['cartMatching'] = Http::withoutVerifying()->withToken(Storage::get('accessTokenGibit'))->get("https://napi.jibit.ir/ide/v1/services/matching?cardNumber=$p1&nationalCode=$p2&birthDate=$p3")->json();
|
||||
}
|
||||
if (isset( $apiData['cartMatching']['matched']) and $apiData['cartMatching']['matched'] == true) {
|
||||
$apiData['cartData'] = Http::withoutVerifying()->withToken(Storage::get('accessTokenGibit'))->get("https://napi.jibit.ir/ide/v1/cards?number=$p1&iban=true")->json();
|
||||
return $apiData;
|
||||
} else {
|
||||
throw new UnprocessableEntityHttpException($apiData['cartMatching']['message']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ use App\Models\BankAccount;
|
||||
use App\Models\Customer;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Morilog\Jalali\Jalalian;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Log;
|
||||
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
|
||||
class BankAccountController extends SuperController
|
||||
@@ -36,9 +39,70 @@ class BankAccountController extends SuperController
|
||||
}
|
||||
public function StoreBankAccount(Request $request)
|
||||
{
|
||||
if (empty($request->shaba_number) || empty($request->bank_name) ){
|
||||
// || empty($request->cart_number) || empty($request->account_number)) {
|
||||
throw new UnprocessableEntityHttpException('اطلاعات کارت را کامل وارد کنید.');
|
||||
if (strlen($request->cart_number) != 16) {
|
||||
throw new UnprocessableEntityHttpException('شماره کارت اشتباه میباشد.');
|
||||
}
|
||||
if (BankAccount::where('cart_number', $request->cart_number)->exists()) {
|
||||
throw new UnprocessableEntityHttpException('شماره کارت تکراری میباشد.');
|
||||
}
|
||||
|
||||
$user = auth()->guard('customer')->user();
|
||||
if ($user->n_code === null || $user->n_code === '') {
|
||||
throw new UnprocessableEntityHttpException('لطفا شماره ملی خود را در پروفایل کاربری وارد کنید سپس اقدام به ثبت کارت بانکی کنید.');
|
||||
}
|
||||
if($user->birth_date == null && !isset($request->birth_date)){
|
||||
throw new UnprocessableEntityHttpException('لطفا تاریخ تولد خود را در پروفایل کاربری وارد کنید سپس اقدام به ثبت کارت بانکی کنید.');
|
||||
}
|
||||
|
||||
//with verification in jibit
|
||||
if($this->Config('jibit_verification') == 'true') {
|
||||
$p1 = $apiData['iban'] = preg_replace('/\D/', '', $request->cart_number);
|
||||
$p2 = $apiData['nationalCode'] = $user->n_code;
|
||||
$p3 = $apiData['birthDate'] = Jalalian::fromCarbon(Carbon::parse($request->birth_date ?? $user->birth_date))->format('Ymd');
|
||||
// dd($p3);
|
||||
// [$apiData['iban'],$apiData['nationalCode'],$apiData['birthDate']];
|
||||
|
||||
$apiData['r'] = $this->jibit('cartMatching', $apiData['iban'], $apiData['nationalCode'], $apiData['birthDate']);
|
||||
try {
|
||||
$log = new Log();
|
||||
$log->customer_id = auth('customer')->id();
|
||||
$log->data = json_encode($apiData['r'], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
$log->save();
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
if (isset($apiData['r']['cartData'])) {
|
||||
$BA = BankAccount::create([
|
||||
'customer_id' => $user->id,
|
||||
'cart_number' => $apiData['r']['cartData']['number'],
|
||||
'bank_name' => $apiData['r']['cartData']['ibanInfo']['bank'],
|
||||
'account_number' => $apiData['r']['cartData']['ibanInfo']['depositNumber'],
|
||||
'shaba_number' => $apiData['r']['cartData']['ibanInfo']['iban'],
|
||||
'first_name' => $apiData['r']['cartData']['ibanInfo']['owners'][0]['firstName'],
|
||||
'last_name' => $apiData['r']['cartData']['ibanInfo']['owners'][0]['lastName'],
|
||||
'cart_status' => $apiData['r']['cartData']['ibanInfo']['status'],
|
||||
'sts' => 2,
|
||||
]);
|
||||
Customer::where('id', $user->id)->update(['birth_date' => $request->birth_date ?? $user->birth_date]);
|
||||
$data = ['success' => true, 'bankAccount' => $BA];
|
||||
return response()->json($data);
|
||||
|
||||
} else {
|
||||
$message = "احرازهویت برای شماره کارت کاربر " . $user->name . " توسط جیبیت انجام نشد. لطفا از پنل ادمین اقدام کنید. ";
|
||||
User::where('send_sms', 1)->get()->each(function ($admin) use ($message) {
|
||||
$this->SendMessage($admin->mobile, $message);
|
||||
});
|
||||
$BA = BankAccount::create([
|
||||
'customer_id' => $user->id,
|
||||
'cart_number' => $request->cart_number,
|
||||
'first_name' => $user->fname,
|
||||
'last_name' => $user->lname,
|
||||
'sts' => 1,
|
||||
]);
|
||||
throw new UnprocessableEntityHttpException('شماره کارت شما برای ادمین ارسال شد و پس از تایید قابل استفاده می باشد.');
|
||||
return $apiData;
|
||||
}
|
||||
}
|
||||
$customer = Customer::find(auth('customer')->id());
|
||||
$message = "کارت جدیدی برای $customer->name ساخته شد منتظر تایید شما هستیم.";
|
||||
|
||||
Reference in New Issue
Block a user