user(); $result = $this->orderService->create($request->validated(), $customer); return response()->json([ 'success' => true, 'data' => $result, 'message' => 'Tạo đơn hàng thành công' ], 201); } catch (\Exception $e) { return response()->json([ 'success' => false, 'message' => $e->getMessage() ], 400); } } public function payOrder(int $id, PayOrderRequest $request): JsonResponse { try { $order = $this->orderRepo->find($id); if (!$order) { return response()->json(['message' => 'Đơn hàng không tồn tại'], 404); } if ($order->customer_id !== $request->user()->id) { return response()->json(['message' => 'Không có quyền truy cập'], 403); } $this->orderService->pay($order, $request->payment_method); return response()->json([ 'success' => true, 'message' => 'Thanh toán thành công' ]); } catch (\Exception $e) { return response()->json([ 'success' => false, 'message' => $e->getMessage() ], 400); } } }