def send_document_for_signing(loan_id, signer_name, signer_email): APP_PATH = os.path.dirname(os.path.abspath(__file__)) access_token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjY4MTg1ZmYxLTRlNTEtNGNlOS1hZjFjLTY4OTgxMjIwMzMxNyJ9.eyJUb2tlblR5cGUiOjUsIklzc3VlSW5zdGFudCI6MTU3NTY5MDA3NywiZXhwIjoxNTc1NzE4ODc3LCJVc2VySWQiOiI5YmM2MWNiZC1lMjA2LTQ4ZmYtOGE2OC1mZGM0ZGNlMWRhOWUiLCJzaXRlaWQiOjEsInNjcCI6WyJzaWduYXR1cmUiLCJjbGljay5tYW5hZ2UiLCJvcmdhbml6YXRpb25fcmVhZCIsImdyb3VwX3JlYWQiLCJwZXJtaXNzaW9uX3JlYWQiLCJ1c2VyX3JlYWQiLCJ1c2VyX3dyaXRlIiwiYWNjb3VudF9yZWFkIiwiZG9tYWluX3JlYWQiLCJpZGVudGl0eV9wcm92aWRlcl9yZWFkIiwiZHRyLnJvb21zLnJlYWQiLCJkdHIucm9vbXMud3JpdGUiLCJkdHIuZG9jdW1lbnRzLnJlYWQiLCJkdHIuZG9jdW1lbnRzLndyaXRlIiwiZHRyLnByb2ZpbGUucmVhZCIsImR0ci5wcm9maWxlLndyaXRlIiwiZHRyLmNvbXBhbnkucmVhZCIsImR0ci5jb21wYW55LndyaXRlIl0sImF1ZCI6ImYwZjI3ZjBlLTg1N2QtNGE3MS1hNGRhLTMyY2VjYWUzYTk3OCIsImF6cCI6ImYwZjI3ZjBlLTg1N2QtNGE3MS1hNGRhLTMyY2VjYWUzYTk3OCIsImlzcyI6Imh0dHBzOi8vYWNjb3VudC1kLmRvY3VzaWduLmNvbS8iLCJzdWIiOiI5YmM2MWNiZC1lMjA2LTQ4ZmYtOGE2OC1mZGM0ZGNlMWRhOWUiLCJhdXRoX3RpbWUiOjE1NzU2OTAwMDYsInB3aWQiOiIyZjA5MDc4Yy0yMzdiLTQ1ODMtYWI0MS1jOGM4NTg2MDllZmYifQ.wrcjGaFQTDAZ2NpYcT4i40hboJyc4s1NGNodhN0VEEWh-XuM5cmHJJQECEueGf3UA9taUjupFbI86JxMkpx9GqebBBNCT6UyHBq0GPbhy85nR2ktgYi6ZbcBJvxiLdWwd3IkrC0a-4GVAgqdp1pXVe79f4nPMmRzCvKMIsdlUUVcQCacPU7hgHNuZhwwPikQKO1WDEBCD8epv4qbil4_Er73It3-DNMNYa4yqaaQ64rb_xTOAwYZ4Ua3w6gW2Vot6zBIt-Gm1Go8GgDrzrAxES5W0e6DtQMUq48q9Kiba5YhdnZSXLC1yJIb2ma_p0j1NYW-Pu0WMjjK8Y_-4B6RpQ' account_id = '5959504' file_name_path = 'documents/approval_letter.pdf' base_path = 'https://demo.docusign.net/restapi' # Create the component objects for the envelope definition... with open(os.path.join(APP_PATH, file_name_path), "rb") as file: content_bytes = file.read() base64_file_content = base64.b64encode(content_bytes).decode('ascii') document = Document( # create the DocuSign document object document_base64=base64_file_content, name='Approval Letter', # can be different from actual file name file_extension='pdf', # many different document types are accepted document_id=1 # a label used to reference the doc ) # Create the signer recipient model signer = Signer( # The signer email=signer_email, name=signer_name, recipient_id="1", routing_order="1") # Create a sign_here tab (field on the document) sign_here = SignHere( # DocuSign SignHere field/tab document_id='1', page_number='1', recipient_id='1', tab_label='SignHereTab', x_position='195', y_position='147') # Add the tabs model (including the sign_here tab) to the signer signer.tabs = Tabs(sign_here_tabs=[ sign_here ]) # The Tabs object wants arrays of the different field/tab types # Next, create the top level envelope definition and populate it. envelope_definition = EnvelopeDefinition( email_subject="Please sign this Approval Letter for your loan.", documents=[ document ], # The order in the docs array determines the order in the envelope recipients=Recipients( signers=[signer] ), # The Recipients object wants arrays for each recipient type status="sent" # requests that the envelope be created and sent. ) # send envelope request api_client = ApiClient() api_client.host = base_path api_client.set_default_header("Authorization", "Bearer " + access_token) envelope_api = EnvelopesApi(api_client) results = envelope_api.create_envelope( account_id, envelope_definition=envelope_definition) return results
def embedded_signing_ceremony(signer_email, signer_name, signer_id, signer_file_path, signer_file_name, form_filled_type): with open(os.path.join(APP_PATH, signer_file_path), "rb") as file: content_bytes = file.read() base64_file_content = base64.b64encode(content_bytes).decode('ascii') document = Document(document_base64 = base64_file_content, name = signer_file_name, file_extension = 'pdf', document_id = 1) signer = Signer(email = signer_email, name = signer_name, recipient_id = "1", routing_order = "1", client_user_id = signer_id) sign_here = SignHere(document_id = '1', page_number = '1', recipient_id = '1', tab_label = 'SignHereTab', x_position = '300', y_position = '650') signer.tabs = Tabs(sign_here_tabs = [sign_here]) envelope_definition = EnvelopeDefinition( email_subject = "Please sign this document sent from the Python SDK", documents = [document], recipients = Recipients(signers = [signer]), status = "sent" ) api_client = ApiClient() api_client.host = base_path api_client.set_default_header("Authorization", "Bearer " + access_token) envelope_api = EnvelopesApi(api_client) results = envelope_api.create_envelope(account_id, envelope_definition=envelope_definition) envelope_id = results.envelope_id recipient_view_request = RecipientViewRequest(authentication_method = "email", client_user_id = signer_id, recipient_id = '1', return_url = base_url + form_filled_type, user_name = signer_name, email = signer_email) results = envelope_api.create_recipient_view(account_id, envelope_id, recipient_view_request = recipient_view_request) return results.url
def send_document_for_signing(): """ Sends the document <file_name> to be signed by <signer_name> via <signer_email> """ # Create the component objects for the envelope definition... with open(os.path.join(APP_PATH, file_name_path), "rb") as file: content_bytes = file.read() base64_file_content = base64.b64encode(content_bytes).decode('ascii') document = Document( # create the DocuSign document object document_base64=base64_file_content, name='Example document', # can be different from actual file name file_extension='pdf', # many different document types are accepted document_id=1 # a label used to reference the doc ) # Create the signer recipient model signer = Signer( # The signer email=signer_email, name=signer_name, recipient_id="1", routing_order="1") # Create a sign_here tab (field on the document) sign_here = SignHere( # DocuSign SignHere field/tab document_id='1', page_number='1', recipient_id='1', tab_label='SignHereTab', x_position='195', y_position='147') # Add the tabs model (including the sign_here tab) to the signer signer.tabs = Tabs(sign_here_tabs=[ sign_here ]) # The Tabs object wants arrays of the different field/tab types # Next, create the top level envelope definition and populate it. envelope_definition = EnvelopeDefinition( email_subject="Please sign this document sent from the Python SDK", documents=[ document ], # The order in the docs array determines the order in the envelope recipients=Recipients( signers=[signer] ), # The Recipients object wants arrays for each recipient type status="sent" # requests that the envelope be created and sent. ) # Ready to go: send the envelope request api_client = ApiClient() api_client.host = base_path api_client.set_default_header("Authorization", "Bearer " + access_token) envelope_api = EnvelopesApi(api_client) results = envelope_api.create_envelope( account_id, envelope_definition=envelope_definition) return results
def make_envelope(cls, args): """ Creates envelope args -- parameters for the envelope: signer_email, signer_name, signer_client_id returns an envelope definition """ # document 1 (pdf) has tag /sn1/ # # The envelope has one recipient. # recipient 1 - signer with open(path.join(demo_docs_path, DS_CONFIG["doc_pdf"]), "rb") as file: content_bytes = file.read() base64_file_content = base64.b64encode(content_bytes).decode("ascii") # Create the document model document = Document( # create the DocuSign document object document_base64=base64_file_content, name="Example document", # can be different from actual file name file_extension="pdf", # many different document types are accepted document_id=1 # a label used to reference the doc ) # Create the signer recipient model signer = Signer( # The signer email=args["signer_email"], name=args["signer_name"], recipient_id="1", routing_order="1", # Setting the client_user_id marks the signer as embedded client_user_id=args["signer_client_id"] ) # Create a sign_here tab (field on the document) sign_here = SignHere( # DocuSign SignHere field/tab anchor_string="/sn1/", anchor_units="pixels", anchor_y_offset="10", anchor_x_offset="20" ) # Add the tabs model (including the sign_here tab) to the signer # The Tabs object wants arrays of the different field/tab types signer.tabs = Tabs(sign_here_tabs=[sign_here]) # Next, create the top level envelope definition and populate it. envelope_definition = EnvelopeDefinition( email_subject="Please sign this document sent from the Python SDK", documents=[document], # The Recipients object wants arrays for each recipient type recipients=Recipients(signers=[signer]), status="sent" # requests that the envelope be created and sent. ) return envelope_definition
def post(self, request, envelope_id): signer = Signer(email=request.POST['email'], name='Aaqib 2', recipient_id='2', routing_order='1') sign_here = SignHere(anchor_string='**Employee Signature**', anchor_units='pixels', anchor_y_offset='10', anchor_x_offset='100') signer.tabs = Tabs(sign_here_tabs=[sign_here]) recipients = Recipients(signers=[signer]) envelopes_api = EnvelopesApi(get_api_client()) envelope = envelopes_api.create_recipient(ACCOUNT_ID, envelope_id, recipients=recipients, resend_envelope='true') sign_request = SignRequest.objects.get(envelope=SigEnvelope.objects.get(envelope_id=envelope_id)) Recipient.objects.create(email=request.POST['email'], recipient_id='2', sign_request=sign_request) return redirect(reverse('esign:envelope_detail', kwargs={'envelope_id': envelope_id}))
def make_envelope(): with open(f'{BASE_DIR}/document.pdf', 'rb') as pdf_file: content_bytes = pdf_file.read() base64_file_content = base64.b64encode(content_bytes).decode('ascii') document = Document(document_base64=base64_file_content, name='Employee Contract', file_extension='pdf', document_id='1') signer = Signer(email='*****@*****.**', name='M Aaqib', recipient_id='1', routing_order='1') sign_here = SignHere(anchor_string='**Employee Signature**', anchor_units='pixels', anchor_y_offset='10', anchor_x_offset='20') signer.tabs = Tabs(sign_here_tabs=[sign_here]) recipients = Recipients(signers=[signer]) envelope_definition = EnvelopeDefinition(email_subject='Please sign this document set', documents=[document], recipients=recipients, status='sent') return envelope_definition
def make_envelope(file, sender, signer_name, signer_email, token): file.seek(0) content_bytes = file.read() base64_file_content = base64.b64encode(content_bytes).decode('ascii') document = Document(document_base64=base64_file_content, name='DocuScan Terms', file_extension='html', document_id=1) signer = Signer(email=signer_email, name=signer_name, recipient_id='1', routing_order='1') envelope_definition = EnvelopeDefinition( email_subject='Please sign these terms', documents=[document], recipients=Recipients(signers=[signer]), status='sent') api_client = ApiClient() api_client.host = 'https://demo.docusign.net/restapi' api_client.set_default_header('Authorization', 'Bearer ' + token) envelope_api = EnvelopesApi(api_client) results = envelope_api.create_envelope( sender['accounts'][0]['account_id'], envelope_definition=envelope_definition) return results
def createSigner(): signer = Signer() signer.email = DSConfig.signer_email() signer.name = DSConfig.signer_name() signer.recipient_id = "1" signer.routing_order = "1" return signer
def make_envelope(cls, args): """ Creates envelope """ # Open the example file with open(path.join(demo_docs_path, DS_CONFIG["doc_pdf"]), "rb") as file: content_bytes = file.read() base64_file_content = base64.b64encode(content_bytes).decode("ascii") document = Document(document_base64=base64_file_content, name="lorem", file_extension="pdf", document_id=1) signer = Signer(email=args["signer_email"], name=args["signer_name"], recipient_id="1", routing_order="1") sign_here = SignHere(anchor_string="/sn1/", anchor_units="pixels", anchor_y_offset="572", anchor_x_offset="75") signer.tabs = Tabs(sign_here_tabs=[sign_here]) envelope_definition = EnvelopeDefinition( email_subject="Please Sign", documents=[document], recipients=Recipients(signers=[signer]), status="sent", brand_id=args["brand_id"], ) return envelope_definition
def get(self, request, *args, **kwargs): api_client = get_api_client() bulk_envelopes_api = BulkEnvelopesApi(api_client) recipient_1 = BulkSendingCopyRecipient(role_name='signer', name='Aaqib 1', email='*****@*****.**') recipient_2 = BulkSendingCopyRecipient(role_name='signer', name='Aaqib 2', email='*****@*****.**') bulk_copies = [ BulkSendingCopy(recipients=[recipient_1], custom_fields=[]), BulkSendingCopy(recipients=[recipient_2], custom_fields=[]), ] bulk_sending_list = BulkSendingList(name='employee_contract', bulk_copies=bulk_copies) bulk_list = bulk_envelopes_api.create_bulk_send_list(ACCOUNT_ID, bulk_sending_list=bulk_sending_list) bulk_list_id = bulk_list.list_id envelopes_api = EnvelopesApi(api_client) with open(f'{BASE_DIR}/document.pdf', 'rb') as pdf_file: content_bytes = pdf_file.read() base64_file_content = base64.b64encode(content_bytes).decode('ascii') document = Document(document_base64=base64_file_content, name='Employee Contract', file_extension='pdf', document_id='1') envelope_definition = EnvelopeDefinition(email_subject='Please sign this document set', documents=[document], recipients={}, status='created', envelope_id_stamping='true') envelope = envelopes_api.create_envelope(account_id=ACCOUNT_ID, envelope_definition=envelope_definition) envelope_id = envelope.envelope_id text_custom_fields = TextCustomField(name='mailingListId', required='false', show='false', value=bulk_list_id) custom_fields = CustomFields(list_custom_fields=[], text_custom_fields=[text_custom_fields]) envelopes_api.create_custom_fields(account_id=ACCOUNT_ID, envelope_id=envelope_id, custom_fields=custom_fields) signer = Signer(name='Multi Bulk Recipient::signer', email='*****@*****.**', role_name='signer', note='', routing_order='1', status='created', delivery_method='email', recipient_id='13', recipient_type='signer') envelopes_api.create_recipient(ACCOUNT_ID, envelope_id, recipients=Recipients(signers=[signer])) bulk_send_request = BulkSendRequest(envelope_or_template_id=envelope_id) batch = bulk_envelopes_api.create_bulk_send_request(ACCOUNT_ID, bulk_list_id, bulk_send_request=bulk_send_request) time.sleep(10) from_date = (datetime.utcnow() - timedelta(seconds=60)).isoformat() envelopes = envelopes_api.list_status_changes(ACCOUNT_ID, status='sent', from_date=from_date).envelopes for envelope in envelopes: env, created = SigEnvelope.objects.get_or_create(envelope_id=envelope.envelope_id) if created: sign_request = SignRequest.objects.create(envelope=env, status_date_time=envelope.status_date_time) recipients = envelopes_api.list_recipients(ACCOUNT_ID, envelope.envelope_id) Recipient.objects.create(sign_request=sign_request, email=recipients.signers[0].email, recipient_id=recipients.signers[0].recipient_id) return redirect('esign:envelope_list')
def make_envelope(cls, args): """ This function creates the envelope definition for the order form. document 1 (html) has multiple tags: /l1q/ and /l2q/ -- quantities: drop down /l1e/ and /l2e/ -- extended: payment lines /l3t/ -- total -- formula The envelope has two recipients. recipient 1 - signer recipient 2 - cc The envelope will be sent first to the signer. After it is signed, a copy is sent to the cc person. ################################################################# # # # NOTA BENA: This method programmatically constructs the # # order form. For many use cases, it would be # # better to create the order form as a template # # using the DocuSign web tool as WYSIWYG # # form designer. # # # ################################################################# """ # Order form constants l1_name = "Harmonica" l1_price = 5 l1_description = f"${l1_price} each" l2_name = "Xylophone" l2_price = 150 l2_description = f"${l2_price} each" currency_multiplier = 100 # read the html file from a local directory # The read could raise an exception if the file is not available! doc1_file = "order_form.html" with open(path.join(demo_docs_path, doc1_file), "r") as file: doc1_html_v1 = file.read() # Substitute values into the HTML # Substitute for: {signerName}, {signerEmail}, {cc_name}, {cc_email} doc1_html_v2 = doc1_html_v1.replace("{signer_name}", args["signer_name"]) \ .replace("{signer_email}", args["signer_email"]) \ .replace("{cc_name}", args["cc_name"]) \ .replace("{cc_email}", args["cc_email"]) # create the envelope definition envelope_definition = EnvelopeDefinition( email_subject="Please complete your order") # add the document doc1_b64 = base64.b64encode(bytes(doc1_html_v2, "utf-8")).decode("ascii") doc1 = Document( document_base64=doc1_b64, name="Order form", # can be different from actual file name file_extension="html", # Source data format. document_id="1" # a label used to reference the doc ) envelope_definition.documents = [doc1] # create a signer recipient to sign the document signer1 = Signer(email=args["signer_email"], name=args["signer_name"], recipient_id="1", routing_order="1") # create a cc recipient to receive a copy of the documents cc1 = CarbonCopy(email=args["cc_email"], name=args["cc_name"], recipient_id="2", routing_order="2") # Create signHere fields (also known as tabs) on the documents, # We"re using anchor (autoPlace) positioning sign_here1 = SignHere(anchor_string="/sn1/", anchor_y_offset="10", anchor_units="pixels", anchor_x_offset="20") list_item0 = ListItem(text="none", value="0") list_item1 = ListItem(text="1", value="1") list_item2 = ListItem(text="2", value="2") list_item3 = ListItem(text="3", value="3") list_item4 = ListItem(text="4", value="4") list_item5 = ListItem(text="5", value="5") list_item6 = ListItem(text="6", value="6") list_item7 = ListItem(text="7", value="7") list_item8 = ListItem(text="8", value="8") list_item9 = ListItem(text="9", value="9") list_item10 = ListItem(text="10", value="10") listl1q = List(font="helvetica", font_size="size11", anchor_string="/l1q/", anchor_y_offset="-10", anchor_units="pixels", anchor_x_offset="0", list_items=[ list_item0, list_item1, list_item2, list_item3, list_item4, list_item5, list_item6, list_item7, list_item8, list_item9, list_item10 ], required="true", tab_label="l1q") listl2q = List(font="helvetica", font_size="size11", anchor_string="/l2q/", anchor_y_offset="-10", anchor_units="pixels", anchor_x_offset="0", list_items=[ list_item0, list_item1, list_item2, list_item3, list_item4, list_item5, list_item6, list_item7, list_item8, list_item9, list_item10 ], required="true", tab_label="l2q") # create two formula tabs for the extended price on the line items formulal1e = FormulaTab( font="helvetica", font_size="size11", anchor_string="/l1e/", anchor_y_offset="-8", anchor_units="pixels", anchor_x_offset="105", tab_label="l1e", formula=f"[l1q] * {l1_price}", round_decimal_places="0", required="true", locked="true", disable_auto_size="false", ) formulal2e = FormulaTab( font="helvetica", font_size="size11", anchor_string="/l2e/", anchor_y_offset="-8", anchor_units="pixels", anchor_x_offset="105", tab_label="l2e", formula=f"[l2q] * {l2_price}", round_decimal_places="0", required="true", locked="true", disable_auto_size="false", ) # Formula for the total formulal3t = FormulaTab( font="helvetica", bold="true", font_size="size12", anchor_string="/l3t/", anchor_y_offset="-8", anchor_units="pixels", anchor_x_offset="50", tab_label="l3t", formula="[l1e] + [l2e]", round_decimal_places="0", required="true", locked="true", disable_auto_size="false", ) # Payment line items payment_line_iteml1 = PaymentLineItem(name=l1_name, description=l1_description, amount_reference="l1e") payment_line_iteml2 = PaymentLineItem(name=l2_name, description=l2_description, amount_reference="l2e") payment_details = PaymentDetails( gateway_account_id=args["gateway_account_id"], currency_code="USD", gateway_name=args["gateway_name"], line_items=[payment_line_iteml1, payment_line_iteml2]) # Hidden formula for the payment itself formula_payment = FormulaTab( tab_label="payment", formula=f"([l1e] + [l2e]) * {currency_multiplier}", round_decimal_places="0", payment_details=payment_details, hidden="true", required="true", locked="true", document_id="1", page_number="1", x_position="0", y_position="0") # Tabs are set per recipient / signer signer1_tabs = Tabs( sign_here_tabs=[sign_here1], list_tabs=[listl1q, listl2q], formula_tabs=[formulal1e, formulal2e, formulal3t, formula_payment]) signer1.tabs = signer1_tabs # Add the recipients to the envelope object recipients = Recipients(signers=[signer1], carbon_copies=[cc1]) envelope_definition.recipients = recipients # Request that the envelope be sent by setting |status| to "sent". # To request that the envelope be created as a draft, set to "created" envelope_definition.status = args["status"] return envelope_definition
def make_envelope(cls, args): """ Creates envelope Uses compositing templates to add a new document to the existing template returns an envelope definition The envelope request object uses Composite Template to include in the envelope: 1. A template stored on the DocuSign service 2. An additional document which is a custom HTML source document """ # 1. Create Recipients for server template. Note that Recipients object # is used, not TemplateRole # # Create a signer recipient for the signer role of the server template signer1 = Signer( email=args["signer_email"], name=args["signer_name"], role_name="signer", recipient_id="1", # Adding clientUserId transforms the template recipient # into an embedded recipient: client_user_id=args["signer_client_id"] ) # Create the cc recipient cc1 = CarbonCopy( email=args["cc_email"], name=args["cc_name"], role_name="cc", recipient_id="2" ) # Recipients object: recipients_server_template = Recipients( carbon_copies=[cc1], signers=[signer1] ) # 2. create a composite template for the Server template + roles comp_template1 = CompositeTemplate( composite_template_id="1", server_templates=[ ServerTemplate(sequence="1", template_id=args["template_id"]) ], # Add the roles via an inlineTemplate inline_templates=[ InlineTemplate(sequence="1", recipients=recipients_server_template) ] ) # Next, create the second composite template that will # include the new document. # # 3. Create the signer recipient for the added document # starting with the tab definition: sign_here1 = SignHere( anchor_string="**signature_1**", anchor_y_offset="10", anchor_units="pixels", anchor_x_offset="20" ) signer1_tabs = Tabs(sign_here_tabs=[sign_here1]) # 4. Create Signer definition for the added document signer1_added_doc = Signer( email=args["signer_email"], name=args["signer_name"], role_name="signer", recipient_id="1", client_user_id=args["signer_client_id"], tabs=signer1_tabs ) # 5. The Recipients object for the added document. # Using cc1 definition from above. recipients_added_doc = Recipients( carbon_copies=[cc1], signers=[signer1_added_doc]) # 6. Create the HTML document that will be added to the envelope doc1_b64 = base64.b64encode(bytes(cls.create_document1(args), "utf-8")) \ .decode("ascii") doc1 = Document( document_base64=doc1_b64, name="Appendix 1--Sales order", # can be different from # actual file name file_extension="html", document_id="1" ) # 6. create a composite template for the added document comp_template2 = CompositeTemplate( composite_template_id="2", # Add the recipients via an inlineTemplate inline_templates=[ InlineTemplate(sequence="2", recipients=recipients_added_doc) ], document=doc1 ) # 7. create the envelope definition with the composited templates envelope_definition = EnvelopeDefinition( status="sent", composite_templates=[comp_template1, comp_template2] ) return envelope_definition
def embedded_signing_ceremony(): """ The document <file_name> will be signed by <signer_name> via an embedded signing ceremony. """ # # Step 1. The envelope definition is created. # One signHere tab is added. # The document path supplied is relative to the working directory # env_def = EnvelopeDefinition() env_def.email_subject = 'PLEASE GOD HELP ME, I NEED THIS WORKING!!' env_def.template_id = template_id t_role = TemplateRole() t_role.role_name = role_name t_role.name = name t_role.email = email t_role.client_user_id = client_user_id text_example = Text() text_example.tab_label = 'example' text_example.value = 'SIIII GRACIAS DIOS!! -- EXAMPLE' text_name = Text() text_name.tab_label = 'name' text_name.value = 'SIIII GRACIAS DIOS!! -- NAME' text_name2 = Text() text_name2.tab_label = 'name2' text_name2.value = 'SIIII GRACIAS DIOS!! -- NAME2' text = Text() text.document_id = '1' text.page_number = '1' text.recipient_id = '1' text.x_position = '100' text.y_position = '100' text.scale_value = '0.5' text.value = 'THANKS GOD!!' title_label = Title() title_label.tab_label = 'lablel_example' title_label.value = 'LendingFront' tabs = Tabs() tabs.text_tabs = [text_example, text_name, text_name2, text] tabs.title_tabs = [title_label] t_role.tabs = tabs # Create the signer recipient model signer = Signer( # The signer email=email, name=name, recipient_id="1", routing_order="1", client_user_id=client_user_id # Setting the client_user_id marks the signer as embedded ) # Create a sign_here tab (field on the document) sign_here = SignHere( # DocuSign SignHere field/tab document_id='1', page_number='3', recipient_id='1', tab_label='SignHereTab', x_position='175', y_position='320', ) # Add the tabs model (including the sign_here tab) to the signer signer.tabs = Tabs(sign_here_tabs=[ sign_here ]) # The Tabs object wants arrays of the different field/tab types recipients = Recipients() recipients.signers = [signer] env_def.recipients = recipients env_def.template_roles = [t_role] env_def.status = environment_status # # Step 2. Create/send the envelope. # api_client = ApiClient() api_client.host = base_path api_client.set_default_header("Authorization", "Bearer " + access_token) # authentication_api = AuthenticationApi() # authentication_api.api_client = api_client # access_token = authentication_api.get_o_auth_token() # accessToken = api_client. GetOAuthToken(client_id, client_secret, true, AccessCode); # Console.WriteLine("Access_token: " + accessToken); envelope_api = EnvelopesApi(api_client) envelope_summary = envelope_api.create_envelope( account_id, envelope_definition=env_def) envelope_id = envelope_summary.envelope_id print("Envelope {} has been sent to {}".format(envelope_id, t_role.email)) recipient_view_request = RecipientViewRequest( authentication_method=authentication_method, client_user_id=client_user_id, recipient_id='1', return_url=base_url + '/dsreturn', user_name=name, email=email) results = envelope_api.create_recipient_view( account_id, envelope_id, recipient_view_request=recipient_view_request) return results.url
def make_envelope(cls, args): """ Creates envelope Document: A txt document. DocuSign will convert document to the PDF format. """ # The envelope has two recipients # Recipient 1 - signer1 # Recipient 2 - signer2 # The envelope will be sent first to the signer1 # After it is signed, a signature workflow will be paused # After resuming (unpause) the signature workflow will send to the second recipient # Create the envelope definition env = EnvelopeDefinition(email_subject="EnvelopeWorkflowTest") # Read file from a local directory # The reads could raise an exception if the file is not available! with open(path.join(demo_docs_path, DS_CONFIG["doc_txt"]), "rb") as file: doc_docx_bytes = file.read() doc_b64 = base64.b64encode(doc_docx_bytes).decode("ascii") # Create the document model. document = Document( # Create the DocuSign document object document_base64=doc_b64, name="Welcome", # Can be different from actual file name file_extension="txt", # Many different document types are accepted document_id="1" # The label used to reference the doc ) # The order in the docs array determines the order in the envelope. env.documents = [ document, ] # Create the signer recipient models # routing_order (lower means earlier) determines the order of deliveries # to the recipients. signer1 = Signer(email=args["signer1_email"], name=args["signer1_name"], recipient_id="1", routing_order="1") signer2 = Signer(email=args["signer2_email"], name=args["signer2_name"], recipient_id="2", routing_order="2") # Create SignHere fields (also known as tabs) on the documents. sign_here1 = SignHere(document_id="1", page_number="1", tab_label="Sign Here", x_position="200", y_position="200") sign_here2 = SignHere(document_id="1", page_number="1", tab_label="Sign Here", x_position="300", y_position="200") # Add the tabs model (including the sign_here tabs) to the signer # The Tabs object takes arrays of the different field/tab types signer1.tabs = Tabs(sign_here_tabs=[ sign_here1, ]) signer2.tabs = Tabs(sign_here_tabs=[ sign_here2, ]) # Add the recipients to the envelope object recipients = Recipients(signers=[signer1, signer2]) env.recipients = recipients # Create a workflow model # Signature workflow will be paused after it is signed by the first signer workflow_step = WorkflowStep(action="pause_before", trigger_on_item="routing_order", item_id="2") workflow = Workflow(workflow_steps=[ workflow_step, ]) # Add the workflow to the envelope object env.workflow = workflow # Request that the envelope be sent by setting |status| to "sent" # To request that the envelope be created as a draft, set to "created" env.status = args["status"] return env
def make_envelope(cls, args): """ Creates envelope Document 1: An HTML document. Document 2: A Word .docx document. Document 3: A PDF document. DocuSign will convert all of the documents to the PDF format. The recipients" field tags are placed using <b>anchor</b> strings. """ # document 1 (html) has sign here anchor tag **signature_1** # document 2 (docx) has sign here anchor tag /sn1/ # document 3 (pdf) has sign here anchor tag /sn1/ # # The envelope has two recipients. # recipient 1 - signer # recipient 2 - cc # The envelope will be sent first to the signer. # After it is signed, a copy is sent to the cc person. # create the envelope definition env = EnvelopeDefinition(email_subject="Please sign this document set") doc1_b64 = base64.b64encode(bytes(cls.create_document1(args), "utf-8")).decode("ascii") # read files 2 and 3 from a local directory # The reads could raise an exception if the file is not available! with open(path.join(demo_docs_path, DS_CONFIG["doc_docx"]), "rb") as file: doc2_docx_bytes = file.read() doc2_b64 = base64.b64encode(doc2_docx_bytes).decode("ascii") with open(path.join(demo_docs_path, DS_CONFIG["doc_pdf"]), "rb") as file: doc3_pdf_bytes = file.read() doc3_b64 = base64.b64encode(doc3_pdf_bytes).decode("ascii") # Create the document models document1 = Document( # create the DocuSign document object document_base64=doc1_b64, name= "Order acknowledgement", # can be different from actual file name file_extension="html", # many different document types are accepted document_id="1" # a label used to reference the doc ) document2 = Document( # create the DocuSign document object document_base64=doc2_b64, name="Battle Plan", # can be different from actual file name file_extension="docx", # many different document types are accepted document_id="2" # a label used to reference the doc ) document3 = Document( # create the DocuSign document object document_base64=doc3_b64, name="Lorem Ipsum", # can be different from actual file name file_extension="pdf", # many different document types are accepted document_id="3" # a label used to reference the doc ) # The order in the docs array determines the order in the envelope env.documents = [document1, document2, document3] # Create the signer recipient model signer1 = Signer(email=args["signer_email"], name=args["signer_name"], recipient_id="1", routing_order="1") # routingOrder (lower means earlier) determines the order of deliveries # to the recipients. Parallel routing order is supported by using the # same integer as the order for two or more recipients. # create a cc recipient to receive a copy of the documents cc1 = CarbonCopy(email=args["cc_email"], name=args["cc_name"], recipient_id="2", routing_order="2") # Create signHere fields (also known as tabs) on the documents, # We"re using anchor (autoPlace) positioning # # The DocuSign platform searches throughout your envelope"s # documents for matching anchor strings. So the # signHere2 tab will be used in both document 2 and 3 since they # use the same anchor string for their "signer 1" tabs. sign_here1 = SignHere(anchor_string="**signature_1**", anchor_units="pixels", anchor_y_offset="10", anchor_x_offset="20") sign_here2 = SignHere(anchor_string="/sn1/", anchor_units="pixels", anchor_y_offset="10", anchor_x_offset="20") # Add the tabs model (including the sign_here tabs) to the signer # The Tabs object wants arrays of the different field/tab types signer1.tabs = Tabs(sign_here_tabs=[sign_here1, sign_here2]) # Add the recipients to the envelope object recipients = Recipients(signers=[signer1], carbon_copies=[cc1]) env.recipients = recipients # Request that the envelope be sent by setting |status| to "sent". # To request that the envelope be created as a draft, set to "created" env.status = args["status"] return env
def create(cls, tpl, student, envelope_args): """Creates envelope Parameters: tpl (str): template path for the document student (dict): student information envelope_args (dict): parameters of the document Returns: EnvelopeDefinition object that will be submitted to Docusign """ with open(path.join(TPL_PATH, tpl), 'r') as file: content_bytes = file.read() # Get base64 logo representation to paste it into the html with open(path.join(IMG_PATH, 'logo.png'), 'rb') as file: img_base64_src = base64.b64encode(file.read()).decode('utf-8') content_bytes = Environment(loader=BaseLoader).from_string(content_bytes)\ .render( first_name=student['first_name'], last_name=student['last_name'], email=student['email'], major=student['major'], minor=student['minor'], img_base64_src=img_base64_src ) base64_file_content = base64.b64encode(bytes(content_bytes, 'utf-8')).decode('ascii') # Create the document model document = Document( # create the DocuSign document object document_base64=base64_file_content, name='Change minor/major field', file_extension='html', document_id=1) # Create the signer recipient model signer = Signer( # The signer email=student['email'], name=f"{student['first_name']} {student['last_name']}", recipient_id='1', routing_order='1', # Setting the client_user_id marks the signer as embedded client_user_id=envelope_args['signer_client_id']) # Create a sign_here tab (field on the document) sign_here = SignHere(anchor_string='/signature_1/', anchor_units='pixels', anchor_y_offset='10', anchor_x_offset='20') # Create a initials tab initial_here = InitialHere(anchor_string='/initials_1/', anchor_units='pixels', anchor_y_offset='10', anchor_x_offset='20') # Create email field email = Email(document_id='1', page_number='1', anchor_string='/email/', anchor_units='pixels', required=True, value=student['email'], locked=False, anchor_y_offset='-5') signer.tabs = Tabs(sign_here_tabs=[sign_here], email_tabs=[email], initial_here_tabs=[initial_here]) # Next, create the top level envelope definition and populate it. envelope_definition = EnvelopeDefinition( email_subject='Change minor/major field', documents=[document], # The Recipients object wants arrays for each recipient type recipients=Recipients(signers=[signer]), status='sent' # requests that the envelope be created and sent. ) return envelope_definition
def embedded_signing_ceremony(): """ The document <file_name> will be signed by <signer_name> via an embedded signing ceremony. """ # # Step 1. The envelope definition is created. # One signHere tab is added. # The document path supplied is relative to the working directory # # Create the component objects for the envelope definition... with open(os.path.join(APP_PATH, file_name_path), "rb") as file: content_bytes = file.read() base64_file_content = base64.b64encode(content_bytes).decode('ascii') document = Document( # create the DocuSign document object document_base64=base64_file_content, name='Example document', # can be different from actual file name file_extension='pdf', # many different document types are accepted document_id=1 # a label used to reference the doc ) # Create the signer recipient model signer = Signer( # The signer email=signer_email, name=signer_name, recipient_id="1", routing_order="1", client_user_id= client_user_id, # Setting the client_user_id marks the signer as embedded ) sign_here = SignHere( # DocuSign SignHere field/tab document_id='1', page_number='1', recipient_id='1', tab_label='SignHereTab', x_position='195', y_position='147') # Add the tabs model (including the sign_here tab) to the signer signer.tabs = Tabs(sign_here_tabs=[ sign_here ]) # The Tabs object wants arrays of the different field/tab types # Next, create the top level envelope definition and populate it. envelope_definition = EnvelopeDefinition( email_subject="Please sign this document sent from the Python SDK", documents=[ document ], # The order in the docs array determines the order in the envelope recipients=Recipients( signers=[signer] ), # The Recipients object wants arrays for each recipient type status="sent" # requests that the envelope be created and sent. ) # # Step 2. Create/send the envelope. # api_client = ApiClient() api_client.host = base_path api_client.set_default_header("Authorization", "Bearer " + access_token) envelope_api = EnvelopesApi(api_client) results = envelope_api.create_envelope( account_id, envelope_definition=envelope_definition) # # Step 3. The envelope has been created. # Request a Recipient View URL (the Signing Ceremony URL) # envelope_id = results.envelope_id recipient_view_request = RecipientViewRequest( authentication_method=authentication_method, client_user_id=client_user_id, recipient_id='1', return_url=base_url + '/dsreturn', user_name=signer_name, email=signer_email) results = envelope_api.create_recipient_view( account_id, envelope_id, recipient_view_request=recipient_view_request) # # Step 4. The Recipient View URL (the Signing Ceremony URL) has been received. # Redirect the user's browser to it. # return results.url
def create_claim(cls, tpl, claim, envelope_args): """Creates claim document Parameters: tpl (str): Template path for the document claim (dict): Claim information envelope_args (dict): Parameters of the document Returns: EnvelopeDefinition object that will be submitted to Docusign """ with open(path.join(TPL_PATH, tpl), 'r') as file: content_bytes = file.read() # Get base64 logo representation to paste it into the HTML file with open(path.join(IMG_PATH, 'logo.png'), 'rb') as file: img_base64_src = base64.b64encode(file.read()).decode('utf-8') content_bytes = Environment(loader=BaseLoader).from_string( content_bytes) \ .render( first_name=claim['first_name'], last_name=claim['last_name'], email=claim['email'], street=claim['street'], city=claim['city'], state=claim['state'], zip_code=claim['zip_code'], type=claim['type'], timestamp=claim['timestamp'], description=claim['description'], img_base64_src=img_base64_src ) base64_file_content = base64.b64encode(bytes(content_bytes, 'utf-8')).decode('ascii') # Create the document model document = Document( # Create the DocuSign document object document_base64=base64_file_content, name='Submit a Claim', file_extension='html', document_id=1) # Create the signer recipient model signer = Signer( # The signer email=claim['email'], name=f"{claim['first_name']} {claim['last_name']}", recipient_id='1', routing_order='1', # Setting the client_user_id marks the signer as embedded client_user_id=envelope_args['signer_client_id']) # Create a sign_here tab (field on the document) sign_here = SignHere(anchor_string='/signature_1/', anchor_units='pixels', anchor_y_offset='10', anchor_x_offset='20') # Create an initials tab initial_here = InitialHere(anchor_string='/initials_1/', anchor_units='pixels', anchor_y_offset='10', anchor_x_offset='20') # Create an email field email = Email(document_id='1', page_number='1', anchor_string='/email/', anchor_units='pixels', required=True, value=claim['email'], locked=False, anchor_y_offset='-5') signer_attachment_tabs = SignerAttachment(anchor_string='/attachment/', anchor_y_offset='-20', anchor_units='pixels', anchor_x_offset='20', optional='true') signer.tabs = Tabs( sign_here_tabs=[sign_here], email_tabs=[email], initial_here_tabs=[initial_here], signer_attachment_tabs=[signer_attachment_tabs], ) # Create the top-level envelope definition and populate it envelope_definition = EnvelopeDefinition( email_subject='Submit a Claim', documents=[document], # The Recipients object takes arrays for each recipient type recipients=Recipients(signers=[signer]), status='sent' # Requests that the envelope be created and sent ) return envelope_definition
def embedded_signing_ceremony(filename, vname, vemail): """ The document <file_name> will be signed by <signer_name> via an embedded signing ceremony. """ # # Step 1. The envelope definition is created. # One signHere tab is added. # The document path supplied is relative to the working directory # # Create the component objects for the envelope definition... with open(filename, "rb") as file: content_bytes = file.read() base64_file_content = base64.b64encode(content_bytes).decode('ascii') document = Document( document_base64=base64_file_content, name='IPFS Document', # can be different from actual file name file_extension='pdf', # many different document types are accepted document_id=1 # a label used to reference the doc ) # Create the signer recipient model signer = Signer(email=vemail, name=vname, recipient_id="1", routing_order="1", client_user_id=settings.DOCU_CLIENT_ID) sign_here = SignHere(document_id='1', page_number='1', recipient_id='1', tab_label='IPFS Sign Request', x_position='200', y_position='147') # Add the tabs model (including the sign_here tab) to the signer signer.tabs = Tabs(sign_here_tabs=[ sign_here ]) # The Tabs object wants arrays of the different field/tab types # Next, create the top level envelope definition and populate it. envelope_definition = EnvelopeDefinition( email_subject="Please sign this document sent from IPFS", documents=[document], recipients=Recipients(signers=[signer]), status="sent") envelope_api = envelope_obj() results = envelope_api.create_envelope( settings.DOCU_ACCOUNT_ID, envelope_definition=envelope_definition) envelope_id = results.envelope_id recipient_view_request = RecipientViewRequest( authentication_method=settings.DOCU_AUTH_METHOD, client_user_id=settings.DOCU_CLIENT_ID, recipient_id='1', return_url=settings.DOCU_REDIRECT_URL, user_name=vname, email=vemail) results = envelope_api.create_recipient_view( settings.DOCU_ACCOUNT_ID, envelope_id, recipient_view_request=recipient_view_request) return results.url, envelope_id
def worker(cls, args): """ 1. Create an api client and construct API clients 2. Create and submit a bulk sending list 3. Create a draft envelope 4. Add custom fields to the envelope 5. Add recipients to the envelope 6. Initiate bulk envelope sending 7. Confirm sending success """ # Step 2. Construct your API headers api_client = create_api_client(base_path=args["base_path"], access_token=args["access_token"]) # Step 3. Submit a bulk list bulk_envelopes_api = BulkEnvelopesApi(api_client) bulk_sending_list = cls.create_bulk_sending_list(args["signers"]) bulk_list = bulk_envelopes_api.create_bulk_send_list( account_id=args["account_id"], bulk_sending_list=bulk_sending_list) bulk_list_id = bulk_list.list_id # Step 4. Create an envelope envelope_api = EnvelopesApi(api_client) envelope_definition = cls.make_draft_envelope() envelope = envelope_api.create_envelope( account_id=args["account_id"], envelope_definition=envelope_definition) envelope_id = envelope.envelope_id # Step 5. Attach your bulk list id to the envelope text_custom_fields = TextCustomField(name="mailingListId", required="false", show="false", value=bulk_list_id) custom_fields = CustomFields(list_custom_fields=[], text_custom_fields=[text_custom_fields]) envelope_api.create_custom_fields(account_id=args["account_id"], envelope_id=envelope_id, custom_fields=custom_fields) # Step 6. Add placeholder recipients cc = Signer(name="Multi Bulk Recipient::cc", email="*****@*****.**", role_name="cc", note="", routing_order="1", status="created", delivery_method="email", recipient_id="12", recipient_type="signer") signer = Signer(name="Multi Bulk Recipient::signer", email="*****@*****.**", role_name="signer", note="", routing_order="1", status="created", delivery_method="email", recipient_id="13", recipient_type="signer") envelope_api.create_recipient( account_id=args["account_id"], envelope_id=envelope_id, recipients=Recipients(signers=[signer, cc])) # Step 7. Initiate bulk send bulk_send_request = BulkSendRequest( envelope_or_template_id=envelope_id) batch = bulk_envelopes_api.create_bulk_send_request( account_id=args["account_id"], bulk_send_list_id=bulk_list_id, bulk_send_request=bulk_send_request) batch_id = batch.batch_id # Step 8. Confirm successful batch send response = bulk_envelopes_api.get(account_id=args["account_id"], batch_id=batch_id) return response
def send_envelope(self): self.check_token() # document 1 (html) has sign here anchor tag **signature_1** # document 2 (docx) has sign here anchor tag /sn1/ # document 3 (pdf) has sign here anchor tag /sn1/ # # The envelope has two recipients. # recipient 1 - signer # recipient 2 - cc # The envelope will be sent first to the signer. # After it is signed, a copy is sent to the cc person. args = { 'signer_email': DSConfig.signer_email(), 'signer_name': DSConfig.signer_name(), 'cc_email': DSConfig.cc_email(), 'cc_name': DSConfig.cc_name(), } # create the envelope definition env = EnvelopeDefinition(email_subject='Please sign this document set') doc1_b64 = base64.b64encode(bytes(self.create_document1(args), 'utf-8')).decode('ascii') # read files 2 and 3 from a local directory # The reads could raise an exception if the file is not available! with open(path.join(demo_docs_path, DOC_2_DOCX), "rb") as file: doc2_docx_bytes = file.read() doc2_b64 = base64.b64encode(doc2_docx_bytes).decode('ascii') with open(path.join(demo_docs_path, DOC_3_PDF), "rb") as file: doc3_pdf_bytes = file.read() doc3_b64 = base64.b64encode(doc3_pdf_bytes).decode('ascii') # Create the document models document1 = Document( # create the DocuSign document object document_base64=doc1_b64, name='Order acknowledgement', # can be different from actual file name file_extension='html', # many different document types are accepted document_id='1' # a label used to reference the doc ) document2 = Document( # create the DocuSign document object document_base64=doc2_b64, name='Battle Plan', # can be different from actual file name file_extension='docx', # many different document types are accepted document_id='2' # a label used to reference the doc ) document3 = Document( # create the DocuSign document object document_base64=doc3_b64, name='Lorem Ipsum', # can be different from actual file name file_extension='pdf', # many different document types are accepted document_id='3' # a label used to reference the doc ) # The order in the docs array determines the order in the envelope env.documents = [document1, document2, document3] # Create the signer recipient model signer1 = Signer(email=args['signer_email'], name=args['signer_name'], recipient_id="1", routing_order="1") # routingOrder (lower means earlier) determines the order of deliveries # to the recipients. Parallel routing order is supported by using the # same integer as the order for two or more recipients. # create a cc recipient to receive a copy of the documents cc1 = CarbonCopy(email=args['cc_email'], name=args['cc_name'], recipient_id="2", routing_order="2") # Create signHere fields (also known as tabs) on the documents, # We're using anchor (autoPlace) positioning # # The DocuSign platform searches throughout your envelope's # documents for matching anchor strings. So the # signHere2 tab will be used in both document 2 and 3 since they # use the same anchor string for their "signer 1" tabs. sign_here1 = SignHere(anchor_string='**signature_1**', anchor_units='pixels', anchor_y_offset='10', anchor_x_offset='20') sign_here2 = SignHere(anchor_string='/sn1/', anchor_units='pixels', anchor_y_offset='10', anchor_x_offset='20') # Add the tabs model (including the sign_here tabs) to the signer # The Tabs object wants arrays of the different field/tab types signer1.tabs = Tabs(sign_here_tabs=[sign_here1, sign_here2]) # Add the recipients to the envelope object recipients = Recipients(signers=[signer1], carbon_copies=[cc1]) env.recipients = recipients # Request that the envelope be sent by setting |status| to "sent". # To request that the envelope be created as a draft, set to "created" env.status = "sent" envelope_api = EnvelopesApi(SendEnvelope.api_client) results = envelope_api.create_envelope(SendEnvelope.accountID, envelope_definition=env) return results
def create_with_payment(cls, tpl, student, activity_info, envelope_args): """Create envelope with payment feature included Parameters: tpl (str): template path for the document student (dict}: student information activity_info (dict): activity information for enrollment envelope_args (dict): parameters for the envelope Returns: EnvelopeDefinition object that will be submitted to Docusign """ l1_name = activity_info['name'] l1_price = activity_info['price'] l1_description = f'${l1_price}' currency_multiplier = 100 # Read template and fill it up with open(path.join(TPL_PATH, tpl), 'r') as file: content_bytes = file.read() # Get base64 logo representation to paste it into the html with open(path.join(IMG_PATH, 'logo.png'), 'rb') as file: img_base64_src = base64.b64encode(file.read()).decode('utf-8') content_bytes = Environment( loader=BaseLoader).from_string(content_bytes).render( user_name=f"{student['first_name']} {student['last_name']}", user_email=student['email'], activity_name=l1_name, activity_price=l1_price, img_base64_src=img_base64_src) base64_file_content = base64.b64encode(bytes(content_bytes, 'utf-8')).decode('ascii') # Create the envelope definition envelope_definition = EnvelopeDefinition( email_subject='Register for extra-curricular activity') # Create the document doc1 = Document( document_base64=base64_file_content, name='Order form', # can be different from actual file name file_extension='html', # Source data format. document_id='1' # a label used to reference the doc ) envelope_definition.documents = [doc1] # Create a signer recipient to sign the document signer1 = Signer( email=student['email'], name=f"{student['first_name']} {student['last_name']}", recipient_id='1', routing_order='1', client_user_id=envelope_args['signer_client_id']) sign_here1 = SignHere(anchor_string='/sn1/', anchor_y_offset='10', anchor_units='pixels', anchor_x_offset='20') # Create number tab for the price numberl1e = Number( font='helvetica', font_size='size11', anchor_string='/l1e/', anchor_y_offset='-8', anchor_units='pixels', anchor_x_offset='-7', tab_label='l1e', formula=l1_price, required='true', locked='true', disable_auto_size='false', ) # Create formula tab for the total formula_total = FormulaTab( font='helvetica', bold='true', font_size='size12', anchor_string='/l2t/', anchor_y_offset='-6', anchor_units='pixels', anchor_x_offset='30', tab_label='l2t', formula='[l1e]', round_decimal_places='2', required='true', locked='true', disable_auto_size='false', ) # Create payment line items payment_line_iteml1 = PaymentLineItem(name=l1_name, description=l1_description, amount_reference='l1e') payment_details = PaymentDetails( gateway_account_id=envelope_args['gateway_account_id'], currency_code='USD', gateway_name=envelope_args['gateway_name'], line_items=[payment_line_iteml1]) # Create hidden formula tab for the payment itself formula_payment = FormulaTab( tab_label='payment', formula=f'{l1_price} * {currency_multiplier}', round_decimal_places='2', payment_details=payment_details, hidden='true', required='true', locked='true', document_id='1', page_number='1', x_position='0', y_position='0') # Create tabs for signer signer1_tabs = Tabs(sign_here_tabs=[sign_here1], formula_tabs=[formula_payment, formula_total], number_tabs=[numberl1e]) signer1.tabs = signer1_tabs # Add the recipients to the envelope object recipients = Recipients(signers=[signer1]) envelope_definition.recipients = recipients # Request that the envelope be sent by setting |status| to 'sent'. envelope_definition.status = 'sent' return envelope_definition
def make_envelope(cls, args): """ Creates envelope Document: A txt document. DocuSign will convert document to the PDF format. """ # The envelope has two recipients # Recipient 1 - signer1 # Recipient 2 - signer_2a or signer_2b # The envelope will be sent first to signer1 # If signer1 doesn't check the checkbox the envelope will be sent to the signer_2a # If signer1 check the checkbox the envelope will be sent to the signer_2b # Create the envelope definition env = EnvelopeDefinition(email_subject="ApproveIfChecked") # Read file from a local directory # The reads could raise an exception if the file is not available with open(path.join(demo_docs_path, DS_CONFIG["doc_txt"]), "rb") as file: doc_docx_bytes = file.read() doc_b64 = base64.b64encode(doc_docx_bytes).decode("ascii") # Create the document model. document = Document( # Create the DocuSign document object document_base64=doc_b64, name="Welcome", # Can be different from actual file name file_extension="txt", # Many different document types are accepted document_id="1" # A label used to reference the doc ) env.documents = [document, ] # Create the signer model # routingOrder (lower means earlier) determines the order of deliveries to the recipients signer1 = Signer( email=args["signer1_email"], name=args["signer1_name"], recipient_id="1", routing_order="1", role_name="Purchaser" ) signer2 = Signer( email="*****@*****.**", name="Approver", recipient_id="2", routing_order="2", role_name="Approver" ) # Create signHere fieldы (also known as tabs) on the documents sign_here1 = SignHere( document_id="1", page_number="1", name="SignHere", tab_label="PurchaserSignature", x_position="200", y_position="200" ) sign_here2 = SignHere( document_id="1", page_number="1", name="SignHere", recipient_id="2", tab_label="ApproverSignature", x_position="300", y_position="200" ) # Create checkbox field on the documents checkbox = Checkbox( document_id="1", page_number="1", name="ClickToApprove", selected="false", tab_label="ApproveWhenChecked", x_position="50", y_position="50" ) # Add the tabs models (including the sign_here tabs) to the signer # The Tabs object wants arrays of the different field/tab types signer1.tabs = Tabs( sign_here_tabs=[sign_here1, ], checkbox_tabs=[checkbox, ] ) signer2.tabs = Tabs(sign_here_tabs=[sign_here2, ]) # Add the recipients to the envelope object env_recipients = Recipients(signers=[signer1, signer2]) # env_recipients = Recipients(signers=[signer1, ]) env.recipients = env_recipients # Create recipientOption models signer_2a = RecipientOption( email=args["signer_2a_email"], name=args["signer_2a_name"], role_name="Signer when not checked", recipient_label="signer2a" ) signer_2b = RecipientOption( email=args["signer_2b_email"], name=args["signer_2b_name"], role_name="Signer when checked", recipient_label="signer2b" ) recipients = [signer_2a, signer_2b] # Create recipientGroup model recipient_group = RecipientGroup( group_name="Approver", group_message="Members of this group approve a workflow", recipients=recipients ) # Create conditionalRecipientRuleFilter models filter1 = ConditionalRecipientRuleFilter( scope="tabs", recipient_id="1", tab_id="ApprovalTab", operator="equals", value="false", tab_label="ApproveWhenChecked" ) filter2 = ConditionalRecipientRuleFilter( scope="tabs", recipient_id="1", tab_id="ApprovalTab", operator="equals", value="true", tab_label="ApproveWhenChecked" ) # Create conditionalRecipientRuleCondition models condition1 = ConditionalRecipientRuleCondition( filters=[filter1, ], order="1", recipient_label="signer2a" ) condition2 = ConditionalRecipientRuleCondition( filters=[filter2, ], order="2", recipient_label="signer2b" ) conditions = [condition1, condition2] # Create conditionalRecipientRule model conditional_recipient = ConditionalRecipientRule( conditions=conditions, recipient_group=recipient_group, recipient_id="2", order="0", ) # Create recipientRules model rules = RecipientRules(conditional_recipients=[conditional_recipient, ]) recipient_routing = RecipientRouting(rules=rules) # Create a workflow model workflow_step = WorkflowStep( action="pause_before", trigger_on_item="routing_order", item_id="2", status="pending", recipient_routing=recipient_routing ) workflow = Workflow(workflow_steps=[workflow_step, ]) # Add the workflow to the envelope object env.workflow = workflow # Request that the envelope be sent by setting |status| to "sent" # To request that the envelope be created as a draft, set to "created" env.status = args["status"] return env
def worker(args): """ 1. Create an api client 2. Create an envelope definition object """ # Step 1: Construct your API headers api_client = create_api_client(base_path=args["base_path"], access_token=args["access_token"]) # Step 3: Construct your envelope envelope_definition = EnvelopeDefinition( email_subject="Please sign this document set") # Open the example file with open(path.join(demo_docs_path, DS_CONFIG["doc_pdf"]), "rb") as file: content_bytes = file.read() base64_file_content = base64.b64encode(content_bytes).decode("ascii") # Add a document document1 = Document( # create the DocuSign document object document_base64=base64_file_content, document_id="1", # a label used to reference the doc file_extension="pdf", # many different document types are accepted name="Lorem" # can be different from actual file name ) envelope_definition.documents = [document1] envelope_definition.status = args["envelope_args"]["status"] # Create your signature tab sign_here1 = SignHere( name="SignHereTab", x_position="75", y_position="572", tab_label="SignHereTab", page_number="1", document_id="1", # A 1- to 8-digit integer or 32-character GUID to match recipient IDs on your own systems. # This value is referenced in the Tabs element below to assign tabs on a per-recipient basis. recipient_id="1" # represents your {RECIPIENT_ID} ) signer1 = Signer( email=args["envelope_args"] ["signer_email"], # Represents your {signer_email} name=args["envelope_args"] ["signer_name"], # Represents your {signer_name} role_name="", note="", status="created", delivery_method="email", recipient_id="1", # Represents your {RECIPIENT_ID} routing_order="1", identity_verification={ "workflowId": args["envelope_args"]["workflow_id"], "steps": "null" }, tabs=Tabs(sign_here_tabs=[sign_here1])) # Tabs are set per recipient envelope_definition.recipients = Recipients(signers=[signer1]) # Step 4: Call the eSignature REST API envelopes_api = EnvelopesApi(api_client) results = envelopes_api.create_envelope( account_id=args["account_id"], envelope_definition=envelope_definition) return results
def create_with_payment(cls, tpl, user, insurance_info, envelope_args): """Create envelope with payment feature included Parameters: tpl (str): Template path for the document user (dict}: User information insurance_info (dict): Insurance information for enrollment envelope_args (dict): Parameters for the envelope Returns: EnvelopeDefinition object that will be submitted to Docusign """ currency_multiplier = 100 discount_percent = 5 insurance_rate_percent = 10 # Read template and fill it up with open(path.join(TPL_PATH, tpl), 'r') as file: content_bytes = file.read() # Get base64 logo representation to paste it into the HTML file with open(path.join(IMG_PATH, 'logo.png'), 'rb') as file: img_base64_src = base64.b64encode(file.read()).decode('utf-8') content_bytes = Environment( loader=BaseLoader).from_string(content_bytes).render( user_name=f"{user['first_name']} {user['last_name']}", user_email=user['email'], address=f"{user['street']}, {user['city']}, {user['state']}", zip_code=user['zip_code'], detail_1=insurance_info['detail1']['name'], detail_2=insurance_info['detail2']['name'], value_detail_1=insurance_info['detail1']['value'], value_detail_2=insurance_info['detail2']['value'], img_base64_src=img_base64_src) base64_file_content = base64.b64encode(bytes(content_bytes, 'utf-8')).decode('ascii') # Create the envelope definition envelope_definition = EnvelopeDefinition( email_subject='Buy New Insurance') # Create the document doc1 = Document( document_base64=base64_file_content, name= 'Insurance order form', # Can be different from actual file name file_extension='html', # Source data format document_id='1' # A label used to reference the doc ) envelope_definition.documents = [doc1] # Create a signer recipient to sign the document signer1 = Signer(email=user['email'], name=f"{user['first_name']} {user['last_name']}", recipient_id='1', routing_order='1', client_user_id=envelope_args['signer_client_id']) sign_here1 = SignHere( anchor_string='/sn1/', anchor_y_offset='10', anchor_units='pixels', anchor_x_offset='20', ) # Create number tabs for the coverage amount and deductible coverage = Number( font='helvetica', font_size='size11', anchor_string='/l1e/', anchor_y_offset='-7', anchor_units='pixels', tab_label='l1e', required='true', ) deductible = Number( font='helvetica', font_size='size11', anchor_string='/l2e/', anchor_y_offset='-7', anchor_units='pixels', tab_label='l2e', required='true', ) # Create checkbox and trigger tabs to apply the discount checkbox = Checkbox( font='helvetica', font_size='size11', anchor_string='/cb/', anchor_y_offset='-4', anchor_units='pixels', anchor_x_offset='-8', tab_label='checkbox', height='50', bold='true', ) trigger = FormulaTab( anchor_string='/trigger/', font_color='white', anchor_y_offset='10', tab_label='trigger', conditional_parent_label='checkbox', conditional_parent_value='on', formula='1', required='true', locked='true', ) discount = FormulaTab( font='helvetica', font_size='size11', bold='true', anchor_string='/dt/', anchor_y_offset='-4', anchor_units='pixels', anchor_x_offset='0', tab_label='discount', formula=f"if([trigger] > 0, {discount_percent}, 0)", round_decimal_places='0', locked='true', ) # Create a formula tab for the insurance price total = f'([l1e]-[l2e]) * {insurance_rate_percent}/100' formula_total = FormulaTab( font='helvetica', bold='true', font_size='size12', anchor_string='/l4t/', anchor_y_offset='-6', anchor_units='pixels', anchor_x_offset='84', tab_label='l4t', formula=f'({total}) - (({total}) * [discount]/100)', round_decimal_places='2', required='true', locked='true', ) # Create payment line item payment_line_iteml1 = PaymentLineItem(name='Insurance payment', description='$[l4t]', amount_reference='l4t') payment_details = PaymentDetails( gateway_account_id=envelope_args['gateway_account_id'], currency_code='USD', gateway_name=envelope_args['gateway_name'], line_items=[payment_line_iteml1]) # Create a hidden formula tab for the payment itself formula_payment = FormulaTab( tab_label='payment', formula=f'([l4t]) * {currency_multiplier}', round_decimal_places='2', payment_details=payment_details, hidden='true', required='true', locked='true', document_id='1', page_number='1', x_position='0', y_position='0') # Create tabs for the signer signer1_tabs = Tabs( sign_here_tabs=[sign_here1], number_tabs=[coverage, deductible], formula_tabs=[formula_payment, formula_total, discount, trigger], checkbox_tabs=[checkbox]) signer1.tabs = signer1_tabs # Add the recipients to the envelope object recipients = Recipients(signers=[signer1]) envelope_definition.recipients = recipients # Request that the envelope be sent by setting status to 'sent' envelope_definition.status = 'sent' return envelope_definition
def make_envelope(cls, args): """ Creates envelope args -- parameters for the envelope: signer_email, signer_name, signer_client_id returns an envelope definition """ # Document 1 (PDF) has tag /sn1/ # # The envelope has one recipient: # recipient 1 - signer with open(path.join(demo_docs_path, DS_CONFIG["doc_salary_docx"]), "rb") as file: content_bytes = file.read() base64_file_content = base64.b64encode(content_bytes).decode("ascii") # Create the document model document = Document( # Create the DocuSign document object document_base64=base64_file_content, name="Lorem Ipsum", # Can be different from the actual filename file_extension="docx", # Many different document types are accepted document_id=1 # A label used to reference the doc ) # Create the signer recipient model signer = Signer( # The signer email=args["signer_email"], name=args["signer_name"], recipient_id="1", routing_order="1", # Setting the client_user_id marks the signer as embedded client_user_id=args["signer_client_id"] ) # Create a SignHere tab (field on the document) sign_here = SignHere( # DocuSign SignHere field/tab anchor_string="/sn1/", anchor_units="pixels", anchor_y_offset="10", anchor_x_offset="20" ) text_legal = Text( anchor_string="/legal/", anchor_units="pixels", anchor_y_offset="-9", anchor_x_offset="5", font="helvetica", font_size="size11", bold="true", value=args["signer_name"], locked="false", tab_id="legal_name", tab_label="Legal name") text_familar = Text( anchor_string="/familiar/", anchor_units="pixels", anchor_y_offset="-9", anchor_x_offset="5", font="helvetica", font_size="size11", bold="true", value=args["signer_name"], locked="false", tab_id="familar_name", tab_label="Familiar name") salary = 123000 text_salary = Text( anchor_string="/salary/", anchor_units="pixels", anchor_y_offset="-9", anchor_x_offset="5", font="helvetica", font_size="size11", bold="true", value="${:.2f}".format(salary), locked="true", tab_id="salary", tab_label="Salary") salary_custom_field = TextCustomField( name="salary", required="false", show="true", # Yes, include in the CoC value=str(salary) ) cf = CustomFields(text_custom_fields=[salary_custom_field]) # Add the tabs model (including the SignHere tab) to the signer # The Tabs object wants arrays of the different field/tab types signer.tabs = Tabs(sign_here_tabs=[sign_here], text_tabs=[text_legal, text_familar, text_salary]) # Create the top level envelope definition and populate it envelope_definition = EnvelopeDefinition( email_subject="Please sign this document sent from the Python SDK", documents=[document], # The Recipients object wants arrays for each recipient type recipients=Recipients(signers=[signer]), custom_fields=cf, status="sent" # Requests that the envelope be created and sent ) return envelope_definition
def make_template_req(cls): """Creates template req object""" # document 1 (pdf) # # The template has two recipient roles. # recipient 1 - signer # recipient 2 - cc with open(path.join(demo_docs_path, doc_file), "rb") as file: content_bytes = file.read() base64_file_content = base64.b64encode(content_bytes).decode("ascii") # Create the document model document = Document( # create the DocuSign document object document_base64=base64_file_content, name="Lorem Ipsum", # can be different from actual file name file_extension="pdf", # many different document types are accepted document_id=1 # a label used to reference the doc ) # Create the signer recipient model signer = Signer(role_name="signer", recipient_id="1", routing_order="1") # create a cc recipient to receive a copy of the envelope (transaction) cc = CarbonCopy(role_name="cc", recipient_id="2", routing_order="2") # Create fields using absolute positioning # Create a sign_here tab (field on the document) sign_here = SignHere(document_id="1", page_number="1", x_position="191", y_position="148") check1 = Checkbox(document_id="1", page_number="1", x_position="75", y_position="417", tab_label="ckAuthorization") check2 = Checkbox(document_id="1", page_number="1", x_position="75", y_position="447", tab_label="ckAuthentication") check3 = Checkbox(document_id="1", page_number="1", x_position="75", y_position="478", tab_label="ckAgreement") check4 = Checkbox(document_id="1", page_number="1", x_position="75", y_position="508", tab_label="ckAcknowledgement") list1 = List(document_id="1", page_number="1", x_position="142", y_position="291", font="helvetica", font_size="size14", tab_label="list", required="false", list_items=[ ListItem(text="Red", value="red"), ListItem(text="Orange", value="orange"), ListItem(text="Yellow", value="yellow"), ListItem(text="Green", value="green"), ListItem(text="Blue", value="blue"), ListItem(text="Indigo", value="indigo"), ListItem(text="Violet", value="violet") ]) number1 = Number(document_id="1", page_number="1", x_position="163", y_position="260", font="helvetica", font_size="size14", tab_label="numbersOnly", width="84", required="false") radio_group = RadioGroup(document_id="1", group_name="radio1", radios=[ Radio(page_number="1", x_position="142", y_position="384", value="white", required="false"), Radio(page_number="1", x_position="74", y_position="384", value="red", required="false"), Radio(page_number="1", x_position="220", y_position="384", value="blue", required="false") ]) text = Text(document_id="1", page_number="1", x_position="153", y_position="230", font="helvetica", font_size="size14", tab_label="text", height="23", width="84", required="false") # Add the tabs model to the signer # The Tabs object wants arrays of the different field/tab types signer.tabs = Tabs(sign_here_tabs=[sign_here], checkbox_tabs=[check1, check2, check3, check4], list_tabs=[list1], number_tabs=[number1], radio_group_tabs=[radio_group], text_tabs=[text]) # Top object: template_request = EnvelopeTemplate( documents=[document], email_subject="Please sign this document", recipients=Recipients(signers=[signer], carbon_copies=[cc]), description="Example template created via the API", name=template_name, shared="false", status="created") return template_request
def embedded_signing_ceremony(): """ The document <file_name> will be signed by <signer_name> via an embedded signing ceremony. """ # # Step 1. The envelope definition is created. # One signHere tab is added. # The document path supplied is relative to the working directory # '''with open(os.path.join(APP_PATH, file_name_path), "rb") as file: content_bytes = file.read()''' base64_file_content = '' #base64.b64encode(content_bytes).decode('ascii') # Create the document model '''document = Document( # create the DocuSign document object document_base64 = base64_file_content, name = 'Example document', # can be different from actual file name file_extension = 'pdf', # many different document types are accepted document_id = 1 # a label used to reference the doc )''' '''text_field = docusign.Text( tab_label='name', # tab_label must exactly match the field you created in the Docusign GUI value='Manuel' # value, as far as I can tell, must be a string. ) docusign.Tabs(text_tabs=[text_field])''' patient_first_name = TextCustomField(name='name', value='Allen', show='true', required='false') patient_last_name = TextCustomField(name='lastname', value='Elks', show='true', required='false') custom_fields = CustomFields( text_custom_fields=[patient_first_name, patient_last_name]) # envelope_definition.custom_fields = custom_fields # Custome fields custom_fields_old = CustomFields(['name'], ['Manuel']) # Create the signer recipient model signer = Signer( # The signer email=signer_email, name=signer_name, recipient_id="1", routing_order="1", client_user_id= client_user_id, # Setting the client_user_id marks the signer as embedded ) # Create a sign_here tab (field on the document) sign_here = SignHere( # DocuSign SignHere field/tab document_id='1', page_number='3', recipient_id='1', tab_label='SignHereTab', x_position='175', y_position='320') # Add the tabs model (including the sign_here tab) to the signer signer.tabs = Tabs(sign_here_tabs=[ sign_here ]) # The Tabs object wants arrays of the different field/tab types # Next, create the top level envelope definition and populate it. '''envelope_definition = EnvelopeDefinition( email_subject = "Please sign this document sent from the Python SDK", documents = [document], # The order in the docs array determines the order in the envelope recipients = Recipients(signers = [signer]), # The Recipients object wants arrays for each recipient type status = "sent", # requests that the envelope be created and sent. custom_fields = custom_fields )''' envDef = EnvelopeDefinition() envDef.email_subject = 'PLEASE GOD HELP ME, I NEED THIS WORKING!!' envDef.template_id = 'd5e617be-da0a-4431-9014-4575282f61d4' tRole = TemplateRole() tRole.role_name = 'Manager' tRole.name = 'Manuel Alejandro Galvez' tRole.email = '*****@*****.**' envDef.template_roles = [tRole] envDef.status = 'sent' envDef.custom_fields = custom_fields # # Step 2. Create/send the envelope. # api_client = ApiClient() api_client.host = base_path api_client.set_default_header("Authorization", "Bearer " + access_token) envelope_api = EnvelopesApi(api_client) results = envelope_api.create_envelope(account_id, envelope_definition=envDef) # # Step 3. The envelope has been created. # Request a Recipient View URL (the Signing Ceremony URL) # envelope_id = results.envelope_id recipient_view_request = RecipientViewRequest( authentication_method=authentication_method, client_user_id=client_user_id, recipient_id='1', return_url=base_url + '/dsreturn', user_name=signer_name, email=signer_email) results = envelope_api.create_recipient_view(account_id, envelope_id) #recipient_view_request = recipient_view_request) # # Step 4. The Recipient View URL (the Signing Ceremony URL) has been received. # Redirect the user's browser to it. # return results.url
def worker(args): """ 1. Create an api client 2. Create an envelope definition object 3. Call the eSignature REST API using the SDK """ # Step 1: Construct your API headers api_client = create_api_client(base_path=args["base_path"], access_token=args["access_token"]) # Step 2: Construct your envelope envelope_definition = EnvelopeDefinition( email_subject="Please sign this document set" ) # Open the example file with open(path.join(demo_docs_path, DS_CONFIG["doc_pdf"]), "rb") as file: content_bytes = file.read() base64_file_content = base64.b64encode(content_bytes).decode("ascii") # Add a Document document1 = Document( # create the DocuSign document object document_base64=base64_file_content, document_id="1", # a label used to reference the doc file_extension="pdf", # many different document types are accepted name="Lorem" # can be different from actual file name ) envelope_definition.documents = [document1] envelope_definition.status = args["envelope_args"]["status"] signer1 = Signer( email=args["envelope_args"]["signer_email"], # represents your {signer_email} name=args["envelope_args"]["signer_name"], # represents your {signer_name} phone_authentication={"senderProvidedNumbers": [args["envelope_args"]["phone_number"]]}, id_check_configuration_name="Phone Auth $", require_id_lookup="true", recipient_id="1", routing_order="1" ) # Create your signature tab sign_here1 = SignHere( name="SignHereTab", x_position="75", y_position="572", tab_label="SignHereTab", page_number="1", document_id="1", # A 1- to 8-digit integer or 32-character GUID to match recipient IDs on your own systems. # This value is referenced in the Tabs element below to assign tabs on a per-recipient basis. recipient_id="1" # represents your {RECIPIENT_ID} ) # Add the tabs model (including the sign_here tabs) to the signer # The Tabs object wants arrays of the different field/tab types signer1.tabs = Tabs(sign_here_tabs=[sign_here1]) # Tabs are set per recipient envelope_definition.recipients = Recipients(signers=[signer1]) # Step 3: Call the eSignature REST API envelope_api = EnvelopesApi(api_client) results = envelope_api.create_envelope(account_id=args["account_id"], envelope_definition=envelope_definition) return results
def make_envelope(cls, args): """ Creates envelope: document 1 (HTML) has signHere anchor tag: **signature_1** document 2 (DOCX) has signHere anchor tag: /sn1/ document 3 (PDF) has signHere anchor tag: /sn1/ DocuSign will convert all of the documents to the PDF format. The recipient’s field tags are placed using anchor strings. The envelope has two recipients: recipient 1: signer recipient 2: cc The envelope will be sent first to the signer via SMS. After it is signed, a copy is sent to the cc recipient via SMS. """ # Create the envelope definition env = EnvelopeDefinition(email_subject="Please sign this document set") doc1_b64 = base64.b64encode(bytes(cls.create_document1(args), "utf-8")).decode("ascii") # Read files 2 and 3 from a local folder # The reads could raise an exception if the file is not available! with open(path.join(demo_docs_path, DS_CONFIG["doc_docx"]), "rb") as file: doc2_docx_bytes = file.read() doc2_b64 = base64.b64encode(doc2_docx_bytes).decode("ascii") with open(path.join(demo_docs_path, DS_CONFIG["doc_pdf"]), "rb") as file: doc3_pdf_bytes = file.read() doc3_b64 = base64.b64encode(doc3_pdf_bytes).decode("ascii") # Create the document models document1 = Document( # Create the DocuSign document object document_base64=doc1_b64, name= "Order acknowledgement", # Can be different from actual file name file_extension="html", # Many different document types are accepted document_id="1" # A label used to reference the doc ) document2 = Document( # Create the DocuSign document object document_base64=doc2_b64, name="Battle Plan", # Can be different from actual file name file_extension="docx", # Many different document types are accepted document_id="2" # A label used to reference the doc ) document3 = Document( # Create the DocuSign document object document_base64=doc3_b64, name="Lorem Ipsum", # Can be different from actual file name file_extension="pdf", # Many different document types are accepted document_id="3" # A label used to reference the doc ) # The order in the docs array determines the order in the envelope env.documents = [document1, document2, document3] phoneNumber = RecipientPhoneNumber(country_code=args["country_code"], number=args["phone_number"]) sms_notification = RecipientAdditionalNotification( phone_number=phoneNumber) sms_notification.secondary_delivery_method = "SMS" # Create the signer recipient model signer1 = Signer(email=args["signer_email"], name=args["signer_name"], recipient_id="1", routing_order="1", additional_notifications=[sms_notification]) # Create a RecipientPhoneNumber and add it to the additional SMS notification ccPhoneNumber = RecipientPhoneNumber( country_code=args["cc_country_code"], number=args["cc_phone_number"]) cc_sms_notification = RecipientAdditionalNotification( phone_number=ccPhoneNumber) cc_sms_notification.secondary_delivery_method = "SMS" # Create a cc recipient to receive a copy of the documents cc1 = CarbonCopy(email=args["cc_email"], name=args["cc_name"], recipient_id="2", routing_order="2", additional_notifications=[cc_sms_notification]) # routingOrder (lower means earlier) determines the order of deliveries # to the recipients. Parallel routing order is supported by using the # same integer as the order for two or more recipients # Create signHere fields (also known as tabs) on the documents # We're using anchor (autoPlace) positioning # # The DocuSign platform searches throughout your envelope"s # documents for matching anchor strings. So the # signHere2 tab will be used in both document 2 and 3 since they # use the same anchor string for their "signer 1" tabs sign_here1 = SignHere(anchor_string="**signature_1**", anchor_units="pixels", anchor_y_offset="10", anchor_x_offset="20") sign_here2 = SignHere(anchor_string="/sn1/", anchor_units="pixels", anchor_y_offset="10", anchor_x_offset="20") # Add the tabs model (including the SignHere tabs) to the signer # The Tabs object wants arrays of the different field/tab types signer1.tabs = Tabs(sign_here_tabs=[sign_here1, sign_here2]) # Add the recipients to the envelope object recipients = Recipients(signers=[signer1], carbon_copies=[cc1]) env.recipients = recipients # Request that the envelope be sent by setting status to "sent" # To request that the envelope be created as a draft, set to "created" env.status = args["status"] return env