# frozen_string_literal: true module StrikeMe module API # Parses the WebhookEvent payload every Strike webhook POST carries — # {id, eventType, webhookVersion, data: {entityId, changes}, created, # deliverySuccess}. Deliberately does NOT carry the changed values # themselves — Strike's own docs are explicit that the event never # contains the actual data changes, only that something changed on # `entity_id`. A real value only comes from calling the matching # fetch endpoint (e.g. Invoices#find for an invoice.* event) — # trusting anything else here would mean trusting an unauthenticated # claim about money having moved. class WebhookEvent < BaseModel attribute :id attribute :eventType attribute :webhookVersion attribute :data attribute :created, :datetime attribute :deliverySuccess, :boolean alias_attribute :event_type, :eventType alias_attribute :webhook_version, :webhookVersion alias_attribute :delivery_success, :deliverySuccess def entity_id data['entityId'] || data[:entityId] end def changes data['changes'] || data[:changes] || [] end def invoice_event? event_type.to_s.start_with?('invoice.') end end end end