Return master and master details record(s) in a single row in postgresql
It's really hard to tell what exactly you want, but maybe something like this:

select jsonb_build_object('customer', to_jsonb(c), 
                          'total_amount', pd.total_amount,
                          'payment_details', pd.payments)
from customer c
  join lateral (
     select jsonb_agg(jsonb_build_object('amount', amount, 'date', payment_date)) as payments,
            sum(amount) as total_amount
     from payment p
     where p.customer_id = c.customer_id
  ) pd on true