Skip to content

Commit 1795aa6

Browse files
update focused view (#183)
1 parent e747901 commit 1795aa6

3 files changed

Lines changed: 106 additions & 27 deletions

File tree

‎app/eSignature/examples/eg044_focused_view.py‎

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from datetime import datetime as dt, timezone
33
from os import path
44

5-
from docusign_esign import EnvelopesApi, RecipientViewRequest, Document, Signer, EnvelopeDefinition, SignHere, Tabs, \
6-
Recipients
5+
from docusign_esign import AccountsApi, EnvelopesApi, RecipientIdentityInputOption, RecipientIdentityPhoneNumber, RecipientViewRequest, Document, Signer, EnvelopeDefinition, \
6+
Recipients, RecipientIdentityVerification
77
from flask import session, url_for, request
88

9-
from ...consts import authentication_method, demo_docs_path, pattern, signer_client_id
9+
from ...consts import demo_docs_path, pattern, signer_client_id
1010
from ...docusign import create_api_client
1111
from ...ds_config import DS_CONFIG
1212

@@ -20,11 +20,16 @@ def get_args():
2020
# 1. Parse request arguments
2121
signer_email = pattern.sub("", request.form.get("signer_email"))
2222
signer_name = pattern.sub("", request.form.get("signer_name"))
23+
phone_number = pattern.sub("", request.form.get("phone_number", ""))
24+
country_code = pattern.sub("", request.form.get("country_code", ""))
2325
envelope_args = {
2426
"signer_email": signer_email,
2527
"signer_name": signer_name,
28+
"phone_number": phone_number if phone_number else None,
29+
"country_code": country_code if country_code else None,
2630
"signer_client_id": signer_client_id,
2731
"ds_return_url": url_for("ds.ds_return", _external=True),
32+
"ds_ping_url": DS_CONFIG["app_url"] + "/",
2833
}
2934
args = {
3035
"account_id": session["ds_account_id"],
@@ -44,16 +49,41 @@ def worker(cls, args):
4449
"""
4550
#ds-snippet-start:eSign44Step3
4651
envelope_args = args["envelope_args"]
47-
# 1. Create the envelope request object
48-
envelope_definition = cls.make_envelope(envelope_args)
4952

5053
# 2. call Envelopes::create API method
5154
# Exceptions will be caught by the calling function
5255
api_client = create_api_client(base_path=args["base_path"], access_token=args["access_token"])
5356

57+
if envelope_args.get("phone_number"):
58+
account_api = AccountsApi(api_client)
59+
(workflow_results, status, headers) = account_api.get_account_identity_verification_with_http_info(
60+
account_id=args["account_id"]
61+
)
62+
remaining = headers.get("X-RateLimit-Remaining")
63+
reset = headers.get("X-RateLimit-Reset")
64+
65+
if remaining is not None and reset is not None:
66+
reset_date = dt.fromtimestamp(int(reset), tz=timezone.utc)
67+
print(f"API calls remaining: {remaining}")
68+
print(f"Next Reset: {reset_date}")
69+
70+
workflow_id = None
71+
if workflow_results.identity_verification:
72+
for workflow in workflow_results.identity_verification:
73+
if workflow.default_name == "Phone Authentication":
74+
workflow_id = workflow.workflow_id
75+
break
76+
77+
if workflow_id is None:
78+
raise ValueError("IDENTITY_WORKFLOW_INVALID_ID")
79+
80+
envelope_args["workflow_id"] = workflow_id
81+
82+
# Create the envelope request object
83+
envelope_definition = cls.make_envelope(envelope_args)
84+
5485
envelope_api = EnvelopesApi(api_client)
5586
(results, status, headers) = envelope_api.create_envelope_with_http_info(account_id=args["account_id"], envelope_definition=envelope_definition)
56-
5787
remaining = headers.get("X-RateLimit-Remaining")
5888
reset = headers.get("X-RateLimit-Reset")
5989

@@ -68,12 +98,14 @@ def worker(cls, args):
6898
# 3. Create the Recipient View request object
6999
#ds-snippet-start:eSign44Step4
70100
recipient_view_request = RecipientViewRequest(
71-
authentication_method=authentication_method,
101+
authentication_method="none",
72102
client_user_id=envelope_args["signer_client_id"],
73103
recipient_id="1",
74-
return_url=envelope_args["ds_return_url"],
104+
return_url=envelope_args["ds_return_url"] + "?state=123",
75105
user_name=envelope_args["signer_name"],
76106
email=envelope_args["signer_email"],
107+
ping_frequency=600,
108+
ping_url=envelope_args["ds_ping_url"],
77109
frame_ancestors=["http://localhost:3000", "https://apps-d.docusign.com"],
78110
message_origins=["https://apps-d.docusign.com"]
79111
)
@@ -88,7 +120,6 @@ def worker(cls, args):
88120
envelope_id=envelope_id,
89121
recipient_view_request=recipient_view_request
90122
)
91-
92123
remaining = headers.get("X-RateLimit-Remaining")
93124
reset = headers.get("X-RateLimit-Reset")
94125

@@ -137,18 +168,24 @@ def make_envelope(cls, args):
137168
client_user_id=args["signer_client_id"]
138169
)
139170

140-
# Create a sign_here tab (field on the document)
141-
sign_here = SignHere(
142-
# DocuSign SignHere field/tab
143-
anchor_string="/sn1/",
144-
anchor_units="pixels",
145-
anchor_y_offset="10",
146-
anchor_x_offset="20"
147-
)
148-
149-
# Add the tabs model (including the sign_here tab) to the signer
150-
# The Tabs object wants arrays of the different field/tab types
151-
signer.tabs = Tabs(sign_here_tabs=[sign_here])
171+
if args.get("phone_number"):
172+
signer.identity_verification = RecipientIdentityVerification(
173+
workflow_id=args["workflow_id"],
174+
steps=None,
175+
id_check_configuration_name="",
176+
input_options = [
177+
RecipientIdentityInputOption(
178+
name="phone_number_list",
179+
value_type="PhoneNumberList",
180+
phone_number_list=[
181+
RecipientIdentityPhoneNumber(
182+
country_code=args["country_code"],
183+
number=args["phone_number"]
184+
)
185+
]
186+
)
187+
]
188+
)
152189

153190
# Next, create the top level envelope definition and populate it.
154191
envelope_definition = EnvelopeDefinition(

‎app/templates/eSignature/eg044_embed.html‎

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ <h2>The document has been embedded with focused view.</h2>
1616
html,
1717
body {
1818
padding: 0;
19-
margin: 0;
19+
margin-top: 15px;
2020
font: 13px Helvetica, Arial, sans-serif;
2121
}
2222

@@ -32,8 +32,6 @@ <h2>The document has been embedded with focused view.</h2>
3232
</body>
3333
</html>
3434

35-
<p><a href="/">Continue</a></p>
36-
3735
<script src='https://js.docusign.com/bundle.js'></script>
3836
<script>
3937
window.DocuSign.loadDocuSign('{{ integration_key }}')
@@ -46,7 +44,7 @@ <h2>The document has been embedded with focused view.</h2>
4644
branding: {
4745
primaryButton: {
4846
/** Background color of primary button */
49-
backgroundColor: '#333',
47+
backgroundColor: '#50C878',
5048
/** Text color of primary button */
5149
color: '#fff',
5250
}
@@ -55,8 +53,28 @@ <h2>The document has been embedded with focused view.</h2>
5553
/** High-level components we allow specific overrides for */
5654
signingNavigationButton: {
5755
finishText: 'You have finished the document! Hooray!',
58-
position: 'bottom-center'
59-
}
56+
position: 'bottom-center',
57+
shape: 'pill',
58+
},
59+
60+
signingAgreeButton: {
61+
finishText: 'I Agree',
62+
},
63+
64+
signingDeclineButton: {
65+
show: true,
66+
finishText: 'Decline',
67+
backgroundColor: '#ff0000',
68+
color: '#ffffff',
69+
},
70+
71+
downloadModal: {
72+
show: true,
73+
},
74+
75+
declineModal: {
76+
show: true,
77+
},
6078
}
6179
});
6280

@@ -67,6 +85,7 @@ <h2>The document has been embedded with focused view.</h2>
6785
signing.on('sessionEnd', (event) => {
6886
/** The event here denotes what caused the sessionEnd to trigger, such as signing_complete, ttl_expired etc../ **/
6987
console.log('sessionend', event);
88+
window.location.href = '/'
7089
});
7190

7291
signing.mount('#agreement');

‎app/templates/eSignature/eg044_focused_view.html‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
{% set signer_form_index = 0 %}
66
{% set signer_email_index = 0 %}
77
{% set signer_name_index = 1 %}
8+
{% set phone_form_index = 1 %}
9+
{% set country_code_index = 0 %}
10+
{% set phone_number_index = 1 %}
811

912
<form class="eg" action="" method="post" data-busy="form">
1013
{% if 'FormName' in example['Forms'][signer_form_index] %}
@@ -23,6 +26,26 @@
2326
<input type="text" class="form-control" id="signer_name" placeholder="{{ example['Forms'][signer_form_index]['Inputs'][signer_name_index]['InputPlaceholder'] }}" name="signer_name"
2427
value="{{ signer_name }}" required>
2528
</div>
29+
30+
<br/>
31+
{% if example['Forms']|length > phone_form_index and 'FormName' in example['Forms'][phone_form_index] %}
32+
<p>{{ example['Forms'][phone_form_index]['FormName'] | safe }}</p>
33+
{% endif %}
34+
35+
{% if example['Forms']|length > phone_form_index %}
36+
<div class="form-group">
37+
<label for="country_code">{{ example['Forms'][phone_form_index]['Inputs'][country_code_index]['InputName'] }}</label>
38+
<input type="text" class="form-control" id="country_code" name="country_code"
39+
placeholder="{{ example['Forms'][phone_form_index]['Inputs'][country_code_index]['InputPlaceholder'] }}">
40+
</div>
41+
42+
<div class="form-group">
43+
<label for="phone_number">{{ example['Forms'][phone_form_index]['Inputs'][phone_number_index]['InputName'] }}</label>
44+
<input type="text" class="form-control" id="phone_number" name="phone_number"
45+
aria-describedby="phoneHelp" placeholder="{{ example['Forms'][phone_form_index]['Inputs'][phone_number_index]['InputPlaceholder'] }}">
46+
<small id="phoneHelp" class="form-text text-muted">Provide a phone number to enable phone authentication for the signer</small>
47+
</div>
48+
{% endif %}
2649
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
2750
{% include 'submit_button.html' %}
2851
</form>

0 commit comments

Comments
 (0)