Mutiple webhooks called payments.updated

Hello Team,

We have noticed that our server is receiving multiple simultaneous requests to the webhook endpoint configured for payment.updated, payment.created and order.updated events in the Checkout API. These webhook events are triggered after a payment is completed via the Square Payment Link.

Our primary concern is with the payment.updated event, as we rely on it to:
:white_check_mark: Verify if the payment was successful.
:white_check_mark: Update our database accordingly.
:white_check_mark: Send a payment confirmation notification to the customer.

However, since the same webhook event is triggered multiple times, customers will receive duplicate notifications, which is incorrect.

What is the recommended approach to handle these duplicate webhook events effectively?

Thanks

:waving_hand: I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:

Additional Documentation

Use Customer Webhooks
Use Webhooks to Integrate with a Payroll System
Handle Bookings Webhook Events

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.

The Square webhook system is designed to ensure that your application receives all the necessary notifications. However, it’s possible that your application might receive duplicate notifications for the same event. This can happen due to network issues or if your server doesn’t respond quickly enough to the webhook notification.

To handle these duplicate webhook events effectively, your application should be idempotent. This means that it should be able to process the same webhook notification multiple times without any negative effects.

One way to achieve this is by storing the event IDs of the webhook notifications that your application has already processed. When your application receives a webhook notification, it should check if the event ID is already stored. If it is, your application can ignore the notification. If it’s not, your application should process the notification and store the event ID.

This way, even if your application receives duplicate webhook notifications, it will only process each unique notification once, preventing any duplicate actions such as sending multiple notifications to the customer.

This answer was reviewed by @Bryan-Square.

Since Square’s webhook system assigns a unique Event ID to each notification for the same payment, storing the Event ID in the database serves no purpose in preventing duplicate processing.

If your function started a lookup of one payment_id or order_id and receives another updated event you can ignore that particular event till you get the confirmation you need. This isn’t uncommon since there are asynchronous functions on the Square side that update the order or payment for things like tax calculations or fee calculations. :slight_smile: