Beispiel #1
0
    def create_envelope(self):
        envelope_definition = EnvelopeDefinition()
        envelope_definition.email_subject = "Please sign this document sent from the Python SDK"

        doc1 = create_document("1", "Order acknowledgement", "html",
                               ENVELOPE_1_DOCUMENT_1)
        doc2 = create_document("2", "Battle Plan", "docx",
                               DSHelper.read_content(DOC_2_DOCX))
        doc3 = create_document("3", "Lorem Ipsum", "pdf",
                               DSHelper.read_content(DOC_3_PDF))

        # The order in the docs array determines the order in the envelope
        envelope_definition.documents = [doc1, doc2, doc3]
        # create a signer recipient to sign the document, identified by name and email
        # We're setting the parameters via the object creation
        signer1 = createSigner()
        # 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, identified by name and email
        # We're setting the parameters via setters
        cc1 = createCarbonCopy()
        # 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
        # sign_here_2 tab will be used in both document 2 and 3 since they
        # use the same anchor string for their "signer 1" tabs.
        sign_here1 = createSignHere("**signature_1**", "pixels", "20", "10")
        sign_here2 = createSignHere("/sn1/", "pixels", "20", "10")
        # Tabs are set per recipient / signer
        setSignerTabs(signer1, [sign_here1, sign_here2])
        # Add the recipients to the envelope object
        recipients = createRecipients(signer1, 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 = "sent"

        return envelope_definition
    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
Beispiel #3
0
    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 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
Beispiel #5
0
    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 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
Beispiel #7
0
    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 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
Beispiel #9
0
    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
Beispiel #10
0
    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 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
Beispiel #12
0
    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