Payment webhooks with multiple "payment link" items

Hi,

I’m struggling to get payment webhooks to work as expected with 2 items. Let’s call it:

Coke, has a payment.updated webhook called coke_webhook
Pepsi, has a payment.updated webhook called pepsi_webhook

I have coke_app which is supposed to listen to Coke payments only. I mean, it only has a route for coke_webhook.
I have pepsi app which is supposed to listen to Pepsi payments only. I mean, it only has a route for pepsi_webhook.

The problem i’m having is that when somebody buys a pepsi, the coke app also gets a notification about it. (And vice versa.)

I’ve checked that the URL’s for the 2 different webhooks (coke_webhook and pepsi_webhook) are different and correct in the Square Developer Dashboard.

:wave: 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 Webhooks to Integrate with a Payroll System
Handle Inventory Event Notifications
Use Customer Webhooks

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.

In a nutshell, what I’m asking is, “How to set up a webhook for the sale of one specific item?”

The behavior you’re experiencing is expected based on the current design of Square’s webhook system. The Payments API webhooks are not item-specific, meaning they are triggered whenever a payment event occurs, regardless of the specific item involved in the transaction.

When a payment is updated, a payment.updated webhook event is triggered and sent to all registered webhook endpoints, regardless of the specific item that was part of the payment. This is why both your ‘coke_app’ and ‘pepsi_app’ are receiving notifications for all payment events.

If you want to differentiate the handling of these events based on the item purchased, you would need to implement this logic in your application code. When your application receives a webhook notification, it can retrieve the payment details, inspect the line items involved in the payment, and then take appropriate action based on whether the payment involves a ‘Coke’ or ‘Pepsi’.

This answer was reviewed by @Bryan-Square.