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 make_envelope(cls, args): """ Creates envelope args -- parameters for the envelope: signer_email, signer_name, signer_client_id returns an envelope definition """ # Set the values for the fields in the template # List item list1 = List(value="green", document_id="1", page_number="1", tab_label="list") # Checkboxes check1 = Checkbox(tab_label="ckAuthorization", selected="true") check3 = Checkbox(tab_label="ckAgreement", selected="true") radio_group = RadioGroup( group_name="radio1", radios=[Radio(value="white", selected="true")]) text = Text(tab_label="text", value="Jabberywocky!") # We can also add a new tab (field) to the ones already in the template: text_extra = Text(document_id="1", page_number="1", x_position="280", y_position="172", font="helvetica", font_size="size14", tab_label="added text field", height="23", width="84", required="false", bold="true", value=args["signer_name"], locked="false", tab_id="name") # Add the tabs model (including the SignHere tab) to the signer. # The Tabs object wants arrays of the different field/tab types # Tabs are set per recipient / signer tabs = Tabs(checkbox_tabs=[check1, check3], radio_group_tabs=[radio_group], text_tabs=[text, text_extra], list_tabs=[list1]) # create a signer recipient to sign the document, identified by name and email # We"re setting the parameters via the object creation signer = TemplateRole( # The signer email=args["signer_email"], name=args["signer_name"], # Setting the client_user_id marks the signer as embedded client_user_id=args["signer_client_id"], role_name="signer", tabs=tabs) cc = TemplateRole(email=args["cc_email"], name=args["cc_name"], role_name="cc") # create an envelope custom field to save our application"s # data about the envelope custom_field = TextCustomField( name="app metadata item", required="false", show="true", # Yes, include in the CoC value="1234567") cf = CustomFields(text_custom_fields=[custom_field]) # Next, create the top level envelope definition and populate it. envelope_definition = EnvelopeDefinition( email_subject="Please sign this document sent from the Python SDK", # The Recipients object wants arrays for each recipient type template_id=session["template_id"], template_roles=[signer, cc], custom_fields=cf, status="sent" # requests that the envelope be created and sent. ) return envelope_definition
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 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