public function acceptOrder(Request $request) { $order = Order::findOrNew($request->get('order_id')); $order->status = 1; //accepted $order->save(); $product = Product::findOrNew($request->get('product_id')); $product->amount = $product->amount - $request->get('product_amount'); $product->save(); $bill = new Bill(); $bill->status = 0; $bill->customer_id = 1; $bill->order_id = $order->id; $bill->save(); $passingData = array('order_id' => $order->id, 'message_title' => 'Confirmed order', 'message_detail' => 'You order id ' . $request->get('order_id') . ' has been confirm (product_name : ' . $request->get('product_name') . ', order_date : ' . $request->get('order_date') . ')'); $data_string = json_encode($passingData); $url = curl_init('http://localhost:8080/api/order/confirm'); curl_setopt($url, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($url, CURLOPT_POSTFIELDS, $data_string); curl_setopt($url, CURLOPT_RETURNTRANSFER, true); curl_setopt($url, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string))); // response back $result = curl_exec($url); $data = array('name' => $order->customer->name, 'phone_number' => $order->customer->phone_number, 'email' => $order->customer->email, 'line1' => $order->customer->customerAddress->line1, 'district' => $order->customer->customerAddress->district, 'province' => $order->customer->customerAddress->province, 'post_code' => $order->customer->customerAddress->post_code, 'product_name' => $order->orderDetail->product->name, 'product_amount' => $order->orderDetail->amount, 'total_price' => $order->orderDetail->total_price, 'is_paid' => 0, 'order_id' => $order->id); $data_string = json_encode($data); $url2 = curl_init('http://localhost:8080/api/bill/create'); curl_setopt($url2, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($url2, CURLOPT_POSTFIELDS, $data_string); curl_setopt($url2, CURLOPT_RETURNTRANSFER, true); curl_setopt($url2, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string))); $result2 = curl_exec($url2); $notificationData = array('message_title' => 'Notify Payment', 'message_detail' => 'Your bill which has order id ' . $request->get('order_id') . 'is waiting for payment.'); $data_string = json_encode($notificationData); $notificationUrl = curl_init('http://localhost:8080/api/notification/add'); curl_setopt($notificationUrl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($notificationUrl, CURLOPT_POSTFIELDS, $data_string); curl_setopt($notificationUrl, CURLOPT_RETURNTRANSFER, true); curl_setopt($notificationUrl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string))); // response back $result3 = curl_exec($notificationUrl); return redirect()->back(); }