I’m working with a 3rd-party payment service that sends my user back to my site after doing a payment on their site. It sends the user back with javascript (setTimeout and location='my_site.com?data'), but there’s also a button the user can click if it takes too long. The double request happens when the browser is already loading my site because of the javascript, and the user clicks the button.
Can I prevent the request is handled twice? Or should I simply handle it twice?
Right now, I show a “request is already handled” when the same request is handled twice, but because the two requests happen near simultaneously, the user never sees the page that says the request was correctly handled.
In this case you want your user to get the correct feedback and from what you’ve said you are aware that they currently lose the response to the first request.
So what you probably want to do is for any subsequent request (possibly only within a certain time frame) to check if the event has been handled already. If it has been handled already you may want to check that the handling is consistent (ie that the data is the same both times and deal appropriately if the data is in fact different).
If its all the same you can display the “handled correctly” page whether it is the first or second or tenth time they went to the page.
Other techniques to handle this may include making sure that your landing page returns faster. Presumably the problem is that a reasonable amount of work is being done on your side whcih is causing them to give up and go for the click as well. If you can reduce this time to display content then that may solve your problem in a slightly better way. This might involve something like returing a small page that has your site branding and says “please wait while we process your order” or whatever. This then puts the control in your hand and allows you to more intelligently deal with the double click scenario at the beginning.
Exact solution will depend on your exact situation though.