middleware('admin'); } public function index($id = NULL) { return view('admin.retailer.index')->with('distributor_id',$id); } public function retailerListAjax(Request $request) { $columns = array( 0=>'id', 1=>'profile', 2=>'name', 3=>'business_type', 4=>'distributor_id', 5=>'mobile_number', 6=>'email', 7=>'wallet_balance', 8=>'status', 9=>'created_at', 10=>'action', ); $limit = $request->input('length'); $start = $request->input('start'); $order = $columns[$request->input('order.0.column')]; $dir = $request->input('order.0.dir'); $distributor_id = $request->input('distributor_id'); if($distributor_id) { $totalData = Client::where('distributor_id',$distributor_id)->where('role',2)->get()->count(); $totalFiltered = Client::where('distributor_id',$distributor_id)->where('role',2); $values = Client::where('distributor_id',$distributor_id)->where('role',2)->offset($start)->limit($limit)->orderBy('clients'.'.'.$order,$dir); } else { $totalData = Client::where('role',2)->get()->count(); $totalFiltered = Client::where('role',2); $values = Client::where('role',2)->offset($start)->limit($limit)->orderBy('clients'.'.'.$order,$dir); } if(!empty($request->input('search'))) { $search = $request->input('search'); $values = $values->where(function ($query) use ($search) { return $query->Where('name', 'LIKE',"%{$search}%")->orWhere('business_type', 'LIKE',"%{$search}%")->orWhere('mobile_number', 'LIKE',"%{$search}%")->orWhere('email', 'LIKE',"%{$search}%")->orWhere('address', 'LIKE',"%{$search}%")->orWhere('created_at', 'LIKE',"%{$search}%"); }); $totalFiltered = $totalFiltered->where(function ($query) use ($search) { return $query->where('name', 'LIKE',"%{$search}%")->orWhere('business_type', 'LIKE',"%{$search}%")->orWhere('mobile_number', 'LIKE',"%{$search}%")->orWhere('email', 'LIKE',"%{$search}%")->orWhere('address', 'LIKE',"%{$search}%")->orWhere('created_at', 'LIKE',"%{$search}%"); }); } $values = $values->get(); $totalFiltered = $totalFiltered->count(); $data = array(); if(!empty($values)) { $i = 1; foreach ($values as $value) { if($value->status == 1) { $status = 'Active'; } else { $status = 'In-Active'; } if($value->profile) { $image = ''; } else { $image = ''; } $get_distributor = Client::where('id',$value->distributor_id)->first(); if($get_distributor) { $distributor_name = $get_distributor->name; } else { $distributor_name = "N/A"; } $retailerData['id'] = $i; $retailerData['profile'] = $image; $retailerData['name'] = $value->name; $retailerData['business_type'] = $value->business_type; $retailerData['distributor_id'] = $distributor_name; $retailerData['mobile_number'] = $value->mobile_number; $retailerData['email'] = $value->email; $retailerData['wallet_balance'] = '('.$value->wallet_balance.')'; $retailerData['status'] = $status; $retailerData['created_at'] = date("Y-m-d H:i:s", strtotime($value->created_at)); $retailerData['action'] = ' '; $data[] = $retailerData; $i++; } } $json_data = array( "draw" => intval($request->input('draw')), "recordsTotal" => intval($totalData), "recordsFiltered" => intval($totalFiltered), "data" => $data ); echo json_encode($json_data); } public function retailerAdd() { $clients = Client::where('role',1)->where('status',1)->get(); return view('admin.retailer.add')->with('clients',$clients); } public function retailerInsert(Request $request) { $messages = array( 'distributor_id.required' => 'This field is required.', 'business_type.required' => 'This field is required.', 'name.required' => 'This field is required.', 'email.required' => 'This field is required.', 'mobile_number.required' => 'This field is required.', 'password.required' => 'This field is required.', 'password.min' => 'The password must be at least 6 characters.', 'password.regex' => 'The password must include at least one uppercase letter, one lowercase letter, one digit, and one special character.' ); $rules = [ 'distributor_id' => 'required', 'business_type'=>"required", 'name'=>"required", 'email'=>"required|email|unique:clients", 'mobile_number'=>"required|min:10|max:15|unique:clients", 'password' => [ 'required', 'min:6', 'regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*(_|[^\w])).+$/' ], 'profile' => 'nullable|file|mimes:jpeg,png,jpg|max:2048', ]; if ($request->filled('password')) { $rules['password'] = ['required','min:6','regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*(_|[^\w])).+$/']; } $validation = Validator::make($request->all(), $rules, $messages); if ($validation->fails()) { return back() ->withInput() ->withErrors($validation) ->with('message', 'There were validation errors.'); } else { $sponsor_code = Helper::retailerSponserCode(); $data = [ 'distributor_id' => $request->input('distributor_id'), 'business_type' => $request->input('business_type'), 'name' => $request->input('name'), 'mobile_number' => $request->input('mobile_number'), 'email' => $request->input('email'), 'address' => $request->input('address'), 'password' => Hash::make($request->input('password')), 'txn_password' => $request->input('password'), 'role' => 2, 'sponsor_code' => $sponsor_code, 'reffered_code' => $request->input('reffered_code'), 'status' => $request->input('status'), 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s') ]; if($files=$request->file('profile')) { $destination = 'storage/app/public/profile'; $image= time().$files->getClientOriginalName(); $files->move($destination,$image); $data['profile'] = $image; } $id = Client::insertGetId($data); ClientKyc::insert(['distributor_id'=>$id,'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s')]); Commission::insert(['retailer_id'=>$id,'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s')]); toastr()->success('Retailer added successfully.!'); return redirect()->route('admin/retailer-list'); } } public function retailerEdit($id) { $retailer = Client::where('id',$id)->first(); $clients = Client::where('role',1)->where('status',1)->get(); return view('admin.retailer.edit',compact('retailer','clients')); } public function retailerUpdate(Request $request, $id) { $messages = array( 'distributor_id.required' => 'This field is required.', 'business_type.required' => 'This field is required.', 'name.required' => 'This field is required.', 'mobile_number.required' => 'This field is required.', 'password.min' => 'The password must be at least 6 characters.', 'password.regex' => 'The password format is invalid. It must contain at least one uppercase letter, one lowercase letter, one digit, and one special character.', ); $rules = [ 'distributor_id' => 'required', 'business_type' => 'required', 'name' => 'required', 'email'=>"required|email|unique:clients,email,$id,id", 'mobile_number'=>"required|min:10|max:15|unique:clients,mobile_number,$id,id", 'profile' => 'nullable|file|mimes:jpeg,png,jpg|max:2048', ]; if ($request->filled('password')) { $rules['password'] = ['required','min:6','regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*(_|[^\w])).+$/']; } $validation = Validator::make($request->all(), $rules, $messages); if($validation->fails()) { return back() ->withInput() ->withErrors($validation) ->with('messagess', 'There were validation errors.'); } else { $data = [ 'distributor_id' => $request->input('distributor_id'), 'business_type' => $request->input('business_type'), 'name' => $request->input('name'), 'mobile_number' => $request->input('mobile_number'), 'email' => $request->input('email'), 'reffered_code' => $request->input('reffered_code'), 'address' => $request->input('address'), 'status' => $request->input('status'), 'updated_at' => date('Y-m-d H:i:s'), ]; if($files=$request->file('profile')) { $destination = 'storage/app/public/profile'; $image= time().$files->getClientOriginalName(); $files->move($destination,$image); $data['profile'] = $image; } if($request->input('password')) { $data['password'] = Hash::make($request->input('password')); $data['txn_password'] = $request->input('password'); } Client::where('id', $id)->update($data); } toastr()->success('Retailer updated successfully.!'); return redirect()->route('admin/retailer-list',$request->input('distributor_id')); } public function retailerDelete($id) { Client::where('id', $id)->delete(); toastr()->success('Retailer delete successfully.!'); return redirect()->route('admin/retailer-list'); } public function retailerWalletList() { $clients = Client::where('status',1)->where('role',2)->get(); return view('admin.retailer.wallet.index')->with('clients',$clients); } public function retailerWalletListAjax(Request $request) { $columns = array( 0=>'id', 1=>'retailer_id', 2=>'topay_transuction_id', 3=>'amount', 4=>'mode', 5=>'payment_mode', 6=>'remarks', 7=>'payment_api', 8=>'status', 9=>'created_at', 10=>'action', ); $limit = $request->input('length'); $start = $request->input('start'); $order = $columns[$request->input('order.0.column')]; $dir = $request->input('order.0.dir'); $id = $request->input('id'); $from_date = $request->input('from_date'); $to_date = $request->input('to_date'); $filter_mode = $request->input('filter_mode'); $filter_payment_mode = $request->input('filter_payment_mode'); $filter_retailer_id = $request->input('filter_retailer_id'); $retailer_id = $request->input('retailer_id'); $filter_status = $request->input('filter_status'); $totalData = RetailerWallet::select('retailer_wallets.*','c.name') ->join('clients as c','c.id','=','retailer_wallets.retailer_id') ->count(); $totalFiltered = RetailerWallet::select('retailer_wallets.*','c.name') ->join('clients as c','c.id','=','retailer_wallets.retailer_id'); $values = RetailerWallet::select('retailer_wallets.*','c.name') ->join('clients as c','c.id','=','retailer_wallets.retailer_id'); if(!empty($id)) { $values->where('c.id',$id); } $values->offset($start)->limit($limit)->orderBy('retailer_wallets'.'.'.$order,$dir); if(!empty($request->input('search'))) { $search = $request->input('search'); $values = $values->where(function ($query) use ($search) { return $query->where('retailer_wallets.amount', 'LIKE',"%{$search}%")->orWhere('retailer_wallets.mode', 'LIKE',"%{$search}%")->orWhere('retailer_wallets.payment_mode', 'LIKE',"%{$search}%")->orWhere('c.name', 'LIKE',"%{$search}%")->orWhere('retailer_wallets.created_at', 'LIKE',"%{$search}%"); }); $totalFiltered = $totalFiltered->where(function ($query) use ($search) { return $query->where('retailer_wallets.amount', 'LIKE',"%{$search}%")->orWhere('retailer_wallets.mode', 'LIKE',"%{$search}%")->orWhere('retailer_wallets.payment_mode', 'LIKE',"%{$search}%")->orWhere('c.name', 'LIKE',"%{$search}%")->orWhere('retailer_wallets.created_at', 'LIKE',"%{$search}%"); }); } if(!empty($from_date) && !empty($to_date)) { $values->whereBetween(DB::raw('DATE(retailer_wallets.created_at)'),[$from_date, $to_date]); $totalFiltered->whereBetween(DB::raw('DATE(retailer_wallets.created_at)'),[$from_date, $to_date]); } if(!empty($filter_status)) { if($filter_status != 4 && $filter_status != 5) { $values->where('retailer_wallets.is_status',$filter_status); $totalFiltered->where('retailer_wallets.is_status',$filter_status); } else if($filter_status == 4) { $values->where('retailer_wallets.is_pay',$filter_status); $totalFiltered->where('retailer_wallets.is_pay',$filter_status); } else { $values->where('retailer_wallets.is_status',0); $totalFiltered->where('retailer_wallets.is_status',0); } } if(!empty($filter_mode)) { $values->where('retailer_wallets.mode',$filter_mode); $totalFiltered->where('retailer_wallets.mode',$filter_mode); } if(!empty($filter_payment_mode)) { $values->where('retailer_wallets.payment_mode',$filter_payment_mode); $totalFiltered->where('retailer_wallets.payment_mode',$filter_payment_mode); } if(!empty($filter_retailer_id)) { $values->where('retailer_wallets.retailer_id',$filter_retailer_id); $totalFiltered->where('retailer_wallets.retailer_id',$filter_retailer_id); } $values = $values->get(); $totalFiltered = $totalFiltered->count(); $data = array(); if(!empty($values)) { $i = 1; foreach ($values as $value) { if($value->mode == "Credit") { $status_mode = 'Credit'; } else { $status_mode = 'Debit'; } if($value->is_status == 1) { if($value->payment_mode == "Online") { if($value->is_pay == 1) { $status = 'Approved'; } else if($value->is_pay == 4) { $status = 'Refund'; } else { $status = 'Pending'; } } else { $status = 'Approved'; } } else if($value->is_status == 2) { $status = 'Rejected'; } else if($value->is_status == 3) { $status = 'Failed'; } else if($value->is_status == 4) { $status = 'Refund'; } else if($value->is_pay == 4) { $status = 'Refund'; } else { $status = 'Pending'; } $walletData['id'] = $i; $walletData['retailer_id'] = $value->name; $walletData['topay_transuction_id'] = $value->topay_transuction_id; $walletData['amount'] = $value->amount; $walletData['mode'] = $status_mode; $walletData['payment_mode'] = $value->payment_mode; $walletData['remarks'] = $value->remarks; $walletData['payment_api'] = $value->payment_api; $walletData['status'] = $status; $walletData['created_at'] = date("Y-m-d H:i:s", strtotime($value->created_at)); if($value->is_status != 1 && $value->payment_mode == "Online") { $walletData['action'] = ' Check Status '; } else { $walletData['action'] = 'N/A'; } $data[] = $walletData; $i++; } } $json_data = array( "draw" => intval($request->input('draw')), "recordsTotal" => intval($totalData), "recordsFiltered" => intval($totalFiltered), "data" => $data ); echo json_encode($json_data); } public function retailerWalletRecharge() { $clients = Client::where('status',1)->where('role',2)->get(); return view('admin.retailer.wallet.recharge')->with('clients',$clients); } public function retailerWalletRechargeAjax(Request $request) { $columns = array( 0=>'id', 1=>'retailer_id', 2=>'topay_transuction_id', 3=>'amount', 4=>'received_amount', 5=>'mode', 6=>'payment_mode', 7=>'remarks', 8=>'payment_api', 9=>'status', 10=>'created_at', 11=>'action', ); $limit = $request->input('length'); $start = $request->input('start'); $order = $columns[$request->input('order.0.column')]; $dir = $request->input('order.0.dir'); $id = $request->input('id'); $from_date = $request->input('from_date'); $to_date = $request->input('to_date'); $filter_mode = $request->input('filter_mode'); $filter_payment_mode = $request->input('filter_payment_mode'); $filter_retailer_id = $request->input('filter_retailer_id'); $retailer_id = $request->input('retailer_id'); $filter_status = $request->input('filter_status'); $totalData = RetailerWallet::select('retailer_wallets.*','c.name') ->join('clients as c','c.id','=','retailer_wallets.retailer_id') ->whereIn('retailer_wallets.payment_api', ['worldline', 'PayU', 'RunPaisa', 'Lyra']) ->count(); $totalFiltered = RetailerWallet::select('retailer_wallets.*','c.name') ->join('clients as c','c.id','=','retailer_wallets.retailer_id') ->whereIn('retailer_wallets.payment_api',['worldline','PayU', 'RunPaisa', 'Lyra']); $values = RetailerWallet::select('retailer_wallets.*','c.name') ->join('clients as c','c.id','=','retailer_wallets.retailer_id') ->whereIn('retailer_wallets.payment_api',['worldline','PayU', 'RunPaisa', 'Lyra']); if(!empty($id)) { $values->where('c.id',$id); } $values->offset($start)->limit($limit)->orderBy('retailer_wallets'.'.'.$order,$dir); if(!empty($request->input('search'))) { $search = $request->input('search'); $values = $values->where(function ($query) use ($search) { return $query->where('retailer_wallets.amount', 'LIKE',"%{$search}%")->orWhere('retailer_wallets.mode', 'LIKE',"%{$search}%")->orWhere('retailer_wallets.payment_mode', 'LIKE',"%{$search}%")->orWhere('c.name', 'LIKE',"%{$search}%")->orWhere('retailer_wallets.created_at', 'LIKE',"%{$search}%"); }); $totalFiltered = $totalFiltered->where(function ($query) use ($search) { return $query->where('retailer_wallets.amount', 'LIKE',"%{$search}%")->orWhere('retailer_wallets.mode', 'LIKE',"%{$search}%")->orWhere('retailer_wallets.payment_mode', 'LIKE',"%{$search}%")->orWhere('c.name', 'LIKE',"%{$search}%")->orWhere('retailer_wallets.created_at', 'LIKE',"%{$search}%"); }); } if(!empty($from_date) && !empty($to_date)) { $values->whereBetween(DB::raw('DATE(retailer_wallets.created_at)'),[$from_date, $to_date]); $totalFiltered->whereBetween(DB::raw('DATE(retailer_wallets.created_at)'),[$from_date, $to_date]); } if(!empty($filter_status)) { if($filter_status != 4 && $filter_status != 5) { $values->where('retailer_wallets.is_status',$filter_status); $totalFiltered->where('retailer_wallets.is_status',$filter_status); } else if($filter_status == 4) { $values->where('retailer_wallets.is_pay',$filter_status); $totalFiltered->where('retailer_wallets.is_pay',$filter_status); } else { $values->where('retailer_wallets.is_status',0); $totalFiltered->where('retailer_wallets.is_status',0); } } if(!empty($filter_mode)) { $values->where('retailer_wallets.mode',$filter_mode); $totalFiltered->where('retailer_wallets.mode',$filter_mode); } if(!empty($filter_payment_mode)) { $values->where('retailer_wallets.payment_mode',$filter_payment_mode); $totalFiltered->where('retailer_wallets.payment_mode',$filter_payment_mode); } if(!empty($filter_retailer_id)) { $values->where('retailer_wallets.retailer_id',$filter_retailer_id); $totalFiltered->where('retailer_wallets.retailer_id',$filter_retailer_id); } $values = $values->get(); $totalFiltered = $totalFiltered->count(); $data = array(); if(!empty($values)) { $i = 1; foreach ($values as $value) { if($value->mode == "Credit") { $status_mode = 'Credit'; } else { $status_mode = 'Debit'; } if($value->is_status == 1) { if($value->payment_mode == "Online") { if($value->is_pay == 1) { $status = 'Approved'; } else if($value->is_pay == 4) { $status = 'Refund'; } else { $status = 'Pending'; } } else { $status = 'Approved'; } } else if($value->is_status == 2) { $status = 'Rejected'; } else if($value->is_status == 3) { $status = 'Failed'; } else if($value->is_status == 4) { $status = 'Refund'; } else if($value->is_pay == 4) { $status = 'Refund'; } else { $status = 'Pending'; } $selected = ($value->is_status == 0)?'selected':''; //$selected1 = ($value->is_status == 1)?'selected':''; $selected2 = ($value->is_status == 2)?'selected':''; $selected3 = ($value->is_status == 3)?'selected':''; $selected4 = ($value->is_status == 4)?'selected':''; $selected1 = ''; if($value->is_status == 1) { if($value->payment_mode == "Online") { if($value->is_pay == 1) { $selected1 = 'selected'; } else if($value->is_pay == 4) { $selected4 = 'selected'; } else { $selected = 'selected'; } } else { $selected1 = 'selected'; } } $style_disable = ""; if($value->is_status == 1) { if($value->is_pay == 1) { $style_disable = "disabled"; } } $walletData['id'] = $i; $walletData['retailer_id'] = $value->name; $walletData['topay_transuction_id'] = $value->topay_transuction_id; $walletData['amount'] = $value->amount; $walletData['received_amount'] = $value->received_amount; $walletData['mode'] = $status_mode; $walletData['payment_mode'] = $value->payment_mode; $walletData['remarks'] = $value->remarks; $walletData['payment_api'] = $value->payment_api; $walletData['status'] = '';; $walletData['created_at'] = date("Y-m-d H:i:s", strtotime($value->created_at)); if($value->is_status == 0 && $value->payment_mode == "Online") { $walletData['action'] = ' Check Status '; } else { $walletData['action'] = 'N/A'; } if($value->payment_api == "Lyra") { if($value->is_pay == 1 && $value->is_status == 1) { $walletData['action'] = ' Refund Amount '; } } $data[] = $walletData; $i++; } } $json_data = array( "draw" => intval($request->input('draw')), "recordsTotal" => intval($totalData), "recordsFiltered" => intval($totalFiltered), "data" => $data ); echo json_encode($json_data); } public function refundAmountLyra($id) { $get_retailer_wallet = RetailerWallet::whereId($id)->first(); if($get_retailer_wallet) { $url = config('setting.lyra_url'); $lyra_shop_id = config('setting.lyra_shop_id'); $lyra_api_key = config('setting.lyra_api_key'); $headers = [ 'Content-Type: application/json', 'Authorization: Basic ' . base64_encode(''.$lyra_shop_id.':'.$lyra_api_key.'') ]; $refundRef = rand(); $data = array( 'amount' => $get_retailer_wallet->amount * 100, 'currency' => 'INR', 'refundRef' => $refundRef, ); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); $result = curl_exec($ch); if (curl_errno($ch)) { echo 'Error: ' . curl_error($ch); } curl_close($ch); $res = json_decode($result); if(isset($res) && property_exists($res, 'status') && $res->status == "ACCEPTED") { RetailerWallet::where('id', $get_retailer_wallet->id)->update([ 'is_pay' => 4, 'refund_response' => $result, 'updated_at' => date('Y-m-d H:i:s'), ]); toastr()->success('Refunded amount send successfully!'); return redirect()->route('admin/retailer-wallet-recharge'); } else { toastr()->error('Something went wrong. Please try again later.'); return redirect()->route('admin/retailer-wallet-recharge'); } } } public function retailerWalletUpdateStatus(Request $request) { $wallet_recharge_charges = config('setting.wallet_recharge_charges'); $id = $request->id; $status = $request->status; $get_retailer_wallet = RetailerWallet::whereId($id)->first(); $get_retailer = Client::whereId($get_retailer_wallet->retailer_id)->first(); if($status == 1) { $paid_amount = $get_retailer_wallet->received_amount; Client::where('id',$get_retailer_wallet->retailer_id)->update([ 'wallet_balance' => $get_retailer->wallet_balance + $paid_amount, 'updated_at' => date('Y-m-d H:i:s'), ]); Notification::insert([ 'client_id'=>$get_retailer_wallet->retailer_id, 'ref_id'=>$get_retailer_wallet->id, 'text'=>$get_retailer->name.' Added '.$paid_amount.' for wallet', 'read_status' => 0, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]); RetailerWallet::where('id',$get_retailer_wallet->id)->update([ 'is_pay' => 1, 'updated_at' => date('Y-m-d H:i:s'), ]); $sms_text = "Dear customer, your transaction with Topay is successful! Wallet balance: ".$get_retailer_wallet->received_amount.". For assistance or inquiries, contact our support. Thank you for choosing Topay!"; Helper::sendSmsMessages($sms_text,$get_retailer->mobile_number); $get_pg_services_type = PgServicesType::where('id',$get_retailer_wallet->pg_services_id)->first(); if($get_pg_services_type) { $get_retailer_charges = RetailerCharges::where('retailer_id',$get_retailer_wallet->retailer_id)->where('pg_services_type_id',$get_pg_services_type->id)->first(); if($get_retailer_charges) { if($get_retailer) { $get_distributor_charges = DistributorCharges::where('distributor_id',$get_retailer->distributor_id)->where('pg_services_type_id',$get_pg_services_type->id)->first(); if($get_distributor_charges) { $charges = ($get_retailer_charges->charges - $get_distributor_charges->charges); $distributor_commission = ($get_retailer_wallet->amount * $charges / 100); $get_distributor = Client::where('id',$get_retailer->distributor_id)->first(); if($get_distributor) { $last_insert_wallet_id = Wallet::insertGetId(['topay_transuction_id' => sha1(md5(time())),'distributor_id' =>$get_retailer->distributor_id,'amount' => $distributor_commission,'received_amount' => $distributor_commission,'mode' => 'Credit','payment_mode' => 'Commission','is_status' => 1,'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s'),'transuction_type'=>"Retailer Wallet Recharge charges"]); Client::where('id',$get_distributor->id)->update([ 'wallet_balance' => $get_distributor->wallet_balance + $distributor_commission, 'updated_at' => date('Y-m-d H:i:s'), ]); Notification::insert([ 'client_id'=>$get_distributor->id, 'ref_id'=>$last_insert_wallet_id, 'text'=>$get_distributor->name.' Added '.$distributor_commission.' for wallet ', 'read_status' => 0, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]); } } } } } } RetailerWallet::whereId($id)->update(['is_status'=>$status]); echo json_encode(['msg'=>'status updated done.']); die; } public function checkWalletStatus($id) { $get_retailer_wallet = RetailerWallet::where('id', $id)->first(); if($get_retailer_wallet->payment_api == "Lyra") { if(!empty($get_retailer_wallet->field8)) { $res_deata = json_decode($get_retailer_wallet->field8); $url = config('setting.lyra_url').'/'.$res_deata->uuid; $lyra_shop_id = config('setting.lyra_shop_id'); $lyra_api_key = config('setting.lyra_api_key'); $headers = [ 'Content-Type: application/json', 'Authorization: Basic ' . base64_encode(''.$lyra_shop_id.':'.$lyra_api_key.'') ]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); if(curl_errno($ch)){ echo 'Curl error: ' . curl_error($ch); } curl_close($ch); $res = json_decode($result); if($res) { if($res->status == "PAID") { $get_retailer = Client::where('id',$get_retailer_wallet->retailer_id)->first(); RetailerWallet::where('id',$get_retailer_wallet->id)->update([ 'is_status' => 1, 'field8' => $result, 'updated_at' => date('Y-m-d H:i:s'), ]); Notification::insert([ 'client_id'=>$get_retailer_wallet->retailer_id, 'ref_id'=>$get_retailer_wallet->id, 'text'=>$get_retailer->name.' requesting '.$get_retailer_wallet->received_amount.' for wallet', 'read_status' => 0, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]); $get_pg_services_type = PgServicesType::where('id',$get_retailer_wallet->pg_services_id)->first(); if($get_pg_services_type) { if($get_pg_services_type->pg_service_type == "Instant") { Client::where('id',$get_retailer_wallet->retailer_id)->update([ 'wallet_balance' => $get_retailer->wallet_balance + $get_retailer_wallet->received_amount, 'updated_at' => date('Y-m-d H:i:s'), ]); Notification::insert([ 'client_id'=>$get_retailer_wallet->retailer_id, 'ref_id'=>$get_retailer_wallet->id, 'text'=>$get_retailer->name.' Added '.$get_retailer_wallet->received_amount.' for wallet', 'read_status' => 0, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]); RetailerWallet::where('id',$get_retailer_wallet->id)->update([ 'is_pay' => 1, 'updated_at' => date('Y-m-d H:i:s'), ]); $sms_text = "Dear customer, your transaction with Topay is successful! Wallet balance: ".$get_retailer_wallet->received_amount.". For assistance or inquiries, contact our support. Thank you for choosing Topay!"; Helper::sendSmsMessages($sms_text,$get_retailer->mobile_number); $get_retailer_charges = RetailerCharges::where('retailer_id',$get_retailer_wallet->retailer_id)->where('pg_services_type_id',$get_pg_services_type->id)->first(); if($get_retailer_charges) { if($get_retailer) { $get_distributor_charges = DistributorCharges::where('distributor_id',$get_retailer->distributor_id)->where('pg_services_type_id',$get_pg_services_type->id)->first(); if($get_distributor_charges) { $charges = ($get_retailer_charges->charges - $get_distributor_charges->charges); $distributor_commission = ($get_retailer_wallet->amount * $charges / 100); $last_insert_wallet_id = Wallet::insertGetId(['topay_transuction_id' => sha1(md5(time())),'distributor_id' =>$get_retailer->distributor_id,'amount' => $distributor_commission,'received_amount' => $distributor_commission,'mode' => 'Credit','payment_mode' => 'Commission','is_status' => 1,'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s'),'transuction_type'=>"Retailer Wallet Recharge charges"]); $get_distributor = Client::where('id',$get_retailer->distributor_id)->first(); if($get_distributor) { Client::where('id',$get_distributor->id)->update([ 'wallet_balance' => $get_distributor->wallet_balance + $distributor_commission, 'updated_at' => date('Y-m-d H:i:s'), ]); Notification::insert([ 'client_id'=>$get_distributor->id, 'ref_id'=>$last_insert_wallet_id, 'text'=>$get_distributor->name.' Added '.$distributor_commission.' for wallet ', 'read_status' => 0, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]); } } } } } } toastr()->success("Wallet Amount send successfully."); return back(); } } } toastr()->error("Something is wrong. Please try again."); return back(); } if($get_retailer_wallet->payment_api == "RunPaisa") { $url = config('setting.runpaisa_pg_url')."/status"; //$postdata = array('orderId' => $get_retailer_wallet->mihpayid); $postdata = '{ "order_id":"'.$get_retailer_wallet->mihpayid.'" }'; $result = Helper::curlPostRunPaisaRowData($url,$postdata); $res = json_decode($result); if($res->CODE == "RP000") { $get_retailer = Client::where('id',$get_retailer_wallet->retailer_id)->first(); RetailerWallet::where('id',$get_retailer_wallet->id)->update([ 'is_status' => 1, 'updated_at' => date('Y-m-d H:i:s'), ]); Notification::insert([ 'client_id'=>$id, 'ref_id'=>$get_retailer_wallet->id, 'text'=>$get_retailer->name.' requesting '.$get_retailer_wallet->received_amount.' for wallet', 'read_status' => 0, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]); $get_pg_services_type = PgServicesType::where('id',$get_retailer_wallet->pg_services_id)->first(); if($get_pg_services_type) { if($get_pg_services_type->pg_service_type == "Instant") { Client::where('id',$get_retailer_wallet->retailer_id)->update([ 'wallet_balance' => $get_retailer->wallet_balance + $get_retailer_wallet->received_amount, 'updated_at' => date('Y-m-d H:i:s'), ]); Notification::insert([ 'client_id'=>$get_retailer_wallet->retailer_id, 'ref_id'=>$get_retailer_wallet->id, 'text'=>$get_retailer->name.' Added '.$get_retailer_wallet->received_amount.' for wallet', 'read_status' => 0, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]); RetailerWallet::where('id',$get_retailer_wallet->id)->update([ 'is_pay' => 1, 'updated_at' => date('Y-m-d H:i:s'), ]); $sms_text = "Dear customer, your transaction with Topay is successful! Wallet balance: ".$get_retailer_wallet->received_amount.". For assistance or inquiries, contact our support. Thank you for choosing Topay!"; Helper::sendSmsMessages($sms_text,$get_retailer->mobile_number); $get_retailer_charges = RetailerCharges::where('retailer_id',$get_retailer_wallet->retailer_id)->where('pg_services_type_id',$get_pg_services_type->id)->first(); if($get_retailer_charges) { if($get_retailer) { $get_distributor_charges = DistributorCharges::where('distributor_id',$get_retailer->distributor_id)->where('pg_services_type_id',$get_pg_services_type->id)->first(); if($get_distributor_charges) { $charges = ($get_retailer_charges->charges - $get_distributor_charges->charges); $distributor_commission = ($get_retailer_wallet->amount * $charges / 100); $last_insert_wallet_id = Wallet::insertGetId(['topay_transuction_id' => sha1(md5(time())),'distributor_id' =>$get_retailer->distributor_id,'amount' => $distributor_commission,'received_amount' => $distributor_commission,'mode' => 'Credit','payment_mode' => 'Commission','is_status' => 1,'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s'),'transuction_type'=>"Retailer Wallet Recharge charges"]); $get_distributor = Client::where('id',$get_retailer->distributor_id)->first(); if($get_distributor) { Client::where('id',$get_distributor->id)->update([ 'wallet_balance' => $get_distributor->wallet_balance + $distributor_commission, 'updated_at' => date('Y-m-d H:i:s'), ]); Notification::insert([ 'client_id'=>$get_distributor->id, 'ref_id'=>$last_insert_wallet_id, 'text'=>$get_distributor->name.' Added '.$distributor_commission.' for wallet ', 'read_status' => 0, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]); } } } } } } } toastr()->success($res->MESSAGE); return back(); } if($get_retailer_wallet->payment_api == "PayU") { $key = env('PAYU_MERCHANT_KEY'); $salt = env('PAYU_SALT_KEY'); $command = "verify_payment"; $var1 = $get_retailer_wallet->mihpayid; //hash formaula $hash_str = $key . '|' . $command . '|' . $var1 . '|' . $salt ; $hash = strtolower(hash('sha512', $hash_str)); $r = array('key' => $key , 'hash' =>$hash , 'var1' => $var1, 'command' => $command); $qs= http_build_query($r); //$wsUrl = "https://test.payu.in/merchant/postservice.php?form=1"; $wsUrl = "https://info.payu.in/merchant/postservice?form=1"; $c = curl_init(); curl_setopt($c, CURLOPT_URL, $wsUrl); curl_setopt($c, CURLOPT_POST, 1); curl_setopt($c, CURLOPT_POSTFIELDS, $qs); curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0); $o = curl_exec($c); if (curl_errno($c)) { $sad = curl_error($c); throw new Exception($sad); } curl_close($c); $valueSerialized = @unserialize($o); if($o === 'b:0;' || $valueSerialized !== false) { print_r($valueSerialized); } echo $response = $o; //echo $response[0]['status']; die; } if($get_retailer_wallet->payment_api == "worldline") { $mid = env('WORLDLINE_MID_KEY'); $enckey_key = env('WORLDLINE_ENCRYPTION_KEY'); $orderid = $get_retailer_wallet->mihpayid; $trnRefNo = $get_retailer_wallet->txnid; $var=""; $merchantReqStr= $mid ."|". $orderid ."|". $trnRefNo ."|". $var ."|". $var ."|". $var ."|". $var ."|". $var ."|". $var ."|". $var ."|". $var ."|". $var ."|" ; $enc_data = $this->encryptValue($merchantReqStr,$enckey_key); $urlParameters="merchantReqStrT=".$enc_data."&mid=".$mid; //$url="https://cgt.in.worldline.com/ipg/getTransaction/Status"; $url="https://ipg.in.worldline.com/getTransaction/Status"; // Step 1 : Open the URL connection and set the request property $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,$urlParameters); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type: application/x-www-form-urlencoded')); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "\EntrustRootCertificationAuthority-G2.crt"); // Step 2 : Send the request $result = curl_exec ($ch); $error = curl_error($ch); //echo $error; // Step 3 : Read the response $reponseInfo = curl_getinfo($ch); curl_close ($ch); if (preg_match('/OK/',$result)) { echo "ok"; echo $result; die; } else { echo "Test"; echo $result; die; } } } public function encryptValue($inputVal,$secureKey) { $key=''; for ($i=0; $i < strlen($secureKey)-1; $i+=2) { $key .= chr(hexdec($secureKey[$i].$secureKey[$i+1])); } $block = 16; $pad = $block - (strlen($inputVal) % $block); $inputVal .= str_repeat(chr($pad), $pad); $encrypted_text = bin2hex(openssl_encrypt($inputVal, "aes-128-ecb", $key, OPENSSL_RAW_DATA | OPENSSL_NO_PADDING)); return $encrypted_text; } }