Skip to content

Commit 0305ff0

Browse files
add notary example
1 parent ff3b682 commit 0305ff0

File tree

8 files changed

+212
-0
lines changed

8 files changed

+212
-0
lines changed

app/assets/javascripts/search.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const DS_SEARCH = (function () {
77
ADMIN: "admin",
88
CONNECT: "connect",
99
WEBFORMS: "webforms",
10+
NOTARY: "notary"
1011
}
1112

1213
const processJSONData = function () {
@@ -145,6 +146,8 @@ const DS_SEARCH = (function () {
145146
return "cneg";
146147
case API_TYPES.WEBFORMS:
147148
return "weg";
149+
case API_TYPES.NOTARY:
150+
return "neg";
148151
}
149152
}
150153

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../../services/utils'
4+
5+
class Notary::Neg004SendWithThirdPartyNotaryController < EgController
6+
before_action -> { check_auth('Notary') }
7+
before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 4, 'Notary') }
8+
9+
def create
10+
envelope_args = {
11+
signer_email: param_gsub(params['signerEmail']),
12+
signer_name: param_gsub(params['signerName']),
13+
doc_pdf: File.join('data', Rails.application.config.doc_pdf)
14+
}
15+
args = {
16+
account_id: session['ds_account_id'],
17+
base_path: session['ds_base_path'],
18+
access_token: session['ds_access_token'],
19+
envelope_args: envelope_args
20+
}
21+
results = Notary::Eg004SendWithThirdPartyNotaryService.new(args).worker
22+
@title = @example['ExampleName']
23+
@message = format_string(@example['ResultsPageText'], results['envelope_id'])
24+
render 'ds_common/example_done'
25+
rescue DocuSign_eSign::ApiError => e
26+
handle_error(e)
27+
end
28+
end

app/services/jwt_auth/jwt_creator.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def self.consent_url(state, api)
1818
scope = 'signature impersonation click.manage click.send' if api == 'Click'
1919
scope = 'signature impersonation organization_read group_read permission_read user_read user_write account_read domain_read identity_provider_read user_data_redact asset_group_account_read asset_group_account_clone_write asset_group_account_clone_read organization_sub_account_write organization_sub_account_read' if api == 'Admin'
2020
scope = 'signature webforms_read webforms_instance_read webforms_instance_write' if api == 'WebForms'
21+
scope = 'signature organization_read notary_read notary_write' if api == 'Notary'
2122

2223
base_uri = "#{Rails.configuration.authorization_server}/oauth/auth"
2324
response_type = 'code'
@@ -50,6 +51,10 @@ def initialize(session)
5051
scope = 'signature webforms_read webforms_instance_read webforms_instance_write'
5152
@client_module = DocuSign_WebForms
5253
end
54+
if session[:api] == 'Notary'
55+
scope = 'signature organization_read notary_read notary_write'
56+
@client_module = DocuSign_eSign
57+
end
5358

5459
@scope = scope
5560
@api_client = create_initial_api_client(host: Rails.configuration.aud, client_module: @client_module, debugging: false)
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# frozen_string_literal: true
2+
3+
class Notary::Eg004SendWithThirdPartyNotaryService
4+
attr_reader :args
5+
6+
include ApiCreator
7+
8+
def initialize(args)
9+
@args = args
10+
end
11+
12+
#ds-snippet-start:Notary4Step3
13+
def worker
14+
# Create the envelope request object
15+
envelope_definition = make_envelope args[:envelope_args]
16+
# Call Envelopes::create API method
17+
# Exceptions will be caught by the calling function
18+
envelope_api = create_envelope_api(args)
19+
20+
results = envelope_api.create_envelope args[:account_id], envelope_definition
21+
envelope_id = results.envelope_id
22+
{ 'envelope_id' => envelope_id }
23+
end
24+
#ds-snippet-end:Notary4Step3
25+
26+
private
27+
28+
#ds-snippet-start:Notary4Step2
29+
def make_envelope(envelope_args)
30+
# document 1 (HTML) has tag **signature_1**
31+
# document 2 (DOCX) has tag /sn1/
32+
# document 3 (PDF) has tag /sn1/
33+
#
34+
# The envelope has two recipients:
35+
# recipient 1 - signer
36+
# recipient 2 - cc
37+
# The envelope will be sent first to the signer.
38+
# After it is signed, a copy is sent to the cc person
39+
40+
# Create the envelope definition
41+
envelope_definition = DocuSign_eSign::EnvelopeDefinition.new
42+
43+
envelope_definition.email_subject = 'Please sign this document set'
44+
45+
# Add the document
46+
doc_b64 = Base64.encode64(File.binread(envelope_args[:doc_pdf]))
47+
48+
# Create the document model
49+
document = DocuSign_eSign::Document.new(
50+
# Create the Docusign document object
51+
documentBase64: doc_b64,
52+
name: 'Order acknowledgement', # Can be different from actual file name
53+
fileExtension: 'html', # Many different document types are accepted
54+
documentId: '1' # A label used to reference the doc
55+
)
56+
57+
# The order in the docs array determines the order in the envelope
58+
envelope_definition.documents = [document]
59+
60+
# Create the signer recipient model
61+
signer = DocuSign_eSign::Signer.new
62+
signer.email = envelope_args[:signer_email]
63+
signer.name = envelope_args[:signer_name]
64+
signer.recipient_id = '1'
65+
signer.routing_order = '1'
66+
## routingOrder (lower means earlier) determines the order of deliveries
67+
# to the recipients. Parallel routing order is supported by using the
68+
# same integer as the order for two or more recipients
69+
70+
# Create signHere fields (also known as tabs) on the documents
71+
# We're using anchor (autoPlace) positioning
72+
#
73+
# The Docusign platform searches throughout your envelope's documents for matching
74+
# anchor strings. So the sign_here_2 tab will be used in both document 2 and 3
75+
# since they use the same anchor string for their "signer 1" tabs.
76+
sign_here = DocuSign_eSign::SignHere.new(
77+
anchorString: '/sn1/',
78+
anchorYOffset: '10',
79+
anchorUnits: 'pixels',
80+
anchorXOffset: '20'
81+
)
82+
83+
# Add the tabs model (including the sign_here tabs) to the signer
84+
# The Tabs object takes arrays of the different field/tab types
85+
signer_tab = DocuSign_eSign::Tabs.new({
86+
signHereTabs: [sign_here]
87+
})
88+
89+
signer.tabs = signer_tab
90+
91+
notary_seal = DocuSign_eSign::NotarySeal.new(
92+
xPosition: '300',
93+
yPosition: '235',
94+
documentId: '1',
95+
pageNumber: '1',
96+
)
97+
98+
notary_sign_here = DocuSign_eSign::SignHere.new(
99+
xPosition: '300',
100+
yPosition: '150',
101+
documentId: '1',
102+
pageNumber: '1',
103+
)
104+
105+
notary_tabs = DocuSign_eSign::Tabs.new(
106+
signHereTabs: [notary_sign_here],
107+
notarySealTabs: [notary_seal]
108+
)
109+
110+
notary_recipient = DocuSign_eSign::NotaryRecipient.new(
111+
email: '',
112+
name: 'Notary',
113+
recipientId: '1',
114+
routingOrder: '1',
115+
tabs: notary_tabs,
116+
notaryType: 'remote',
117+
notarySourceType: 'thirdparty',
118+
notaryThirdPartyPartner: 'onenotary',
119+
recipientSignatureProviders: [
120+
{
121+
sealDocumentsWithTabsOnly: 'false',
122+
signatureProviderName: 'ds_authority_idv',
123+
signatureProviderOptions: {}
124+
}
125+
]
126+
)
127+
128+
# Add the recipients to the envelope object
129+
recipients = DocuSign_eSign::Recipients.new(
130+
signers: [signer],
131+
notary: [notary_recipient]
132+
)
133+
# Request that the envelope be sent by setting status to "sent".
134+
# To request that the envelope be created as a draft, set status to "created"
135+
envelope_definition.recipients = recipients
136+
envelope_definition.status = 'sent'
137+
envelope_definition
138+
end
139+
#ds-snippet-end:Notary4Step2
140+
end

app/views/ds_common/index.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
"cn"
5656
elsif api["Name"] == "WebForms"
5757
"w"
58+
elsif api["Name"] == "Notary"
59+
"n"
5860
else
5961
"e"
6062
end %>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<%= render('partials/example_info') %>
2+
3+
<% form_index = 0 %>
4+
<% signer_email_index = 0 %>
5+
<% signer_name_index = 1 %>
6+
7+
<form class="eg" action="" method="post" data-busy="form">
8+
<% if @example["Forms"][form_index]["FormName"] %>
9+
<%= sanitize @example["Forms"][form_index]["FormName"] %>
10+
<% end %>
11+
12+
<div class="form-group">
13+
<label for="signerEmail"><%= @example["Forms"][form_index]["Inputs"][signer_email_index]["InputName"] %></label>
14+
<input type="email" class="form-control" id="signerEmail" name="signerEmail"
15+
aria-describedby="emailHelp"
16+
placeholder="<%= @example["Forms"][form_index]["Inputs"][signer_email_index]["InputPlaceholder"] %>" required
17+
value="<%= @config.signer_email %>">
18+
<%= render('partials/email_will_not_be_shared') %>
19+
</div>
20+
<div class="form-group">
21+
<label for="signerName"><%= @example["Forms"][form_index]["Inputs"][signer_name_index]["InputName"] %></label>
22+
<input type="text" class="form-control" id="signerName"
23+
placeholder="<%= @example["Forms"][form_index]["Inputs"][signer_name_index]["InputPlaceholder"] %>" name="signerName"
24+
value="<%= @config.signer_name %>" required>
25+
</div>
26+
<%= render('partials/submit_button') %>
27+
</form>

config/initializers/omniauth.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
strategy.options[:authorize_params].scope = 'signature organization_read group_read permission_read user_read user_write account_read domain_read identity_provider_read user_data_redact asset_group_account_read asset_group_account_clone_write asset_group_account_clone_read organization_sub_account_write organization_sub_account_read'
5555
when 'WebForms'
5656
strategy.options[:authorize_params].scope = 'signature webforms_read webforms_instance_read webforms_instance_write'
57+
when 'Notary'
58+
strategy.options[:authorize_params].scope = 'signature organization_read notary_read notary_write'
5759
end
5860
}
5961
end

config/routes.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@
245245
post 'weg001webForm' => 'weg001_create_instance#create_web_form_instance'
246246
end
247247

248+
scope module: 'notary' do
249+
get 'neg004' => 'neg004_send_with_third_party_notary#get'
250+
post 'neg004' => 'neg004_send_with_third_party_notary#create'
251+
end
252+
248253
root 'ds_common#index'
249254

250255
# Login starts with POST'ing to: /auth/docusign

0 commit comments

Comments
 (0)