get(); return view('agent.index', compact('agents')); } public function create() { $types = AgentType::all(); return view('agent.create', compact('types')); } public function store(Request $request) { $agent = new Agent(); $agent->type_id = $request->get('type_id'); $agent->name = $request->get('name'); $agent->email = $request->get('email'); $agent->phone = $request->get('phone'); $agent->domain = $request->get('domain'); $agent->deposit = $request->get('deposit') ? str_replace(',', '.', str_replace('.', '', $request->get('deposit'))) : '0'; $agent->created_at = date('Y-m-d H:i:s'); $agent->save(); return redirect()->route('agent.index')->with('message', 'Agent Successfully Added'); } public function edit($id) { $agent = Agent::findOrFail($id); $types = AgentType::all(); return view('agent.edit', compact('agent', 'types')); } public function update(Request $request, $id) { $agent = Agent::findOrFail($id); $agent->type_id = $request->get('type_id'); $agent->name = $request->get('name'); $agent->email = $request->get('email'); $agent->phone = $request->get('phone'); $agent->domain = $request->get('domain'); $agent->created_at = date('Y-m-d H:i:s'); $agent->save(); return redirect()->route('agent.index')->with('message', 'Agent Successfully Updated'); } public function delete(Request $request) { Agent::destroy($request->get('agent_id')); return 'true'; } public function order() { $orders = OrderAgent::orderBy('id')->get(); return view('order_agent.index', compact('orders')); } public function updateAfterWhmcs(Request $request) { $order_id = $request->get('order_id'); $order = OrderAgent::findOrFail($order_id); $order->status = 'inactive'; $order->whmcs_order_id = $request->get('whmcs_order_id'); $order->save(); return 'true'; } public function addToCloudflare(Request $request) { $domain = $request->get('domain'); $order_id = $request->get('order_id'); $order = OrderAgent::findOrFail($order_id); // GET DOMAIN ID $user_id = $request->get('user_id'); // ADD DOMAIN TO CLOUDFLARE $data_1 = [ 'account' => [ 'id' => '95b4aefc1b159eb30a1e11f6c481b0e7' ], 'name' => $domain, 'jump_start' => true ]; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://api.cloudflare.com/client/v4/zones", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => json_encode($data_1), CURLOPT_HTTPHEADER => array( "X-Auth-Key: 0b0e252aca941390463df4b4c758ab4b08074", "X-Auth-Email: mybintoroapps@gmail.com", "Content-Type: application/json" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); // GET DOMAIN ZONE ID $zone_id = json_decode($response, true)['result']['id']; // UPDATE ZONE ID TO ORDER BINGGO DATA $order->zone_id = $zone_id; $order->save(); return 'true'; } public function activate(Request $request) { $order = OrderAgent::findOrFail($request->get('order_id')); $data_2 = [ 'type' => 'A', 'name' => $order->domain, 'content' => '51.79.152.251', 'ttl' => 120, 'priority' => 10, 'proxied' => false ]; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://api.cloudflare.com/client/v4/zones/" . $order->zone_id . '/dns_records', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => json_encode($data_2), CURLOPT_HTTPHEADER => array( "X-Auth-Key: 0b0e252aca941390463df4b4c758ab4b08074", "X-Auth-Email: mybintoroapps@gmail.com", "Content-Type: application/json" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); $order->status = 'active'; $order->active_at = date('Y-m-d H:i:s'); $order->save(); // Update Deposit $service = Whmcs::GetProducts([ 'pid' => $order->pid ]); $setup_fee = $service['products']['product'][0]['pricing']['IDR']['asetupfee']; $annually = $service['products']['product'][0]['pricing']['IDR']['annually']; $total = $setup_fee + $annually; $total_final = number_format($total, 0, ',', '.'); $recent = Agent::findOrFail($order->agent_id); $recent_deposit = $recent->deposit; $recent_income = $recent->income; if($recent->type_id != NULL) { $commision = ($recent->type->commision/100) * $total; } else { $commision = 0; } $agent = Agent::findOrFail($order->agent_id); $agent->deposit = $recent_deposit - $total; $agent->income = $recent_income + $commision; $agent->save(); return [ 'cost' => $total_final, 'deposit' => $agent->deposit, 'commision' => $commision, 'income' => $agent->income, 'domain' => $agent->domain, 'order_id' => $order->order_agent_id ]; } public static function checkZoneStatus($zone_id) { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://api.cloudflare.com/client/v4/zones/" . $zone_id, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "X-Auth-Key: 0b0e252aca941390463df4b4c758ab4b08074", "X-Auth-Email: mybintoroapps@gmail.com", "Content-Type: application/json" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); $status = json_decode($response, true)['result']['status']; return $status; } public function changeDeposit(Request $request) { $amount = str_replace(',', '.', str_replace('.', '', $request->get('amount'))); $action = $request->get('action'); $temp = Agent::findOrFail($request->get('agent_id'))->deposit; $agent = Agent::findOrFail($request->get('agent_id')); if($action == 'increase') { $agent->deposit = $temp + $amount; } else if($action == 'decrease') { $agent->deposit = $temp - $amount; } $agent->save(); return [ 'deposit' => $agent->deposit, 'domain' => $agent->domain, 'amount' => $amount ]; } public function withdraw() { $withdraws = AgentWithdraw::orderBy('id', 'DESC')->get(); return view('withdraw.index', compact('withdraws')); } public function confirmWithdraw(Request $request) { $withdraw_id = $request->get('withdraw_id'); $withdraw = AgentWithdraw::findOrFail($withdraw_id); $agent = Agent::findOrFail($withdraw->agent_id); if($agent->income >= $withdraw->amount) { if ($request->hasFile('slip_image')) { $image = $request->file('slip_image'); $ext = $image->getClientOriginalExtension(); if ($request->file('slip_image')->isValid()) { // CHECK IF FILE EXIST $image_name = date('YmdHis') . '.' . $ext; $upload_path = 'withdraw'; $request->file('image')->move($upload_path, $image_name); $withdraw->status = 'paid'; $withdraw->bukti_pembayaran = $image_name; $withdraw->paid_at = date('Y-m-d H:i:s'); $withdraw->save(); $temp_saldo = $agent->income; $agent->income = $temp_saldo - $withdraw->amount; $agent->save(); return [ 'status' => 'success', 'link_image' => 'https://binggo.co.id/withdraw/' . $image_name, 'domain' => $agent->domain, 'amount' => $withdraw->amount, 'balance' => $agent->income, 'paid_at' => date('Y-m-d H:i:s') ]; } else { return [ 'status' => 'failed', 'message' => 'Image is not valid' ]; } } else { return [ 'status' => 'failed', 'message' => 'Image is not valid' ]; } } else { return [ 'status' => 'failed', 'message' => 'Income is not enough' ]; } } }