Class: ReductoAI::Webhooks::Verifier

Inherits:
Object
  • Object
show all
Defined in:
lib/reducto_ai/webhooks/verifier.rb

Class Method Summary collapse

Class Method Details

.verify!(payload:, headers:, secret: nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/reducto_ai/webhooks/verifier.rb', line 9

def verify!(payload:, headers:, secret: nil)
  normalized_headers = normalize_headers(headers)
  resolved_secret = resolve_secret(secret, normalized_headers)

  raise WebhookVerificationError, "webhook secret is required" if resolved_secret.to_s.strip.empty?

  build_webhook(resolved_secret).verify(payload.to_s, normalized_headers)
rescue Svix::WebhookVerificationError => e
  raise WebhookVerificationError, e.message
end