Hello,
I am trying to set up a webhook that will send a message every time an order is placed and completed with a payment. Right now I am using the payment.updated endpoint which works but it sends more than one message for each payment. The only difference I see in the payload is the version # and the receipt url one is a preview and one is the actual receipt. Is there a better way to get this information.
If using the payment .updated webhook what happens if someone returns part or all of the order associated with the payment. Is this payment updated again or is a new payment object created.
Thanks
Don
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
Catalog API Webhooks
Use Customer Webhooks
Use Webhooks to Integrate with a Payroll System
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.
To achieve your goal of receiving a notification when an order is placed and completed with a payment, you might consider using a combination of webhooks and API calls to ensure you capture the complete lifecycle of an order and its associated payment.
Order and Payment Completion: - You can use the payment.updated webhook to track changes to a payment, including when it is completed. However, as you’ve noticed, this webhook can trigger multiple times for the same payment due to updates in the payment object, such as changes in the version number or receipt URL. - To reduce noise, you might want to filter these events in your application logic to only act on specific changes, such as when the payment status changes to COMPLETED.
Handling Returns: - If a part or all of an order is returned, the payment.updated webhook will indeed trigger again if the payment object is updated to reflect a refund. The payment object itself is updated rather than a new payment object being created. You will see changes in fields like amount_money and refunded_money. 
So is this actually the best way to handle this? Would it be better to use the order.updated webhook. Currently I am polling the orders api endpoint for orders created since a time to get new orders. I was hoping to be able to use the webhook instead so I didn’t have to have the polling login on and to have a closer to realtime process. I guess I will give it a shot but if there are any pitfalls you see in using the order.updated hook I would like to know.
THanks
Don
So I gave the order.updates webhook a shot and it sent three messages for one order. The first one was still open which is fine and expected. the second one said completed which according to the documentation is a terminal state so at that point the payment should be completed and the order should no longer be updated. But then I got a third message also says completed and the only difference is the event id.
DO you have any insight into why an order that is already marked as completed is being updated again?
Thanks
Don