validate([ 'status' => ['nullable', 'string', 'in:pending_payment,paid,cancelled,expired'], 'per_page' => ['nullable', 'integer', 'min:10', 'max:100'], ]); $user = Auth::user(); $invoices = $this->invoiceService->getCustomerInvoices($user, $validated); return response()->json([ 'success' => true, 'data' => [ 'invoices' => $invoices->items(), 'pagination' => [ 'current_page' => $invoices->currentPage(), 'last_page' => $invoices->lastPage(), 'per_page' => $invoices->perPage(), 'total' => $invoices->total(), ], ], ]); } /** * GET /api/v1/customer/invoices/{id} * جزئیات یک فاکتور. */ public function show(int $id): JsonResponse { $user = Auth::user(); $invoice = ManualInvoice::where('id', $id) ->where('user_id', $user->id) ->with(['issuedBy:id,name']) ->first(); if (! $invoice) { return response()->json([ 'success' => false, 'message' => 'فاکتور یافت نشد.', ], 404); } return response()->json([ 'success' => true, 'data' => $this->invoiceService->toArray($invoice), ]); } /** * POST /api/v1/customer/invoices/{id}/pay * پرداخت فاکتور از کیف پول مشتری. */ public function pay(int $id): JsonResponse { $user = Auth::user(); $invoice = ManualInvoice::where('id', $id) ->where('user_id', $user->id) ->first(); if (! $invoice) { return response()->json([ 'success' => false, 'message' => 'فاکتور یافت نشد.', ], 404); } try { $paid = $this->invoiceService->payFromWallet($invoice, $user->id); return response()->json([ 'success' => true, 'message' => 'فاکتور با موفقیت پرداخت شد.', 'data' => $this->invoiceService->toArray($paid), ]); } catch (\RuntimeException $e) { return response()->json([ 'success' => false, 'message' => $e->getMessage(), ], 400); } catch (\Throwable $e) { report($e); return response()->json([ 'success' => false, 'message' => 'خطای داخلی سرور هنگام پرداخت فاکتور.', ], 500); } } }