Class: SpreeDoordash::WebhookEvent

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree_doordash/webhook_event.rb

Overview

Idempotency + audit log for inbound DoorDash webhook notifications.

Unlike SpreeSquare::WebhookEvent, there's no single event_id in the payload to key off — the unique index instead covers (external_delivery_id, event_name, payload_digest), see the migration for why each piece is needed. That's what makes DoorDash's documented up-to-3x redelivery-on-non-200 safe to process without duplicating side effects.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.digest(raw_body) ⇒ Object



24
25
26
# File 'app/models/spree_doordash/webhook_event.rb', line 24

def self.digest(raw_body)
  Digest::SHA256.hexdigest(raw_body)
end

Instance Method Details

#mark_failed!(error) ⇒ Object



32
33
34
# File 'app/models/spree_doordash/webhook_event.rb', line 32

def mark_failed!(error)
  update!(status: 'failed', processed_at: Time.current, error_message: error.to_s.truncate(1000))
end

#mark_processed!Object



28
29
30
# File 'app/models/spree_doordash/webhook_event.rb', line 28

def mark_processed!
  update!(status: 'processed', processed_at: Time.current)
end