I’m trying to get the latest inventory counts after a successful order/payment transaction, but I’m still receiving the same quantity value as it was before the transaction.
Here is what I am doing.
My menu page loads with all the current items and each items variation with its inventory quantity.
Time passes, customer selects item(s) for order ahead and checks out.
On the server before I create an order I verify that all items in their cart are still in stock - no problem
I then create the order and submit the payment.
In the same request before returning the success response to the client, I make a fresh call to batch retrieve inventory counts so that I can send down and merge / update the latest quantities on the client side, however I find that the quantities for the items just ordered are not updated.
I figured since the count is a calculated field in Square, perhaps I queried before it was updated (only a few milliseconds after payment response). So I changed my code to send the successful response w/o the updated quantities, and instead on the Thank You / Receipt page I make a new separate ajax request to get the latest inventory, but I’m still getting the old quantities.
if I wait another second or two and manually query the API, I see the correct updated counts. I feel like adding a forced wait timer is a hack, and I really don’t want to implement a web hook and have it update every single client every single time an items inventory changes, but I’m not sure what else to try.
Inventory tracking in an order ahead app does not need to be perfect, however I don’t want it to be so far out of sync as to annoy my customers either.
Any suggestions would be appreciated