Vending using the DG600F(s) 6 coin acceptor

It may be too early for you, but eventually you’ll see the sense in a state-machine, to keep track of what has happened, what is happening, and what needs to happen next.

6v6gt’s suggestion is correct.
Break your code apart (keep a copy of what you have so far!)
Then you’ll know that each function() operates reliably and independently, and you can tie them together.