onTransactionComplete called twice?

It seems that onTransactionComplete is being called twice on a successful transaction. I’m sure only one browser window is open so it’s not that it’s being called from multiple screens. My apache log looks like:

xx.xx.xx.xx - - [12/Mar/2019:01:34:48 +0000] “POST /abcHTTP/1.1” 200 39
xx.xx.xx.xx - - [12/Mar/2019:01:34:48 +0000] “POST /abcHTTP/1.1” 500 84976

The second header returns a 500 because I set a unique index on the transaction id from twitch to make sure it didn’t accidentally enter it twice. I made some error checking to prevent the 500 error but it’s really weird that it seems to call twice.

I added a try/catch to get rid of the 500 and still see the same thing. I end up with the data inserted once as I would like but the browser is only seeing the second response for some reason and so I end up with a different response than I should.

It’s very strange behavior, I’ve tried console.log() on onTransactionComplete and I see it once only but it seems to only log once, which made me thing that maybe jQuery’s post function was the culprit but I’ve tried logging with that as well and I cannot seem to see any double log entries there either.

Any ideas?

Check the network tab of devtools and see what requests are being sent.

Also, you say only one browser window is open, but what about other users? If you have selected that SKU to broadcast then all users on that channel will receive a transaction through onTransactionComplete.

This may be it. If someone else has the browser open maybe their browser is sending the transaction first and mine is sending second, so that’s why I’m seeing the duplicate response most of the time and intermittently getting the right response. I’ll double check all my SKUs…

You’re right! I had a SKU setup for testing while in development and it was set to broadcast = “yes”, but my production ones were all set to “no” and so I was just seeing it while testing.

Thanks a ton!

I’m glad that’s solved then :slight_smile:

Broadcasting is set to true by default so it’s easy to forget to change it when creating a new SKU.