Answer the question
In order to leave comments, you need to log in
How to disable two parallel requests?
Hello! There is a website site.com.
The site has a payment section. The user enters and selects the payment system for which he wants to receive his money. What is the problem?
The problem is that the user accesses the site, for example, in normal browser mode and through incognito in the same account, and can also create as many isolated sessions in the same account from one browser using sessionbox (extension).
So further, the process of payments on the side of the site occurs in such a way that the user sends a request and the server accepts it, and php sends a request to the payment system, and then writes to the database if the transaction was successful.
But let's imagine a situation when a user sends 3 identical requests from different sessions from one account.
At what point it is not clear, but most likely when php is waiting for a response from the payment system, that is, 3 requests are waiting for a response from the PS, then it occurs with some delay, that is, depending on the PS API, we will wait for a different response time, from payeer .com for example 2 seconds, from qiwi 500ms.
But as a result, all 3 requests are executed and the user receives a payment 3 times, and not 1 time.
The solution to this problem, it seems to me, lies in the fact that every time a user enters the payout page, create some kind of unique hash that will write to the user's table, for example, and the last request will be written to the table and upon payment we will compare.
Or option 2, when we simply write down the user's request for payment, and we ourselves will make payments to the user in the background with crowns.
What else can be a solution in this situation?
Answer the question
In order to leave comments, you need to log in
At the beginning of the transaction, withdraw the amount from the user's balance, writing it down along with the transaction ID. After confirming the transfer, delete the entry. In case of refusal or timeout, return the amount to the user's balance.
As an option, do not withdraw the amount, but mark it as blocked, making a real decrease in the balance after confirming the transfer.
Well, limit the frequency of withdrawal requests from one user.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question