While what you ask can be accomplished you will find it is not worth the effort as pivoting requires advanced knowledge of the results, well at least the exact size. Since you have varying number of payments you will need to dynamically create the query. Meaning you write a code which looks at the data then writes the query before executing it. That can get very complex very quickly and the result is a maintenance nightmare. Let me propose the following instead.
Your idea to maximum number of payments done by a client in order to determine the number of columns has merit, but let SQL do that work (which it does easily), then let your client's presentation manager handle the pivoting. The following builds one row per customer with an array of payments for each customer and adding columns for number of payments for that customer and the maximum number of payments for any customer. (See demo).
select client_id, payments_made
, array_length(payments_made,1) num_payments
, max(array_length(payments_made,1)) over() max_payments
from (
select client_id, array_agg(payment order by paid_date) payments_made
from payments
group by client_id
) gs;