コード例 #1
0
    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
コード例 #2
0
    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
コード例 #3
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