11import base64
22from os import path
33
4- from docusign_esign import EnvelopesApi , EnvelopeDefinition , Document , Signer , SignHere , Tabs , Recipients
5- from flask import request , session
4+ from docusign_esign import AccountsApi , EnvelopesApi , EnvelopeDefinition , Document , Signer , SignHere , Tabs , Recipients , RecipientIdentityInputOption , RecipientIdentityPhoneNumber
5+ from docusign_esign .client .api_exception import ApiException
6+ from flask import current_app as app , session , request
67
78from ....consts import demo_docs_path , pattern
89from ....docusign import create_api_client
910from ....ds_config import DS_CONFIG
11+ from ....error_handlers import process_error
1012
1113
1214class Eg020Controller :
1315 @staticmethod
1416 def get_args ():
1517 """Get required session and request arguments"""
1618 # More data validation would be a good idea here
17- # Strip anything other than characters listed
18- phone_number = request .form .get ("phone_number" )
19+ # Strip anything other than the characters listed
1920 signer_email = pattern .sub ("" , request .form .get ("signer_email" ))
2021 signer_name = pattern .sub ("" , request .form .get ("signer_name" ))
22+ country_code = pattern .sub ("" , request .form .get ("country_code" ))
23+ phone_number = pattern .sub ("" , request .form .get ("phone_number" ))
2124 envelope_args = {
2225 "signer_email" : signer_email ,
2326 "signer_name" : signer_name ,
27+ "phone_number" : phone_number ,
28+ "country_code" : country_code ,
2429 "status" : "sent" ,
25- "phone_number " : phone_number
30+ "workflow_id " : session [ 'workflow_id' ]
2631 }
27-
2832 args = {
2933 "account_id" : session ["ds_account_id" ], # represents your {ACCOUNT_ID}
3034 "base_path" : session ["ds_base_path" ],
@@ -38,12 +42,11 @@ def worker(args):
3842 """
3943 1. Create an api client
4044 2. Create an envelope definition object
41- 3. Call the eSignature REST API using the SDK
4245 """
4346 # Step 1: Construct your API headers
4447 api_client = create_api_client (base_path = args ["base_path" ], access_token = args ["access_token" ])
4548
46- # Step 2 : Construct your envelope
49+ # Step 3 : Construct your envelope
4750 envelope_definition = EnvelopeDefinition (
4851 email_subject = "Please sign this document set"
4952 )
@@ -53,7 +56,7 @@ def worker(args):
5356 content_bytes = file .read ()
5457 base64_file_content = base64 .b64encode (content_bytes ).decode ("ascii" )
5558
56- # Add a Document
59+ # Add a document
5760 document1 = Document ( # create the DocuSign document object
5861 document_base64 = base64_file_content ,
5962 document_id = "1" , # a label used to reference the doc
@@ -64,16 +67,6 @@ def worker(args):
6467 envelope_definition .documents = [document1 ]
6568 envelope_definition .status = args ["envelope_args" ]["status" ]
6669
67- signer1 = Signer (
68- email = args ["envelope_args" ]["signer_email" ], # represents your {signer_email}
69- name = args ["envelope_args" ]["signer_name" ], # represents your {signer_name}
70- sms_authentication = {"senderProvidedNumbers" : [args ["envelope_args" ]["phone_number" ]]},
71- id_check_configuration_name = "SMS Auth $" ,
72- require_id_lookup = "true" ,
73- recipient_id = "1" ,
74- routing_order = "1"
75- )
76-
7770 # Create your signature tab
7871 sign_here1 = SignHere (
7972 name = "SignHereTab" ,
@@ -87,14 +80,50 @@ def worker(args):
8780 recipient_id = "1" # represents your {RECIPIENT_ID}
8881 )
8982
90- # Add the tabs model (including the sign_here tabs) to the signer
91- # The Tabs object wants arrays of the different field/tab types
92- signer1 .tabs = Tabs (sign_here_tabs = [sign_here1 ])
83+ signer1 = Signer (
84+ email = args ["envelope_args" ]["signer_email" ], # Represents your {signer_email}
85+ name = args ["envelope_args" ]["signer_name" ], # Represents your {signer_name}
86+ role_name = "" ,
87+ note = "" ,
88+ status = "created" ,
89+ delivery_method = "email" ,
90+ recipient_id = "1" , # Represents your {RECIPIENT_ID}
91+ routing_order = "1" ,
92+ identity_verification = { "workflowId" : "c368e411-1592-4001-a3df-dca94ac539ae" , "steps" : "null" , "inputOptions" :[{"name" :"phone_number_list" ,"valueType" :"PhoneNumberList" ,"phoneNumberList" :[{"countryCode" :args ["envelope_args" ]["country_code" ],"code" :"1" ,"number" :args ["envelope_args" ]["phone_number" ]}]}], "idCheckConfigurationName" :"" },
93+ tabs = Tabs (sign_here_tabs = [sign_here1 ])
94+ )
9395
9496 # Tabs are set per recipient
9597 envelope_definition .recipients = Recipients (signers = [signer1 ])
96- # Step 3: Call the eSignature REST API
97- envelope_api = EnvelopesApi (api_client )
98- results = envelope_api .create_envelope (account_id = args ["account_id" ], envelope_definition = envelope_definition )
98+
99+ # Step 4: Call the eSignature REST API
100+ envelopes_api = EnvelopesApi (api_client )
101+ results = envelopes_api .create_envelope (account_id = args ["account_id" ], envelope_definition = envelope_definition )
99102
100103 return results
104+
105+ @staticmethod
106+ def get_workflow (args ):
107+ """Retrieve the workflow id"""
108+ """try:
109+ api_client = create_api_client(base_path=args["base_path"], access_token=args["access_token"])
110+
111+ workflow_details = AccountsApi(api_client)
112+ workflow_response = workflow_details.get_account_identity_verification(account_id=args["account_id"])
113+
114+ # Check that idv authentication is enabled
115+ if workflow_response.identity_verification:
116+ workflow_id = workflow_response.identity_verification[0].workflow_id
117+ app.logger.info("We found the following workflowID: " + workflow_id)
118+ session['workflow_id'] = workflow_id
119+
120+ return workflow_id
121+
122+ else:
123+ return None
124+
125+ except ApiException as err:
126+ return process_error(err)"""
127+
128+ session ['workflow_id' ] = "c368e411-1592-4001-a3df-dca94ac539ae"
129+ return "c368e411-1592-4001-a3df-dca94ac539ae"
0 commit comments