Payer of the transaction pays for the CPI calls as well.
Failed transactions, including those that fail due to a CPI call, still pay transaction fees.
The two main reasons are:
the transaction was executed by the leader validator so it consumed resources regardless of it's failure
it prevents spam/DDOS attacks that would be possible if failed transactions were free for the sender. With free transactions, an attacker could simply flood the network making it unusable.
Thankfully, Solana lets you simulate a transaction before sending it, this helps to avoid errors and wasted fees.
https://docs.solana.com/api/http#sendtransaction
Before submitting, the following preflight checks are performed:
The transaction signatures are verified
The transaction is simulated against the bank slot specified by the preflight commitment. On failure an error will be returned. Preflight