NASER add jibit and send admin messages to bale
This commit is contained in:
@@ -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