Cash on the nail (or pay on the nail) are extensions of the earlier phrase - on the nail, meaning immediate, without delay. Versions of this were used in several European languages:
14th century Anglo-Norman, as payer sur le vngle - to pay immediately and in full. 17th century French, as sur l'ongle - exactly. Dutch, as op den nagel - on the nail German, as auf den Nagel - entirely, to the last detail.
On the nail is first recorded in English in Thomas Nashe's Haue with you to Saffron-Walden, 1596:
"Tell me, haue you a minde to anie thing in the Doctors Booke! speake the word, and I will help you to it vpon the naile."
The 'cash on the nail' version appears to be an American adaptation and was in common use in the USA from the early 19th century. Here's an early example from The Lorain Standard, August 1840:
"Kendall wants to buy 3000 bushels [of wheat] if delivered within two weeks - and cash on the nail."
By around 1900 the US also began to use cash on the barrel with the same meaning.
The story that cash on the nail relates to the bronze pillars, called nails, that are to be seen outside the Corn Exchange in Bristol and the Stock Exchanges in Limerick and Liverpool is widely circulated. Whisper it not in Bristol but this has to be treated with some caution. It is said that the oldest of the four pillars in Bristol is mid-16th century and so would just pre-date the earliest printed reference to on the nail. It is also true that business deals were sealed on these pillars. The late dates of the appearance of either or the terms cash on the nail and pay on the nail, make the attribution doubtful. None of the early printed references make any reference to any of the cities with nails - unsurprising, as most of those references originate in the USA rather than the West Country. The first time the suggested link between the bronze nails and the phrase was made was in 1870 - years after the phrase was already current in the USA. It seems more likely that the nails were named to match the expression rather than the other way around.