Good evening. Faced a problem, I have a website on which a button is used to buy a digital product. A click on the button sends a post request to the server, processes the data, takes the balance and issues a digital product.
Today we were hacked, sending 25 commands to the server in 2 seconds, apparently the server did not fully manage and the user lost the balance 10 times less (The cost of 1 product was 35 rubles, the user had 800 balance, he bought 25 goods, but the balance became 700), I repeated his actions, using the chrome console sent 20 copies of the $ .post command and the result was the same, the goods stood out, but the balance decreased only by 1/10 of the required
The question is, how can I limit the number of requests to 1 url from 1 user, say 1 request per 2 seconds on the server side? Or maybe there are other solutions to the problem?