Skip to content

Commit ce63c76

Browse files
updated example (#58)
1 parent 01d0f58 commit ce63c76

File tree

2 files changed

+85
-79
lines changed

2 files changed

+85
-79
lines changed

app/controllers/e_sign/eg030_brands_apply_to_template_controller.rb

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,48 @@ def get
1313
accounts_api = create_account_api(args)
1414
brand_lists = accounts_api.list_brands(args[:account_id], options = DocuSign_eSign::ListBrandsOptions.default)
1515
@brand_names = brand_lists.brands
16-
# get the template lists
17-
template_api = create_template_api(args)
18-
template_lists = template_api.list_templates(args[:account_id], options = DocuSign_eSign::ListTemplatesOptions.default)
19-
@templates = template_lists.envelope_templates
2016
super
2117
end
2218

2319
def create
24-
begin
25-
envelope_args = {
26-
signer_email: param_gsub(params[:signerEmail]),
27-
signer_name: param_gsub(params[:signerName]),
28-
cc_email: param_gsub(params[:ccEmail]),
29-
cc_name: param_gsub(params[:ccName]),
30-
brand_id: params[:brands],
31-
template_id: params[:templates],
32-
status: 'sent'
33-
34-
}
35-
args = {
36-
account_id: session['ds_account_id'],
37-
base_path: session['ds_base_path'],
38-
access_token: session['ds_access_token'],
39-
envelope_args: envelope_args
40-
}
20+
template_id = session[:template_id]
4121

42-
results = ESign::Eg030BrandsApplyToTemplateService.new(args).worker
43-
session[:envelope_id] = results.envelope_id
22+
if template_id
23+
begin
24+
envelope_args = {
25+
signer_email: param_gsub(params[:signerEmail]),
26+
signer_name: param_gsub(params[:signerName]),
27+
cc_email: param_gsub(params[:ccEmail]),
28+
cc_name: param_gsub(params[:ccName]),
29+
brand_id: params[:brands],
30+
template_id: template_id,
31+
status: 'sent'
4432

45-
# Step 4. a) Call the eSignature API
46-
# b) Display the JSON response
47-
# brand_id = results.brands[0].brand_id
48-
@title = 'Applying a brand to an envelope using a template'
49-
@h1 = 'Applying a brand to an envelope using a template'
50-
@message = "The envelope has been created and sent!<br/>Envelope ID #{results.envelope_id}."
51-
@json = results.to_json.to_json
52-
render 'ds_common/example_done'
33+
}
34+
args = {
35+
account_id: session['ds_account_id'],
36+
base_path: session['ds_base_path'],
37+
access_token: session['ds_access_token'],
38+
envelope_args: envelope_args
39+
}
5340

54-
rescue DocuSign_eSign::ApiError => e
55-
handle_error(e)
41+
results = ESign::Eg030BrandsApplyToTemplateService.new(args).worker
42+
session[:envelope_id] = results.envelope_id
43+
44+
# Step 4. a) Call the eSignature API
45+
# b) Display the JSON response
46+
# brand_id = results.brands[0].brand_id
47+
@title = 'Applying a brand to an envelope using a template'
48+
@h1 = 'Applying a brand to an envelope using a template'
49+
@message = "The envelope has been created and sent!<br/>Envelope ID #{results.envelope_id}."
50+
@json = results.to_json.to_json
51+
render 'ds_common/example_done'
52+
rescue DocuSign_eSign::ApiError => e
53+
handle_error(e)
54+
end
55+
elsif !template_id
56+
@title = 'Use embedded signing from template and extra doc'
57+
@template_ok = false
5658
end
5759
end
5860
end
Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
<h4>30. Applying a brand to an envelope using a template</a></h4>
1+
<h4>30. Applying a brand to an envelope using a template</h4>
22

3-
<p>
4-
This code example demonstrates how to apply a brand to a template
5-
</p>
3+
<% if @template_ok %>
4+
<p>
5+
This code example demonstrates how to apply a brand to a template
6+
</p>
7+
<% end %>
68

79
<p>API method used:
810
<a target='_blank' href="https://developers.docusign.com/docs/esign-rest-api/reference/envelopes/envelopes/create/">Envelopes::create</a>.
@@ -12,45 +14,47 @@
1214
View source file <a target="_blank" href="<%= @source_url %>"><%= @source_file %></a> on GitHub.
1315
</p>
1416

15-
<form class="eg" action="" method="post" data-busy="form">
16-
<div class="form-group">
17-
<label for="signerEmail">Signer Email</label>
18-
<input type="email" class="form-control" id="signerEmail" name="signerEmail"
19-
aria-describedby="emailHelp" placeholder="pat@example.com" required
20-
value="<%= @config.signer_email %>">
21-
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
22-
</div>
23-
<div class="form-group">
24-
<label for="signerName">Signer Name</label>
25-
<input type="text" class="form-control" id="signerName" placeholder="Pat Johnson" name="signerName"
26-
value="<%= @config.signer_name %>" required>
27-
</div>
28-
<div class="form-group">
29-
<label for="ccEmail">CC Email</label>
30-
<input type="email" class="form-control" id="ccEmail" name="ccEmail"
31-
aria-describedby="emailHelp" placeholder="pat@example.com" required>
32-
<small id="emailHelp" class="form-text text-muted">The email for the cc recipient must be different from the signer's email.</small>
33-
</div>
34-
<div class="form-group">
35-
<label for="ccName">CC Name</label>
36-
<input type="text" class="form-control" id="ccName" placeholder="Pat Johnson" name="ccName"
37-
required>
38-
</div>
39-
<div class="form-group">
40-
<label for="templates">Envelope template</label>
41-
<select id="templates" name="templates" class="form-control">
42-
<% @templates.each do |t| %>
43-
<option value="<%= t.template_id %>" selected><%= t.name %></option>
44-
<% end %>
45-
</select>
46-
</div>
47-
<div class="form-group">
48-
<label for="brands">Brand</label>
49-
<select id="brands" name="brands" class="form-control">
50-
<% @brand_names.each do |b| %>
51-
<option value="<%= b.brand_id %>" selected><%= b.brand_name %></option>
52-
<% end %>
53-
</select>
54-
</div>
55-
<button type="submit" class="btn btn-docu">Submit</button>
56-
</form>
17+
<% if @template_ok %>
18+
<form class="eg" action="" method="post" data-busy="form">
19+
<div class="form-group">
20+
<label for="signerEmail">Signer Email</label>
21+
<input type="email" class="form-control" id="signerEmail" name="signerEmail"
22+
aria-describedby="emailHelp" placeholder="pat@example.com" required
23+
value="<%= @config.signer_email %>">
24+
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
25+
</div>
26+
<div class="form-group">
27+
<label for="signerName">Signer Name</label>
28+
<input type="text" class="form-control" id="signerName" placeholder="Pat Johnson" name="signerName"
29+
value="<%= @config.signer_name %>" required>
30+
</div>
31+
<div class="form-group">
32+
<label for="ccEmail">CC Email</label>
33+
<input type="email" class="form-control" id="ccEmail" name="ccEmail"
34+
aria-describedby="emailHelp" placeholder="pat@example.com" required>
35+
<small id="emailHelp" class="form-text text-muted">The email for the cc recipient must be different from the signer's email.</small>
36+
</div>
37+
<div class="form-group">
38+
<label for="ccName">CC Name</label>
39+
<input type="text" class="form-control" id="ccName" placeholder="Pat Johnson" name="ccName"
40+
required>
41+
</div>
42+
<div class="form-group">
43+
<label for="brands">Brand</label>
44+
<select id="brands" name="brands" class="form-control">
45+
<% @brand_names.each do |b| %>
46+
<option value="<%= b.brand_id %>" selected><%= b.brand_name %></option>
47+
<% end %>
48+
</select>
49+
</div>
50+
<button type="submit" class="btn btn-docu">Submit</button>
51+
</form>
52+
53+
<% else %>
54+
<p>Problem: please first create the template using <a href="eg008">example 8.</a> <br/>
55+
Thank you.</p>
56+
57+
<form class="eg" action="eg008" method="get">
58+
<button type="submit" class="btn btn-docu">Continue</button>
59+
</form>
60+
<% end %>

0 commit comments

Comments
 (0)