When adding support for events in Element Builder, it is necessary to format the information the provider sends in the webhook into the format the Cloud Elements event framework is expecting.
Here is an example of an event hook that can be used when the provider makes a GET request to the element instance event URL with information about the event passed in query parameters instead of a body. Specifically, the object type (e.g. customer or account), the action and the object ID are passed in. Note that the event date is generated in the event hook.
var formattedEvents = []; var eventObj = {}; eventObj.event_date = new Date().toISOString(); eventObj.event_object_id = events["id"]; eventObj.event_type = events["action"].toUpperCase(); eventObj.event_object_type = events["object"]; formattedEvents.push(eventObj); done({ "events": formattedEvents });