question

John Paul Hayes avatar image
John Paul Hayes asked hammer answered

Understanding the webhook payload

Hi Folks,

I was wondering what is the best practice for using the data that arrives in the webhook payload.

Below is a sample of what I receive when an order is created (no payment yet). As you can see from this, there is one create event and two update. Why are there two updates after the create? What use are they?

{ "merchants": { "XXXXX": [ { "type": "CREATE", "ts": 1453829584344, "objectId": "O:ZZZZZZZZZZ" }, { "type": "UPDATE", "ts": 1453829584765, "objectId": "O:ZZZZZZZZZZ" }, { "type": "UPDATE", "ts": 1453829585037, "objectId": "O:ZZZZZZZZZZ" } ] }, "appId": "BBBBBBBBB" }

When a payment is received the following is received. I understand that the same order id can be tracked, but again, why the updates to the order before the payment event is created?

{ "merchants": { "XXXXX": [ { "type": "UPDATE", "ts": 1453830144608, "objectId": "O:ZZZZZZZZZZ" }, { "type": "UPDATE", "ts": 1453830145072, "objectId": "O:ZZZZZZZZZZ" }, { "type": "CREATE", "ts": 1453830145072, "objectId": "P:EVRSKSBHTGQ6M" } ] }, "appId": "1X2NPBGXKPK18" }

Lastly, what would be the best way to store these orders and payments relationally in a database?

--

Thanks in advance!

JP

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

hammer avatar image
hammer answered

Working backwards on this might be best.

See the api docs for the structure of an order and payment. The primary way to store the data relationally would be to maintain the relationship of merchant(XXXXX) -> orders(ZZZZZZZZZZ) -> payments(EVRSKSBHTGQ6M). Depending on what you use of the data is, It might make sense to store these ids and use the Clover REST service for data access, or it might make sense to store some or all of the detail associated with them. It is really a matter of your use case. However storing the data has inherent risks with synchronization that would need to be addressed.

In the case of the multiple updates, it is simply a case of a component framework that has a separation of concerns. One component does not necessarily know the other has done an update, and the webhook infrastructure does not collapse the duplicates, as the timestamps could have significance in some listening sytems. In this case, you can get the details for the order one time, no need to call the REST API twice for the same order id.

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community