Vending machines sound like a very modern tool, but they have been around since the 1880s. While they began as simple machines for dispensing mostly snacks, they are used for many other purposes now, mostly food though. Fresh baguettes, pizzas, bus tickets, short stories, used cars, and even live crabs, basically everything that you can imagine.
The only question is, how does the machine identify money. As a child, you might have tried tricking the vending machine with a fake object or even a counterfeit coin, but we highly doubt that it would have worked. Vending machines are nothing stupid.
The identification mechanism for bills in a vending machine uses optical scanning. Tiny photocells look for patterns in the bill to identify which one it is. The bills are either printed with fluorescent inks or magnetic inks, and the corresponding type of scanner can identify the type and denomination of the bill.
To tell different coins apart, the vending machines look at the physical attributes of the coin, including its diameter, thickness, and the ridges on the sides. It measures all these attributes using light sensors, but that is not all. The machines are equipped with electromagnetic sensors that sense the type of metal the coin is made of. So you can not just throw in any metal shaped like a quarter and fool the machine into thinking it actually is one.