2026-01-24 14:03:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Single;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Http\Controllers\SuperController;
|
|
|
|
|
use App\Models\BankAccount;
|
|
|
|
|
use App\Models\Customer;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use Illuminate\Http\Request;
|
2026-04-19 14:40:04 +00:00
|
|
|
use Hekmatinasser\Verta\Verta;
|
2026-04-19 17:19:25 +03:30
|
|
|
use Carbon\Carbon;
|
|
|
|
|
use App\Models\Log;
|
2026-07-22 01:05:00 +03:30
|
|
|
use App\Services\ConfigService;
|
2026-01-24 14:03:11 +00:00
|
|
|
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
|
|
|
|
|
|
|
|
|
class BankAccountController extends SuperController
|
|
|
|
|
{
|
|
|
|
|
public function __construct(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$query = BankAccount::where('customer_id', auth('customer')->id());
|
|
|
|
|
$request->request->add(['customer_id' => auth('customer')->id()]);
|
|
|
|
|
parent::__construct(BankAccount::class, [], ['*', BankAccount::$SELECT_STS_STR], null, $query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function destroy($id)
|
|
|
|
|
{
|
2026-07-23 17:53:10 +03:30
|
|
|
$account = BankAccount::where('customer_id', auth('customer')->id())->findOrFail($id);
|
|
|
|
|
$account->delete();
|
|
|
|
|
return response()->json(true);
|
2026-01-24 14:03:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function listActiveBankAccount()
|
|
|
|
|
{
|
|
|
|
|
$query = BankAccount::where('customer_id', auth('customer')->id())
|
|
|
|
|
->whereIn('sts', [1, 2])->get();
|
|
|
|
|
return response()->json($query);
|
|
|
|
|
}
|
|
|
|
|
public function StoreBankAccount(Request $request)
|
|
|
|
|
{
|
2026-04-19 17:19:25 +03:30
|
|
|
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
|
2026-07-22 01:05:00 +03:30
|
|
|
if (app(ConfigService::class)->isJibitCardVerificationEnabled()) {
|
2026-04-19 17:19:25 +03:30
|
|
|
$p1 = $apiData['iban'] = preg_replace('/\D/', '', $request->cart_number);
|
|
|
|
|
$p2 = $apiData['nationalCode'] = $user->n_code;
|
2026-04-19 14:40:04 +00:00
|
|
|
$p3 = $apiData['birthDate'] = Verta::instance(Carbon::parse($request->birth_date ?? $user->birth_date))->format('Ymd');
|
2026-04-19 17:19:25 +03:30
|
|
|
// dd($p3);
|
|
|
|
|
// [$apiData['iban'],$apiData['nationalCode'],$apiData['birthDate']];
|
|
|
|
|
|
|
|
|
|
$apiData['r'] = $this->jibit('cartMatching', $apiData['iban'], $apiData['nationalCode'], $apiData['birthDate']);
|
|
|
|
|
try {
|
2026-06-06 21:36:19 +03:30
|
|
|
$logPayload = [
|
|
|
|
|
'cartMatching' => $apiData['r']['cartMatching'] ?? null,
|
|
|
|
|
'cartData' => $apiData['r']['cartData'] ?? null,
|
|
|
|
|
];
|
2026-04-19 17:19:25 +03:30
|
|
|
$log = new Log();
|
|
|
|
|
$log->customer_id = auth('customer')->id();
|
2026-06-06 21:36:19 +03:30
|
|
|
$log->data = json_encode($logPayload, JSON_UNESCAPED_UNICODE);
|
2026-04-19 17:19:25 +03:30
|
|
|
$log->save();
|
|
|
|
|
} catch (\Exception $e) {
|
2026-06-06 21:36:19 +03:30
|
|
|
\Log::warning('Bank account jibit log save failed', [
|
|
|
|
|
'customer_id' => auth('customer')->id(),
|
|
|
|
|
'message' => $e->getMessage(),
|
|
|
|
|
]);
|
2026-04-19 17:19:25 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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]);
|
2026-08-30 21:35:10 +03:30
|
|
|
$data = [
|
|
|
|
|
'success' => true,
|
|
|
|
|
'bankAccount' => $BA,
|
|
|
|
|
'message' => 'کارت بانکی شما با موفقیت ثبت شد',
|
|
|
|
|
];
|
2026-04-19 17:19:25 +03:30
|
|
|
return response()->json($data);
|
|
|
|
|
|
|
|
|
|
} else {
|
2026-07-23 17:53:10 +03:30
|
|
|
$message = 'احراز هویت کارت بانکی برای کاربر ' . $user->name . ' توسط جیبیت ناموفق بود. کارت ثبت نشد.';
|
2026-07-18 22:22:01 +03:30
|
|
|
if (self::isSmsNotifEnabled('sms_notif_bank_card_admin')) {
|
|
|
|
|
User::where('send_sms', 1)->get()->each(function ($admin) use ($message) {
|
|
|
|
|
$this->SendMessage($admin->mobile, $message);
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-07-23 17:53:10 +03:30
|
|
|
throw new UnprocessableEntityHttpException(
|
|
|
|
|
'احراز هویت کارت بانکی ناموفق بود. کارت معتبر نیست و ثبت نشد.'
|
|
|
|
|
);
|
2026-04-19 17:19:25 +03:30
|
|
|
}
|
2026-01-24 14:03:11 +00:00
|
|
|
}
|
|
|
|
|
$customer = Customer::find(auth('customer')->id());
|
|
|
|
|
$message = "کارت جدیدی برای $customer->name ساخته شد منتظر تایید شما هستیم.";
|
|
|
|
|
$message .= $this->Config('name_fa');
|
|
|
|
|
|
2026-07-18 22:22:01 +03:30
|
|
|
if (self::isSmsNotifEnabled('sms_notif_bank_card_admin')) {
|
|
|
|
|
User::where('active', 1)->where('send_sms', 1)->get()->each(function ($admin) use ($message) {
|
|
|
|
|
$this->Send($admin->mobile, $message);
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-01-24 14:03:11 +00:00
|
|
|
$data = $request->only(['account_number', 'bank_name', 'cart_number', 'shaba_number', 'customer_id']);
|
|
|
|
|
BankAccount::create($data);
|
2026-08-30 21:35:10 +03:30
|
|
|
$data['message'] = 'اطلاعات کارت بانکی شما ثبت شد و پس از تایید ادمین فعال سازی خواهد شد';
|
2026-01-24 14:03:11 +00:00
|
|
|
return response()->json($data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|