Skip to content

Commit dd1bdc3

Browse files
2 parents 08b54ea + ea77f5c commit dd1bdc3

4 files changed

Lines changed: 136 additions & 23 deletions

File tree

src/main/java/com/docusign/controller/eSignature/examples/EG044ControllerFocusedView.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,29 @@ protected void onInitModel(WorkArguments args, ModelMap model) throws Exception
4040
}
4141

4242
@Override
43-
protected Object doWork(WorkArguments args, ModelMap model,
44-
HttpServletResponse response) throws Exception {
43+
protected Object doWork(
44+
WorkArguments args,
45+
ModelMap model,
46+
HttpServletResponse response
47+
) throws Exception {
4548
String signerName = args.getSignerName();
4649
String signerEmail = args.getSignerEmail();
50+
String phoneNumber = args.getPhoneNumber();
51+
String countryCode = args.getCountryCode();
4752
String accountId = session.getAccountId();
4853

4954
// Call DocuSign to create the envelope
5055
ApiClient apiClient = createApiClient(session.getBasePath(), user.getAccessToken());
5156

5257
// Call the method from Examples API to send envelope and generate url for focused view signing
5358
String[] envelopeIdAndRedirectUrl = new FocusedViewService().sendEnvelopeWithFocusedView(
54-
signerEmail,
55-
signerName,
56-
apiClient,
57-
accountId,
58-
config.getDsReturnUrl());
59+
signerEmail,
60+
signerName,
61+
phoneNumber,
62+
countryCode,
63+
apiClient,
64+
accountId,
65+
config.getDsReturnUrl());
5966

6067
if(envelopeIdAndRedirectUrl.length == 2){
6168
model.addAttribute(ENVELOPE_ID, envelopeIdAndRedirectUrl[0]);

src/main/java/com/docusign/controller/eSignature/services/FocusedViewService.java

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package com.docusign.controller.eSignature.services;
22

33
import com.docusign.controller.eSignature.examples.EnvelopeHelpers;
4+
import com.docusign.esign.api.AccountsApi;
45
import com.docusign.esign.api.EnvelopesApi;
56
import com.docusign.esign.client.ApiClient;
67
import com.docusign.esign.client.ApiException;
8+
import com.docusign.esign.model.AccountIdentityVerificationWorkflow;
79
import com.docusign.esign.model.EnvelopeDefinition;
8-
import com.docusign.esign.model.EnvelopeSummary;
10+
import com.docusign.esign.model.RecipientIdentityInputOption;
11+
import com.docusign.esign.model.RecipientIdentityPhoneNumber;
12+
import com.docusign.esign.model.RecipientIdentityVerification;
913
import com.docusign.esign.model.RecipientViewRequest;
1014
import com.docusign.esign.model.ViewUrl;
1115
import com.docusign.esign.model.Signer;
@@ -27,27 +31,59 @@ public class FocusedViewService {
2731

2832
private static String SIGNER_CLIENT_ID = "1000";
2933

30-
private static int ANCHOR_OFFSET_Y = 20;
31-
32-
private static int ANCHOR_OFFSET_X = 10;
33-
3434
public static String STATE_123 = "?state=123";
3535

3636
public static String AUTHENTICATION_METHOD = "none";
3737

3838
public String[] sendEnvelopeWithFocusedView(
3939
String signerEmail,
4040
String signerName,
41+
String phoneNumber,
42+
String countryCode,
4143
ApiClient apiClient,
4244
String accountId,
4345
String returnUrl) throws ApiException, IOException {
4446
//ds-snippet-start:eSign44Step3
47+
String workflowId = null;
48+
49+
// Resolve identity verification workflow only when phone auth is requested.
50+
if (phoneNumber != null && !phoneNumber.isBlank()) {
51+
AccountsApi accountsApi = new AccountsApi(apiClient);
52+
var workflowRes = accountsApi.getAccountIdentityVerificationWithHttpInfo(
53+
accountId,
54+
accountsApi.new GetAccountIdentityVerificationOptions());
55+
56+
Map<String, List<String>> headers = workflowRes.getHeaders();
57+
java.util.List<String> remaining = headers.get("X-RateLimit-Remaining");
58+
List<String> reset = headers.get("X-RateLimit-Reset");
59+
60+
if (remaining != null & reset != null) {
61+
Instant resetInstant = Instant.ofEpochSecond(Long.parseLong(reset.get(0)));
62+
System.out.println("API calls remaining: " + remaining);
63+
System.out.println("Next Reset: " + resetInstant);
64+
}
65+
66+
List<AccountIdentityVerificationWorkflow> identityVerification =
67+
workflowRes.getData().getIdentityVerification();
68+
for (AccountIdentityVerificationWorkflow workflow : identityVerification) {
69+
if ("Phone Authentication".equals(workflow.getDefaultName())) {
70+
workflowId = workflow.getWorkflowId();
71+
break;
72+
}
73+
}
74+
75+
if (workflowId == null) {
76+
throw new ApiException("IDENTITY_WORKFLOW_INVALID_ID");
77+
}
78+
}
79+
4580
EnvelopeDefinition envelope = makeEnvelope(
4681
signerEmail,
4782
signerName,
4883
SIGNER_CLIENT_ID,
49-
ANCHOR_OFFSET_Y,
50-
ANCHOR_OFFSET_X,
84+
workflowId,
85+
phoneNumber,
86+
countryCode,
5187
DOCUMENT_FILE_NAME,
5288
DOCUMENT_NAME);
5389

@@ -120,21 +156,37 @@ public EnvelopeDefinition makeEnvelope(
120156
String signerEmail,
121157
String signerName,
122158
String signerClientId,
123-
Integer anchorOffsetY,
124-
Integer anchorOffsetX,
159+
String workflowId,
160+
String phoneNumber,
161+
String countryCode,
125162
String documentFileName,
126163
String documentName) throws IOException {
127164
String emailSubject = "Please sign this document";
128165
String recipientId = "1";
129-
String anchorString = "/sn1/";
130166
String docId = "3";
131167

132168
Signer signer = new Signer();
133169
signer.setEmail(signerEmail);
134170
signer.setName(signerName);
135171
signer.clientUserId(signerClientId);
136172
signer.recipientId(recipientId);
137-
signer.setTabs(EnvelopeHelpers.createSingleSignerTab(anchorString, anchorOffsetY, anchorOffsetX));
173+
174+
if (phoneNumber != null && !phoneNumber.isBlank()) {
175+
RecipientIdentityPhoneNumber recipientIdentityPhoneNumber = new RecipientIdentityPhoneNumber();
176+
recipientIdentityPhoneNumber.setCountryCode(countryCode);
177+
recipientIdentityPhoneNumber.setNumber(phoneNumber);
178+
179+
RecipientIdentityInputOption inputOption = new RecipientIdentityInputOption();
180+
inputOption.setName("phone_number_list");
181+
inputOption.setValueType("PhoneNumberList");
182+
inputOption.setPhoneNumberList(List.of(recipientIdentityPhoneNumber));
183+
184+
RecipientIdentityVerification identityVerification = new RecipientIdentityVerification();
185+
identityVerification.setWorkflowId(workflowId);
186+
identityVerification.setInputOptions(List.of(inputOption));
187+
188+
signer.setIdentityVerification(identityVerification);
189+
}
138190

139191
Recipients recipients = new Recipients();
140192
recipients.setSigners(Collections.singletonList(signer));

src/main/webapp/WEB-INF/templates/views/pages/esignature/examples/eg044.jsp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
<jsp:include page="../../../partials/head.jsp"/>
33

44
<c:set var="formNumber" value="0" scope="page" />
5+
<c:set var="phoneFormNumber" value="1" scope="page" />
6+
<c:set var="countryCodeInputNumber" value="0" scope="page" />
57
<c:set var="signerEmailInputNumber" value="0" scope="page" />
8+
<c:set var="phoneNumberInputNumber" value="1" scope="page" />
69
<c:set var="signerNameInputNumber" value="1" scope="page" />
710

811
<h4>${example.getExampleName()}</h4>
@@ -49,6 +52,38 @@
4952
value="${locals.dsConfig.signerName}"
5053
required>
5154
</div>
55+
56+
<br/>
57+
<c:if test="${example.getForms().size() gt 1 and not empty example.getForms().get(phoneFormNumber).getFormName()}">
58+
${example.getForms().get(phoneFormNumber).getFormName()}
59+
</c:if>
60+
61+
<c:if test="${example.getForms().size() gt 1 and example.getForms().get(phoneFormNumber).getInputs().size() gt 0}">
62+
<div class="form-group">
63+
<label for="countryCode">${example.getForms().get(phoneFormNumber).getInputs().get(countryCodeInputNumber).getInputName()}</label>
64+
<input type="text"
65+
class="form-control"
66+
id="countryCode"
67+
name="countryCode"
68+
placeholder="${example.getForms().get(phoneFormNumber).getInputs().get(countryCodeInputNumber).getInputPlaceholder()}">
69+
</div>
70+
</c:if>
71+
72+
<c:if test="${example.getForms().size() gt 1 and example.getForms().get(1).getInputs().size() gt 1}">
73+
<div class="form-group">
74+
<label for="phoneNumber">${example.getForms().get(phoneFormNumber).getInputs().get(phoneNumberInputNumber).getInputName()}</label>
75+
<input type="text"
76+
class="form-control"
77+
id="phoneNumber"
78+
name="phoneNumber"
79+
aria-describedby="phoneHelp"
80+
placeholder="${example.getForms().get(phoneFormNumber).getInputs().get(phoneNumberInputNumber).getInputPlaceholder()}">
81+
<small id="phoneHelp" class="form-text text-muted">
82+
Provide a phone number to enable phone authentication for the signer
83+
</small>
84+
</div>
85+
</c:if>
86+
5287
<input type="hidden" name="_csrf" value="${csrfToken}">
5388
<button type="submit" class="btn btn-docu">${launcherTexts.getSubmitButton()}</button>
5489
</form>

src/main/webapp/WEB-INF/templates/views/pages/esignature/examples/embed.jsp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
</body>
3434
</html>
3535

36-
<p><a href="/">Continue</a></p>
37-
3836
<script src='https://js.docusign.com/bundle.js'></script>
3937
<script>
4038
window.DocuSign.loadDocuSign('${integrationKey}')
@@ -47,7 +45,7 @@
4745
branding: {
4846
primaryButton: {
4947
/** Background color of primary button */
50-
backgroundColor: '#333',
48+
backgroundColor: '#50C878',
5149
/** Text color of primary button */
5250
color: '#fff',
5351
}
@@ -56,8 +54,28 @@
5654
/** High-level components we allow specific overrides for */
5755
signingNavigationButton: {
5856
finishText: 'You have finished the document! Hooray!',
59-
position: 'bottom-center'
60-
}
57+
position: 'bottom-center',
58+
shape: 'pill',
59+
},
60+
61+
signingAgreeButton: {
62+
finishText: 'I Agree',
63+
},
64+
65+
signingDeclineButton: {
66+
show: true,
67+
finishText: 'Decline',
68+
backgroundColor: '#ff0000',
69+
color: '#ffffff',
70+
},
71+
72+
downloadModal: {
73+
show: true,
74+
},
75+
76+
declineModal: {
77+
show: true,
78+
},
6179
}
6280
});
6381
@@ -68,6 +86,7 @@
6886
signing.on('sessionEnd', (event) => {
6987
/** The event here denotes what caused the sessionEnd to trigger, such as signing_complete, ttl_expired etc../ **/
7088
console.log('sessionend', event);
89+
window.location.href = '/'
7190
});
7291
7392
signing.mount('#agreement');

0 commit comments

Comments
 (0)