11package com .docusign .controller .eSignature .services ;
22
33import com .docusign .controller .eSignature .examples .EnvelopeHelpers ;
4+ import com .docusign .esign .api .AccountsApi ;
45import com .docusign .esign .api .EnvelopesApi ;
56import com .docusign .esign .client .ApiClient ;
67import com .docusign .esign .client .ApiException ;
8+ import com .docusign .esign .model .AccountIdentityVerificationWorkflow ;
79import 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 ;
913import com .docusign .esign .model .RecipientViewRequest ;
1014import com .docusign .esign .model .ViewUrl ;
1115import 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 ));
0 commit comments