You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
docuseal/app/jobs/send_form_viewed_webhook_re...

29 lines
972 B

# frozen_string_literal: true
class SendFormViewedWebhookRequestJob < ApplicationJob
USER_AGENT = 'DocuSeal.co Webhook'
NotSuccessStatus = Class.new(StandardError)
def perform(submitter)
config = Accounts.load_webhook_configs(submitter.submission.account)
return if config.blank? || config.value.blank?
ActiveStorage::Current.url_options = Docuseal.default_url_options
resp = Faraday.post(config.value,
{
event_type: 'form.viewed',
timestamp: Time.current,
data: Submitters::SerializeForWebhook.call(submitter)
}.to_json,
'Content-Type' => 'application/json',
'User-Agent' => USER_AGENT)
if resp.status.to_i >= 400 && (!Docuseal.multitenant? || submitter.account.account_configs.exists?(key: :plan))
raise NotSuccessStatus, resp.status.to_s
end
end
end