Buying Out of State: When do you pay?

Hello,
I’ve found the car I want to buy 4 hours away in another state.
I have just begun negotiations on the OTD price. I’ve researched about buying a car from out of state but one question I have is: if I get the price I want when should I pay for the car?
Should I pay for it ahead of time before I go to the dealership so it’s all locked up and ready to go or should I wait until I go the dealership to pay for it? Is there an advantage of paying ahead of time versus traveling there, then doing all the paperwork and paying for it then? Thank you.