$orderId], $data, ['addons_meta' => !empty($addons) ? $addons : null]), ); } // ------------------------------------------------------------------------- // processPayment // ------------------------------------------------------------------------- public function processPayment(Order $order, string $method): Order { $order->update([ 'status' => OrderStatus::ACTIVE->value, 'payment_method' => $method, ]); if ($order->invoice) { $order->invoice->update([ 'status' => InvoiceStatus::PAID->value, 'payment_method' => $method, 'paid_at' => now(), ]); } return $order->fresh(['orderItems', 'invoice', 'customer']); } // ------------------------------------------------------------------------- // hasPendingOrder // ------------------------------------------------------------------------- public function hasPendingOrder(int $customerId): bool { return $this->model->where('customer_id', $customerId)->where('status', OrderStatus::PENDING->value)->exists(); } // ------------------------------------------------------------------------- // getOrders // ------------------------------------------------------------------------- public function getOrders(int $customerId, array $filters): LengthAwarePaginator { $query = $this->model->where('customer_id', $customerId); if (!empty($filters['total_price'])) { $query->where('total', $filters['total_price']); } if (!empty($filters['pending']) && filter_var($filters['pending'], FILTER_VALIDATE_BOOLEAN)) { $query->where('status', OrderStatus::PENDING->value); } return $query->orderByDesc('created_at')->paginate(10); } }