middleware('admin'); } public function index() { $clients = Client::where('status',1)->where('role',1)->get(); return view('admin.wallet.index')->with('clients',$clients); } public function walletList(Request $request) { $columns = array( 0=>'id', 1=>'distributor_id', 2=>'amount', 3=>'received_amount', 4=>'mode', 5=>'payment_mode', 6=>'pay_screenshot', 7=>'payment_api', 8=>'is_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_distributor_id = $request->input('filter_distributor_id'); $totalData = Wallet::select('wallets.*','c.name')->join('clients as c','c.id','=','wallets.distributor_id')->count(); $totalFiltered = Wallet::select('wallets.*','c.name') ->join('clients as c','c.id','=','wallets.distributor_id'); if(!empty($from_date) && !empty($to_date)) { $totalFiltered->whereBetween(DB::raw('DATE(wallets.created_at)'),[$from_date, $to_date]); } if(!empty($filter_mode)) { $totalFiltered->where('wallets.mode',$filter_mode); } if(!empty($filter_payment_mode)) { $totalFiltered->where('wallets.payment_mode',$filter_payment_mode); } if(!empty($filter_distributor_id)) { $totalFiltered->where('wallets.distributor_id',$filter_distributor_id); } if(!empty($id)) { $totalFiltered->where('c.id',$id); } $values = Wallet::select('wallets.*','c.name') ->join('clients as c','c.id','=','wallets.distributor_id'); if(!empty($id)) { $values->where('c.id',$id); } $values->offset($start)->limit($limit)->orderBy('wallets'.'.'.$order,$dir); if(!empty($request->input('search'))) { $search = $request->input('search'); $values = $values->where(function ($query) use ($search) { return $query->where('wallets.amount', 'LIKE',"%{$search}%")->orWhere('wallets.mode', 'LIKE',"%{$search}%")->orWhere('wallets.payment_mode', 'LIKE',"%{$search}%")->orWhere('c.name', 'LIKE',"%{$search}%")->orWhere('wallets.created_at', 'LIKE',"%{$search}%"); }); $totalFiltered = $totalFiltered->where(function ($query) use ($search) { return $query->where('wallets.amount', 'LIKE',"%{$search}%")->orWhere('wallets.mode', 'LIKE',"%{$search}%")->orWhere('wallets.payment_mode', 'LIKE',"%{$search}%")->orWhere('c.name', 'LIKE',"%{$search}%")->orWhere('wallets.created_at', 'LIKE',"%{$search}%"); }); } if(!empty($from_date) && !empty($to_date)) { $values->whereBetween(DB::raw('DATE(wallets.created_at)'),[$from_date, $to_date]); } if(!empty($filter_mode)) { $values->where('wallets.mode',$filter_mode); } if(!empty($filter_payment_mode)) { $values->where('wallets.payment_mode',$filter_payment_mode); } if(!empty($filter_distributor_id)) { $values->where('wallets.distributor_id',$filter_distributor_id); } $values = $values->get(); $totalFiltered = $totalFiltered->count(); $data = array(); if(!empty($values)) { $i = 1; foreach ($values as $value) { if(!empty($value->pay_screenshot)) { $image = ''; } else { $image = ''; } $selected = ($value->is_status == 0)?'selected':''; $selected1 = ($value->is_status == 1)?'selected':''; $selected2 = ($value->is_status == 2)?'selected':''; $style_disable = ""; if($value->is_status == 1) { $style_disable = "disabled"; } if($value->mode == "Credit") { $status_mode = 'Credit'; } else { $status_mode = 'Debit'; } $walletData['id'] = $i; $walletData['distributor_id'] = $value->name; $walletData['amount'] = $value->amount; $walletData['received_amount'] = $value->received_amount; $walletData['mode'] = $status_mode; $walletData['payment_mode'] = $value->payment_mode; $walletData['pay_screenshot'] = $image; $walletData['payment_api'] = $value->payment_api; $walletData['is_status'] = ''; $walletData['created_at'] = date("Y-m-d H:i:s", strtotime($value->created_at)); if($value->is_status == 1) { $walletData['action'] = ' '; } else { $walletData['action'] = ' '; } if($value->is_status == 0 && $value->payment_mode == "Online") { $walletData['action'] .= '  Check Status '; } 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 distributorRefundAmountLyra($id) { $get_wallet = Wallet::whereId($id)->first(); if($get_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_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") { Wallet::where('id', $get_wallet->id)->update([ 'is_pay' => 4, 'refund_response' => $result, 'updated_at' => date('Y-m-d H:i:s'), ]); toastr()->success('Retailer amount send successfully!'); return redirect()->route('admin/wallet-list'); } else { toastr()->error('Something went wrong. Please try again later.'); return redirect()->route('admin/wallet-list'); } } } public function walletInsert(Request $request) { $data = [ 'topay_transuction_id' => sha1(md5(time())), 'distributor_id' => $request->input('distributor_id'), 'amount' => $request->input('amount'), 'mode' => $request->input('mode'), 'payment_mode' => $request->input('payment_mode'), 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), ]; if($files=$request->file('pay_screenshot')) { $destination = 'storage/app/public/payment'; $image= time().$files->getClientOriginalName(); $files->move($destination,$image); $data['pay_screenshot'] = $image; } Wallet::insertGetId($data); $get_distributor = Client::where('id',$request->input('distributor_id'))->first(); if($request->input('mode') == "Credit") { Client::where('id',$request->input('distributor_id'))->update([ 'wallet_balance' => $get_distributor->wallet_balance + $request->input('amount'), 'updated_at' => date('Y-m-d H:i:s'), ]); } else { Client::where('id',$request->input('distributor_id'))->update([ 'wallet_balance' => $get_distributor->wallet_balance - $request->input('amount'), 'updated_at' => date('Y-m-d H:i:s'), ]); } toastr()->success('Wallet balance added successfully.!'); return redirect()->route('admin/wallet-list'); } public function walletEdit($id) { $wallet = Wallet::where('id', $id)->first(); echo json_encode(['wallet'=>$wallet]); die; } public function walletUpdate(Request $request) { $wallet_id = $request->input('wallet_id'); $distributor_id = $request->input('distributor_id'); $wallet = Wallet::where('id', $wallet_id)->first(); $get_distributor = Client::where('id',$wallet->distributor_id)->first(); if($wallet->mode == "Credit") { Client::where('id',$wallet->distributor_id)->update([ 'wallet_balance' => $get_distributor->wallet_balance - $wallet->amount, 'updated_at' => date('Y-m-d H:i:s'), ]); } else { Client::where('id',$wallet->distributor_id)->update([ 'wallet_balance' => $get_distributor->wallet_balance + $wallet->amount, 'updated_at' => date('Y-m-d H:i:s'), ]); } Wallet::whereId($wallet_id)->update([ 'distributor_id' => $distributor_id, 'amount' => $request->input('amount'), 'mode' => $request->input('mode'), 'payment_mode' => $request->input('payment_mode'), 'updated_at' => date('Y-m-d H:i:s'), ]); $get_distributor = Client::where('id',$wallet->distributor_id)->first(); if($request->input('mode') == "Credit") { Client::where('id',$distributor_id)->update([ 'wallet_balance' => $get_distributor->wallet_balance + $request->input('amount'), 'updated_at' => date('Y-m-d H:i:s'), ]); } else { Client::where('id',$distributor_id)->update([ 'wallet_balance' => $get_distributor->wallet_balance - $request->input('amount'), 'updated_at' => date('Y-m-d H:i:s'), ]); } toastr()->success('Wallet balance added successfully.!'); return redirect()->route('admin/wallet-list'); } public function walletDelete($id) { /* $wallet = Wallet::where('id', $id)->first(); $get_distributor = Client::where('id',$wallet->distributor_id)->first(); if($wallet->mode == "Credit") { Client::where('id',$wallet->distributor_id)->update([ 'wallet_balance' => $get_distributor->wallet_balance - $wallet->amount, 'updated_at' => date('Y-m-d H:i:s'), ]); } else { Client::where('id',$wallet->distributor_id)->update([ 'wallet_balance' => $get_distributor->wallet_balance + $wallet->amount, 'updated_at' => date('Y-m-d H:i:s'), ]); } */ Wallet::where('id', $id)->delete(); toastr()->success('Wallet delete successfully.!'); return redirect()->route('admin/wallet-list'); } public function distributorCheckWalletStatus($id) { $get_distributor_wallet = Wallet::where('id', $id)->first(); if($get_distributor_wallet->payment_api == "Lyra") { if(!empty($get_distributor_wallet->field8)) { $res_deata = json_decode($get_distributor_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_distributor = Client::where('id',$get_distributor_wallet->distributor_id)->first(); Wallet::where('id',$get_distributor_wallet->id)->update([ 'is_status' => 1, 'updated_at' => date('Y-m-d H:i:s'), ]); Notification::insert([ 'client_id'=>$id, 'ref_id'=>$get_distributor_wallet->id, 'text'=>$get_distributor->name.' requesting '.$get_distributor_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_distributor_wallet->pg_services_id)->first(); if($get_pg_services_type) { if($get_pg_services_type->pg_service_type == "Instant") { Client::where('id',$get_distributor_wallet->distributor_id)->update([ 'wallet_balance' => $get_distributor->wallet_balance + $get_distributor_wallet->received_amount, 'updated_at' => date('Y-m-d H:i:s'), ]); Notification::insert([ 'client_id'=>$get_distributor_wallet->distributor_id, 'ref_id'=>$get_distributor_wallet->id, 'text'=>$get_distributor->name.' Added '.$get_distributor_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'), ]); Wallet::where('id',$get_distributor_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_distributor_wallet->received_amount.". For assistance or inquiries, contact our support. Thank you for choosing Topay!"; Helper::sendSmsMessages($sms_text,$get_distributor->mobile_number); } } toastr()->success("Wallet Amount send successfully."); return back(); } } } toastr()->error("Something is wrong. Please try again."); return back(); } if($get_distributor_wallet->payment_api == "RunPaisa") { $url = config('setting.runpaisa_pg_url')."/status"; $postdata = '{ "order_id":"'.$get_distributor_wallet->mihpayid.'" }'; $result = Helper::curlPostRunPaisaRowData($url,$postdata); $res = json_decode($result); if($res->CODE == "RP000") { $get_distributor = Client::where('id',$get_distributor_wallet->distributor_id)->first(); Wallet::where('id',$get_distributor_wallet->id)->update([ 'is_status' => 1, 'updated_at' => date('Y-m-d H:i:s'), ]); Notification::insert([ 'client_id'=>$id, 'ref_id'=>$get_distributor_wallet->id, 'text'=>$get_distributor->name.' requesting '.$get_distributor_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_distributor_wallet->pg_services_id)->first(); if($get_pg_services_type) { if($get_pg_services_type->pg_service_type == "Instant") { Client::where('id',$get_distributor_wallet->distributor_id)->update([ 'wallet_balance' => $get_distributor->wallet_balance + $get_distributor_wallet->received_amount, 'updated_at' => date('Y-m-d H:i:s'), ]); Notification::insert([ 'client_id'=>$get_distributor_wallet->distributor_id, 'ref_id'=>$get_distributor_wallet->id, 'text'=>$get_distributor->name.' Added '.$get_distributor_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'), ]); Wallet::where('id',$get_distributor_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_distributor_wallet->received_amount.". For assistance or inquiries, contact our support. Thank you for choosing Topay!"; Helper::sendSmsMessages($sms_text,$get_distributor->mobile_number); } } } toastr()->success($res->MESSAGE); return back(); } if($get_distributor_wallet->payment_api == "PayU") { $key = env('PAYU_MERCHANT_KEY'); $salt = env('PAYU_SALT_KEY'); $command = "verify_payment"; $var1 = $get_distributor_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_distributor_wallet->payment_api == "worldline") { $mid = env('WORLDLINE_MID_KEY'); $enckey_key = env('WORLDLINE_ENCRYPTION_KEY'); $orderid = $get_distributor_wallet->mihpayid; $trnRefNo = $get_distributor_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 distributorWalletStatusUpdate(Request $request) { $wallet_recharge_charges = config('setting.wallet_recharge_charges'); $id = $request->id; $status = $request->status; $wallet = Wallet::whereId($id)->first(); $client = Client::whereId($wallet->distributor_id)->first(); if($status == 1) { $paid_amount = $wallet->received_amount; Client::where('id',$wallet->distributor_id)->update([ 'wallet_balance' => $client->wallet_balance + $paid_amount, 'updated_at' => date('Y-m-d H:i:s'), ]); Wallet::where('id',$wallet->id)->update([ 'is_pay' => 1, 'updated_at' => date('Y-m-d H:i:s'), ]); Notification::insert([ 'client_id'=>$wallet->distributor_id, 'ref_id'=>$wallet->id, 'text'=>$client->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'), ]); $sms_text = "Dear customer, your transaction with Topay is successful! Wallet balance: ".$paid_amount.". For assistance or inquiries, contact our support. Thank you for choosing Topay!"; Helper::sendSmsMessages($sms_text,$client->mobile_number); } Wallet::whereId($id)->update(['is_status'=>$status]); echo json_encode(['msg'=>'status updated done.']); die; } }