Because you're asking for the number of rows, not the actual data.
You want to fetch the row data and use that. Some searching suggests that you'd do that using this code:
return $query->row()->total_paid_amount
Also, if you're trying to get a sum of all payments, you probably don't want to be using GROUP BY, and should remove p_id from your select list.