22from datetime import datetime as dt , timezone
33from 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
77from 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
1010from ...docusign import create_api_client
1111from ...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 (
0 commit comments