How long do i have to wait after a transaction before calling batch retrieve inventory counts?

Hi
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

1 Like

As far as I know this is how it currently works, since the inventory is updated asynchronously from the payment there is no guarantee on when/how soon the inventory will be updated.

1 Like

Thanks Stephen - as I figured.
In my unscientific testing I’ve observed it taking close to 5 seconds to refresh so I’ve implemented a timeout. Feels a bit dirty but its working

const timeout = setTimeout(async () => {
await this.getCatalogInventory(false); // dont show loading - silently update in the background
clearTimeout(timeout);
}, 5000);

1 Like