Skip to content

Commit 4aa0a41

Browse files
Embed elastic signing agreement example
2 parents fe8ef38 + fc85943 commit 4aa0a41

File tree

15 files changed

+261
-10
lines changed

15 files changed

+261
-10
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ group :test do
6868
end
6969

7070
gem 'docusign_admin', '~> 1.1.0'
71-
gem 'docusign_click', '~> 1.0.0'
71+
gem 'docusign_click', '~> 1.2.2'
7272
gem 'docusign_esign', '~> 3.19.0'
7373
gem 'docusign_monitor', '~> 1.1.0'
7474
gem 'docusign_rooms', '~> 1.2.0.rc1'

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ GEM
103103
json (~> 2.1, >= 2.1.0)
104104
jwt (~> 2.2, >= 2.2.1)
105105
typhoeus (~> 1.0, >= 1.0.1)
106-
docusign_click (1.0.0)
106+
docusign_click (1.2.2)
107107
addressable (~> 2.7, >= 2.7.0)
108108
json (~> 2.1, >= 2.1.0)
109109
jwt (~> 2.2, >= 2.2.1)
@@ -322,7 +322,7 @@ DEPENDENCIES
322322
chromedriver-helper (~> 2.1.1)
323323
coffee-rails (~> 5.0.0)
324324
docusign_admin (~> 1.1.0)
325-
docusign_click (~> 1.0.0)
325+
docusign_click (~> 1.2.0)
326326
docusign_esign (~> 3.19.0)
327327
docusign_monitor (~> 1.1.0)
328328
docusign_rooms (~> 1.2.0.rc1)

app/controllers/clickwrap/eg002_activate_clickwrap_controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def create
77
account_id: session[:ds_account_id],
88
base_path: session[:ds_base_path],
99
access_token: session[:ds_access_token],
10-
clickwrap_id: session[:clickwrap_id]
10+
clickwrap_id: params[:clickwrapId]
1111
}
1212

1313
Clickwrap::Eg002ActivateClickwrapService.new(args).worker
@@ -16,4 +16,8 @@ def create
1616
@message = @example['ResultsPageText']
1717
render 'ds_common/example_done'
1818
end
19+
20+
def get
21+
@clickwraps = Clickwrap::Eg002ActivateClickwrapService.new(session).get_inactive_clickwraps
22+
end
1923
end
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
class Clickwrap::Eg006EmbedClickwrapController < EgController
2+
before_action :check_auth
3+
before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 6) }
4+
5+
def create
6+
begin
7+
args = {
8+
account_id: session[:ds_account_id],
9+
base_path: session[:ds_base_path],
10+
access_token: session[:ds_access_token],
11+
clickwrap_id: params[:clickwrapId],
12+
full_name: params[:fullName],
13+
email: params[:email],
14+
company: params[:company],
15+
title: params[:title],
16+
date: params[:date]
17+
}
18+
19+
results = Clickwrap::Eg006EmbedClickwrapService.new(args).worker
20+
21+
if results == nil
22+
@error_code = '200'
23+
@error_message = 'The email address was already used to agree to this elastic template. Provide a different email address if you want to view the agreement and agree to it.'
24+
render 'ds_common/error'
25+
else
26+
@title = @example['ExampleName']
27+
@message = format_string(@example['ResultsPageText'])
28+
@agreementUrl = results["agreementUrl"]
29+
render 'clickwrap/eg006_embed_clickwrap/results'
30+
end
31+
rescue DocuSign_Click::ApiError => e
32+
handle_error(e)
33+
end
34+
end
35+
36+
def get
37+
@clickwraps = Clickwrap::Eg006EmbedClickwrapService.new(session).get_active_clickwraps
38+
@inactive_clickwraps = Clickwrap::Eg006EmbedClickwrapService.new(session).get_inactive_clickwraps
39+
end
40+
end

app/services/clickwrap/eg002_activate_clickwrap_service.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,24 @@ def worker
2828
clickwrap_request
2929
)
3030
end
31+
32+
def get_inactive_clickwraps
33+
configuration = DocuSign_Click::Configuration.new
34+
configuration.host = args[:ds_base_path]
35+
36+
api_client = DocuSign_Click::ApiClient.new configuration
37+
api_client.set_default_header('Authorization', "Bearer #{args[:ds_access_token]}")
38+
39+
accounts_api = DocuSign_Click::AccountsApi.new(api_client)
40+
41+
options = DocuSign_Click::GetClickwrapsOptions.new
42+
options.status = 'inactive'
43+
44+
results = accounts_api.get_clickwraps(
45+
args[:ds_account_id],
46+
options
47+
)
48+
puts results.as_json['clickwraps']
49+
results.as_json['clickwraps']
50+
end
3151
end
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# frozen_string_literal: true
2+
3+
class Clickwrap::Eg006EmbedClickwrapService
4+
attr_reader :args
5+
6+
def initialize(args)
7+
@args = args
8+
end
9+
10+
def worker
11+
# Step 2. Construct your API headers
12+
configuration = DocuSign_Click::Configuration.new
13+
configuration.host = args[:base_path]
14+
15+
api_client = DocuSign_Click::ApiClient.new configuration
16+
api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
17+
api_client.config.debugging = true;
18+
19+
# document_data = DocuSign_Click::DocumentData.new({
20+
# full_name: args[:full_name],
21+
# email: args[:email],
22+
# company: args[:company],
23+
# title: args[:title],
24+
# date: args[:date]
25+
# })
26+
27+
document_data = {
28+
"fullName" => args[:full_name],
29+
"email" => args[:email],
30+
"company" => args[:company],
31+
"title" => args[:title],
32+
"date" => args[:date]
33+
}
34+
35+
36+
userAgreementRequest = DocuSign_Click::UserAgreementRequest.new({
37+
clientUserId: args[:email],
38+
documentData: document_data
39+
})
40+
41+
accounts_api = DocuSign_Click::AccountsApi.new(api_client)
42+
43+
response = accounts_api.create_has_agreed(args[:account_id], args[:clickwrap_id], userAgreementRequest)
44+
45+
response.as_json
46+
end
47+
48+
def get_active_clickwraps
49+
configuration = DocuSign_Click::Configuration.new
50+
configuration.host = args[:ds_base_path]
51+
52+
api_client = DocuSign_Click::ApiClient.new configuration
53+
api_client.set_default_header('Authorization', "Bearer #{args[:ds_access_token]}")
54+
55+
accounts_api = DocuSign_Click::AccountsApi.new(api_client)
56+
57+
options = DocuSign_Click::GetClickwrapsOptions.new
58+
options.status = 'active'
59+
60+
results = accounts_api.get_clickwraps(
61+
args[:ds_account_id],
62+
options
63+
)
64+
puts results.as_json['clickwraps']
65+
results.as_json['clickwraps']
66+
end
67+
68+
def get_inactive_clickwraps
69+
configuration = DocuSign_Click::Configuration.new
70+
configuration.host = args[:ds_base_path]
71+
72+
api_client = DocuSign_Click::ApiClient.new configuration
73+
api_client.set_default_header('Authorization', "Bearer #{args[:ds_access_token]}")
74+
75+
accounts_api = DocuSign_Click::AccountsApi.new(api_client)
76+
77+
options = DocuSign_Click::GetClickwrapsOptions.new
78+
options.status = 'inactive'
79+
80+
results = accounts_api.get_clickwraps(
81+
args[:ds_account_id],
82+
options
83+
)
84+
results.as_json['clickwraps']
85+
end
86+
end

app/views/admin_api/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<h2><%= group["Name"] %></h2>
2626

2727
<% group["Examples"].each { |example| %>
28-
<% if not example["SkipLanguages"] or not example["SkipLanguages"].include? "ruby" %>
28+
<% if not example["SkipForLanguages"] or not example["SkipForLanguages"].include? "ruby" %>
2929
<h4 id="<%= "example%03d" % example["ExampleNumber"] %>">
3030
<a href="<%= "eg%03d" % example["ExampleNumber"] %>">
3131
<%= example["ExampleName"] %>

app/views/clickwrap/eg002_activate_clickwrap/get.html.erb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
<%= render('partials/example_info') %>
22

33
<% redirect_to1_index = 0 %>
4+
<% clickwrap_id_index = 0 %>
5+
<% form_index = 0 %>
46

5-
<% if session[:clickwrap_id] %>
7+
<% if @clickwraps.count.positive? %>
68

79
<form class="eg" action="" method="post" data-busy="form">
810
<% if @example["Forms"][0]["FormName"] %>
911
<%= sanitize @example["Forms"][0]["FormName"] %>
1012
<% end %>
1113

14+
<div class="form-group">
15+
<label for="starting_view"><%= @example["Forms"][form_index]["Inputs"][clickwrap_id_index]["InputName"] %></label>
16+
<%= select_tag "clickwrapId", options_for_select(@clickwraps.map { |obj| [obj['clickwrapName'], obj['clickwrapId']] }), {:class => 'form-control'} %>
17+
</div>
18+
1219
<%= render('partials/submit_button') %>
1320
</form>
1421

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<%= render('partials/example_info') %>
2+
3+
<% form_index = 0 %>
4+
<% clickwrap_id_index = 0 %>
5+
<% full_name_index = 1 %>
6+
<% email_index = 2 %>
7+
<% company_index = 3 %>
8+
<% title_index = 4 %>
9+
<% date_index = 5 %>
10+
<% redirect_to1_index = 0 %>
11+
<% redirect_to2_index = 1 %>
12+
13+
<% if @clickwraps.count.positive? %>
14+
<form class="eg" action="" method="post" data-busy="form">
15+
<% if @example["Forms"][form_index]["FormName"] %>
16+
<%= sanitize @example["Forms"][form_index]["FormName"] %>
17+
<% end %>
18+
19+
<div class="form-group">
20+
<label for="starting_view"><%= @example["Forms"][form_index]["Inputs"][clickwrap_id_index]["InputName"] %></label>
21+
<%= select_tag "clickwrapId", options_for_select(@clickwraps.map { |obj| [obj['clickwrapName'], obj['clickwrapId']] }), {:class => 'form-control'} %>
22+
</div>
23+
<p>
24+
<%= sanitize @manifest["SupportingTexts"]["HelpingTexts"]["DynamicContentValue"] %>
25+
</p>
26+
<p>
27+
<%= sanitize @manifest["SupportingTexts"]["HelpingTexts"]["DynamicContentNote"] %>
28+
</p>
29+
<div class="form-group">
30+
<label for="fullName"><%= @example["Forms"][form_index]["Inputs"][full_name_index]["InputName"] %></label>
31+
<input type="text" class="form-control" id="fullName" name="fullName"
32+
placeholder="<%= @example["Forms"][form_index]["Inputs"][full_name_index]["InputPlaceholder"] %>" required />
33+
</div>
34+
<div class="form-group">
35+
<label for="email"><%= @example["Forms"][form_index]["Inputs"][email_index]["InputName"] %></label>
36+
<input type="email" class="form-control" id="email" name="email"
37+
aria-describedby="emailHelp"
38+
placeholder="<%= @example["Forms"][form_index]["Inputs"][email_index]["InputPlaceholder"] %>" required
39+
<%= render('partials/email_will_not_be_shared') %>
40+
</div>
41+
<div class="form-group">
42+
<label for="company"><%= @example["Forms"][form_index]["Inputs"][company_index]["InputName"] %></label>
43+
<input type="text" class="form-control" id="company" name="company"
44+
placeholder="<%= @example["Forms"][form_index]["Inputs"][company_index]["InputPlaceholder"] %>" required>
45+
</div>
46+
<div class="form-group">
47+
<label for="title"><%= @example["Forms"][form_index]["Inputs"][title_index]["InputName"] %></label>
48+
<input type="text" class="form-control" id="title" name="title"
49+
placeholder="<%= @example["Forms"][form_index]["Inputs"][title_index]["InputPlaceholder"] %>" required>
50+
</div>
51+
<div class="form-group">
52+
<label for="date"><%= @example["Forms"][form_index]["Inputs"][date_index]["InputName"] %></label>
53+
<input type="date" class="form-control" id="date" name="date"
54+
placeholder="<%= @example["Forms"][form_index]["Inputs"][date_index]["InputPlaceholder"] %>" required>
55+
</div>
56+
<%= render('partials/submit_button') %>
57+
</form>
58+
59+
<% elsif @inactive_clickwraps.count.positive? %>
60+
<%= sanitize format_string(@example["RedirectsToOtherCodeExamples"][redirect_to2_index]["RedirectText"], 'href="eg002"') %>
61+
<% else %>
62+
<%= sanitize format_string(@example["RedirectsToOtherCodeExamples"][redirect_to1_index]["RedirectText"], 'href="eg001"') %>
63+
<% end %>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<h2><%= @title %></h2>
2+
<% if !@message.nil? %>
3+
<p><%= @message.html_safe %></p>
4+
<% end %>
5+
6+
<% if !@agreementUrl.nil? %>
7+
<p>
8+
<%= sanitize @manifest["SupportingTexts"]["HelpingTexts"]["EmbedClickwrapURL"] %> <%= @agreementUrl.html_safe %>
9+
</p>
10+
<% end %>
11+
12+
<p id="agreementStatus">
13+
<%= sanitize @manifest["SupportingTexts"]["HelpingTexts"]["NOTAGREED"] %>
14+
</p>
15+
16+
<p><a href="/">Continue</a></p>
17+
18+
<div id="ds-terms-of-service"></div>
19+
<script src="https://stage.docusign.net/clickapi/sdk/latest/docusign-click.js"></script>
20+
<%= javascript_tag do %>
21+
docuSignClick.Clickwrap.render({
22+
agreementUrl: "<%= @agreementUrl.html_safe %>",
23+
onAgreed: function () {
24+
// Triggered if the user has just agreed
25+
document.getElementById("agreementStatus").innerHTML = "<%= sanitize @manifest["SupportingTexts"]["HelpingTexts"]["AGREED"] %>";
26+
}
27+
}, "#ds-terms-of-service");
28+
<% end %>

app/views/clickwrap/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<h2><%= group["Name"] %></h2>
2929

3030
<% group["Examples"].each { |example| %>
31-
<% if not example["SkipLanguages"] or not example["SkipLanguages"].include? "ruby" %>
31+
<% if not example["SkipForLanguages"] or not example["SkipForLanguages"].include? "ruby" %>
3232
<h4 id="<%= "example%03d" % example["ExampleNumber"] %>">
3333
<a href="<%= "eg%03d" % example["ExampleNumber"] %>">
3434
<%= example["ExampleName"] %>

app/views/ds_common/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<h2><%= group["Name"] %></h2>
3535

3636
<% group["Examples"].each { |example| %>
37-
<% if not example["SkipLanguages"] or not example["SkipLanguages"].include? "ruby" %>
37+
<% if not example["SkipForLanguages"] or not example["SkipForLanguages"].include? "ruby" %>
3838
<% if @status_cfr && @status_cfr == "enabled" %>
3939
<% if example["CFREnabled"] == "AllAccounts" || example["CFREnabled"] == "CFROnly" %>
4040
<h4 id="<%= "example%03d" % example["ExampleNumber"] %>">

app/views/monitor_api/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<h2><%= group["Name"] %></h2>
2727

2828
<% group["Examples"].each { |example| %>
29-
<% if not example["SkipLanguages"] or not example["SkipLanguages"].include? "ruby" %>
29+
<% if not example["SkipForLanguages"] or not example["SkipForLanguages"].include? "ruby" %>
3030
<h4 id="<%= "example%03d" % example["ExampleNumber"] %>">
3131
<a href="<%= "eg%03d" % example["ExampleNumber"] %>">
3232
<%= example["ExampleName"] %>

app/views/room_api/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<h2><%= group["Name"] %></h2>
3333

3434
<% group["Examples"].each { |example| %>
35-
<% if not example["SkipLanguages"] or not example["SkipLanguages"].include? "ruby" %>
35+
<% if not example["SkipForLanguages"] or not example["SkipForLanguages"].include? "ruby" %>
3636
<h4 id="<%= "example%03d" % example["ExampleNumber"] %>">
3737
<a href="<%= "eg%03d" % example["ExampleNumber"] %>">
3838
<%= example["ExampleName"] %>

config/routes.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848

4949
get 'eg005' => 'eg005_clickwrap_responses#get'
5050
post 'eg005' => 'eg005_clickwrap_responses#create'
51+
52+
get 'eg006' => 'eg006_embed_clickwrap#get'
53+
post 'eg006' => 'eg006_embed_clickwrap#create'
5154
end
5255
end
5356
constraints ->(req) { req.session[:examples_API] == 'Monitor' } do

0 commit comments

Comments
 (0)