Class: EasydocformsWebhooksController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
lib/generators/easydocforms/webhook/templates/webhooks_controller.rb

Overview

Receives EasyDocForms webhook deliveries. Every delivery is verified against the subscription's signing secret before it is trusted.

Webhook payloads are PHI-minimized by design: they carry ids and retrieve URLs, never patient answers. Fetch answers server-side with your API key.

Instance Method Summary collapse

Instance Method Details

#createObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/generators/easydocforms/webhook/templates/webhooks_controller.rb', line 11

def create
  event = EasyDocForms::Webhook.construct_event(
    payload: request.body.read,
    header: request.headers[EasyDocForms::Webhook::HEADER],
    secret: Rails.application.credentials.dig(:easydocforms, :webhook_secret)
  )

  case event[:event]
  when "import.completed"
    # event[:data] => { import_id:, template_id:, page_count:, field_count:, review_required: }
  when "import.failed"
    # event[:data] => { import_id:, error: }
  when "submission.created"
    # event[:data] => { submission_id:, template_id:, fill_link_id:, external_ref:, retrieve_url: }
  when "submission.pdf_ready"
    # event[:data] => { submission_id:, template_id:, external_ref:, pdf_url: }
  end

  head :ok # respond 2xx fast; deliveries are one-shot
rescue EasyDocForms::SignatureVerificationError
  head :bad_request
end