Hi everyone, I’ve been working on integrating Square into my website for Texas Roadhouse menu orders, and I’ve run into a fairly complex issue that I haven’t been able to figure out. My website is set up to handle online orders for pickup, and I’m using Square APIs to process payments. The problem is that the checkout flow isn’t behaving consistently, and it seems like there’s a disconnect between the order creation and payment confirmation steps. Sometimes the order gets logged in the Square dashboard, but the payment isn’t attached properly, which causes my system to mark the order as unpaid even though the customer gets charged.
I’ve structured the flow so that the backend first creates an order with line items that match the Texas Roadhouse family meals and other menu items. Then, I’m generating a payment request that links back to that order. The strange thing is that when I test in the sandbox environment, everything works perfectly, but in production, about 1 out of 10 orders fails to link the payment correctly. This results in customer support tickets and manual intervention, which is obviously not sustainable.
Another issue I’m noticing is with the webhook notifications. I have webhooks set up for both payment.updated and order.updated, but the timing of these events seems inconsistent. Sometimes the payment webhook arrives before the order webhook, and other times it’s reversed. This wouldn’t normally be a big deal, but my logic depends on receiving the order confirmation first and then updating the payment status. Because of this inconsistency, some orders remain stuck in a “pending” state even though they’ve already been paid.
I’ve tried debugging this by logging request IDs and event payloads, and I can confirm that the issue doesn’t appear to be on my server side. All webhook events are being received, but the linking logic sometimes fails because the order object in the payload doesn’t have the payment info attached yet. It feels like there’s a race condition happening between the order update and payment update events, but I can’t find a clear best practice in the documentation for handling this.
I also want to point out that I’m using the latest Square SDK for Node.js, and I’ve followed the recommended order creation and payment flow from the docs. I even tried implementing a retry mechanism where I re-check the order status after a short delay, but that only partially fixes the issue and adds unnecessary complexity. What I really need is a more reliable way to ensure that the payment and order are synced up before I finalize the order on my side.
Has anyone else run into a similar issue when integrating Square for food ordering systems? Is there a recommended approach for handling the webhook timing problem, or maybe a specific API pattern I should be using to ensure that the payment and order objects are always properly linked? I’d really appreciate any insights or best practices from other developers who’ve worked on Square-powered ordering websites. SOrry for the long post