Ejemplo n.º 1
0
    def resend_envelope(self, envelope_id):
        """
        Re-sends the envelope to the user if they need it again (i.e they deleted it or something)

        :param envelope_id: (string) -> The envelope_id stored on docusign
        :return: (boolean) -> True: The document was successfully resent
                              False; The document was not able to be resent
        """

        # Initialize the envelope api
        envelopes_api = EnvelopesApi()

        try:
            # Add the signer (it is 1 since there should only be one signer per document)
            signer = docusign.Signer()
            signer.recipient_id = 1

            # Add the signer to a recipient list
            recipients = docusign.Recipients()
            recipients.signers = [signer]

            # Queries docusign and tells it to resend that envelope
            recipients_update_summary = envelopes_api.update_recipients(
                self.account_id,
                envelope_id,
                recipients=recipients,
                resend_envelope='true')
            assert recipients_update_summary is not None, "Recipients update summary is None"
            assert len(recipients_update_summary.recipient_update_results) > 0, "Length of recipient_update_results" \
                                                                                "is not >0"
            assert ("SUCCESS" == recipients_update_summary.recipient_update_results[0].error_details.error_code), \
                "The error code" \
                "was not success"
            print("RecipientsUpdateSummary: ", end="")

            return True

        except ApiException as e:
            logger.error(
                "\nException in {0} when calling DocuSign API: {1}".format(
                    DocusignWrapper.resend_envelope.__name__, e))
            return False
    def testResendEnvelope(self):
        with open(SignTest1File, 'rb') as sign_file:
            file_contents = sign_file.read()

        # create an envelope to be signed
        envelope_definition = docusign.EnvelopeDefinition()
        envelope_definition.email_subject = 'Please Sign my Python SDK Envelope'
        envelope_definition.email_blurb = 'Hello, Please sign my Python SDK Envelope.'

        # add a document to the envelope
        doc = docusign.Document()
        base64_doc = base64.b64encode(file_contents).decode("utf-8")
        doc.document_base64 = base64_doc
        doc.name = 'TestFile.pdf'
        doc.document_id = '1'
        envelope_definition.documents = [doc]

        # Add a recipient to sign the document
        signer = docusign.Signer()
        signer.email = Username
        signer.name = 'Pat Developer'
        signer.recipient_id = '1'

        # this value represents the client's unique identifier for the signer
        client_user_id = '2939'
        signer.client_user_id = client_user_id

        # Create a SignHere tab somewhere on the document for the signer to sign
        sign_here = docusign.SignHere()
        sign_here.document_id = '1'
        sign_here.page_number = '1'
        sign_here.recipient_id = '1'
        sign_here.x_position = '100'
        sign_here.y_position = '100'
        sign_here.scale_value = '0.5'

        tabs = docusign.Tabs()
        tabs.sign_here_tabs = [sign_here]
        signer.tabs = tabs

        recipients = docusign.Recipients()
        recipients.signers = [signer]
        envelope_definition.recipients = recipients

        # send the envelope (otherwise it will be "created" in the Draft folder)
        envelope_definition.status = 'sent'

        envelopes_api = EnvelopesApi()

        try:
            docusign.configuration.api_client = self.api_client

            recipients_update_summary = envelopes_api.update_recipients(
                self.user_info.accounts[0].account_id,
                self.envelope_id,
                recipients=recipients,
                resend_envelope='true')
            assert recipients_update_summary is not None
            assert len(recipients_update_summary.recipient_update_results) > 0
            assert ("SUCCESS" == recipients_update_summary.
                    recipient_update_results[0].error_details.error_code)
            print("RecipientsUpdateSummary: ", end="")
            pprint(recipients_update_summary)

        except ApiException as e:
            print("\nException when calling DocuSign API: %s" % e)
            assert e is None  # make the test case fail in case of an API exception
    def testResendEnvelope(self):
        with open(SignTest1File, 'rb') as sign_file:
            file_contents = sign_file.read()

        # Set properties and create an envelope to be signed later on
        email_subject = 'Please Sign my Python SDK Envelope'
        email_blurb = 'Hello, Please sign my Python SDK Envelope.'

        # add a document to the envelope
        base64_doc = base64.b64encode(file_contents).decode("utf-8")
        name = 'TestFile.pdf'
        document_id = '1'
        doc = docusign.Document(document_base64=base64_doc,
                                name=name,
                                document_id=document_id)
        documents = [doc]

        # this value represents the client's unique identifier for the signer
        client_user_id = '2939'

        # Create a SignHere tab somewhere on the document for the signer to sign
        document_id = '1'
        page_number = '1'
        recipient_id = '1'
        x_position = '100'
        y_position = '100'
        scale_value = '0.5'

        sign_here = docusign.SignHere(document_id=document_id,
                                      page_number=page_number,
                                      recipient_id=recipient_id,
                                      x_position=x_position,
                                      y_position=y_position,
                                      scale_value=scale_value)
        sign_here_tabs = [sign_here]
        tabs = docusign.Tabs(sign_here_tabs=sign_here_tabs)

        # Add a recipient to sign the document
        email = Username
        name = 'Pat Developer'
        signer_recipient_id = '1'
        # Create the signer with the information created previous
        signer = docusign.Signer(tabs=tabs,
                                 email=email,
                                 name=name,
                                 recipient_id=signer_recipient_id,
                                 client_user_id=client_user_id)
        signers = [signer]
        recipients = docusign.Recipients(signers=signers)

        # send the envelope (otherwise it will be "created" in the Draft folder)
        status = 'sent'

        # create an envelope to be signed
        envelope_definition = docusign.EnvelopeDefinition(
            email_subject=email_subject,
            email_blurb=email_blurb,
            documents=documents,
            recipients=recipients,
            status=status)

        envelopes_api = EnvelopesApi()

        try:
            docusign.configuration.api_client = self.api_client

            recipients_update_summary = envelopes_api.update_recipients(
                self.user_info.accounts[0].account_id,
                self.envelope_id,
                recipients=recipients,
                resend_envelope='true')
            assert recipients_update_summary is not None
            assert len(recipients_update_summary.recipient_update_results) > 0
            assert (None == recipients_update_summary.
                    recipient_update_results[0].error_details)
            print("RecipientsUpdateSummary: ", end="")
            pprint(recipients_update_summary)

        except ApiException as e:
            print("\nException when calling DocuSign API: %s" % e)
            assert e is None  # make the test case fail in case of an API exception