Ultimately the costs will all be paid by TfW via the leasing charges.
There's the intermediary, the Rosco, which finances the trains.
There will be contracts CAF-Rosco and Rosco-TfW. CAF also does the fleet maintenance, which will be another set of contracts.
I have never really understood who bears the cost of late delivery/acceptance, but for 197s it must be a lot of money for someone to find.
Probably CAF get some portion of the price on delivery and the balance on acceptance, which is when leasing kick in.
TfW also have to pay continuing leasing charges on the fleets which were supposed to be cascaded by now - 175s have gone but the 158s are still there.