Class: Api::Esignatures

Inherits:
BaseService show all
Includes:
Singleton
Defined in:
app/services/api/esignatures.rb

Overview

Service object: esignatures.

Instance Attribute Summary collapse

Attributes inherited from BaseService

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseService

#log_debug, #log_error, #log_info, #log_warning, #logger, #process, #tagged_logger

Constructor Details

#initializeEsignatures

Returns a new instance of Esignatures.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/api/esignatures.rb', line 9

def initialize
  # SSL verification is gated behind an explicit credentials flag so the
  # default is secure (verify:true) and the unsafe path is opt-in. The
  # legacy contract-vendor endpoint had intermittent cert-chain issues
  # historically; if that surfaces again in production, set
  # esignatures.skip_ssl_verify=true in encrypted credentials. Otherwise
  # we get full TLS verification.
  skip_verify = Heatwave::Configuration.fetch(:esignatures, :skip_ssl_verify) == true
  @client = Faraday.new(
    ssl: { verify: !skip_verify },
    request: { open_timeout: 5, timeout: 30 }
  ) do |f|
    f.adapter Faraday.default_adapter
  end
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'app/services/api/esignatures.rb', line 7

def client
  @client
end

Class Method Details

.clientObject



25
26
27
# File 'app/services/api/esignatures.rb', line 25

def self.client
  instance.client
end

.contract_status(contract_id) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'app/services/api/esignatures.rb', line 62

def self.contract_status(contract_id)
  res = retrieve_contract(contract_id)
  contract = JSON.parse(res.body).deep_symbolize_keys[:data]
  if contract.present?
    contract[:status]
  else
    'not found'
  end
end

.hostnameObject



29
30
31
# File 'app/services/api/esignatures.rb', line 29

def self.hostname
  Heatwave::Configuration.fetch(:esignatures, :hostname)
end

.new_contract(options) ⇒ Faraday::Response

Returns the API response.

Parameters:

  • options (Hash)

    contract payload sent to the eSignatures API

Options Hash (options):

  • template_id (Integer)

    eSignatures template id

  • test (Boolean)

    create a test contract

  • signers (Array<Hash>)

    signer entries (name, email, phone, redirect_url)

  • custom_branding (Hash)

    branding options (company_name, logo_url)

  • emails (Hash)

    email customization (signature_request_subject)

  • placeholder_fields (Array<Hash>)

    placeholder fields (api_key, value)

Returns:

  • (Faraday::Response)

    the API response



49
50
51
52
# File 'app/services/api/esignatures.rb', line 49

def self.new_contract(options)
  client.post("#{hostname}/contracts?token=#{token}", options.to_json,
              'Content-Type' => 'application/json')
end

.retrieve_contract(contract_id) ⇒ Object



54
55
56
# File 'app/services/api/esignatures.rb', line 54

def self.retrieve_contract(contract_id)
  client.get("#{hostname}/contracts/#{contract_id}?token=#{token}")
end

.templatesObject



37
38
39
# File 'app/services/api/esignatures.rb', line 37

def self.templates
  client.get("#{hostname}/templates/?token=#{token}")
end

.tokenObject



33
34
35
# File 'app/services/api/esignatures.rb', line 33

def self.token
  Heatwave::Configuration.fetch(:esignatures, :token)
end

.withdraw_contract(contract_id) ⇒ Object



58
59
60
# File 'app/services/api/esignatures.rb', line 58

def self.withdraw_contract(contract_id)
  client.post("#{hostname}/contracts/#{contract_id}/withdraw/?token=#{token}")
end