You pay at the time of declaration. For example, in Canada, the Customs official will let you know if you have to pay tax, and if so, direct you to the cashier (if at an airport) or to the office (if at a land crossing) where you can pay your taxes/duties. Canada will accept cash, cheques, VISA, MasterCard and American Express. I suspect most western countries will take at least some credit cards, but some countries probably only accept cash.
If you are unsure about the country you are visiting (or the country you are from), check their website or call them in advance.
Normally you will only pay tax/duty re-entering your own country, depending on the dollar amount of your purchases but if you are bringing in significant amounts of goods, particularly for others, or more than a small amount of alcohol or tobacco, you may need to pay tax/duty in a country you are visiting.