def testRequestASignature(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'

        # 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

        envelope_definition.status = 'sent'

        envelopes_api = EnvelopesApi()

        try:
            envelope_summary = envelopes_api.create_envelope(
                self.user_info.accounts[0].account_id,
                envelope_definition=envelope_definition)
            assert envelope_summary is not None
            assert envelope_summary.envelope_id is not None
            assert envelope_summary.status == 'sent'

            print("EnvelopeSummary: ", end="")
            pprint(envelope_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
Exemple #2
0
    def send_template(self, name, email):
        webbrowser.open_new_tab(self._oauth_login_url)
        print(self._oauth_login_url)

        self._api_client.configure_jwt_authorization_flow(
            self._private_key_filename, self._oauth_base_url, self._integrator_key, self._user_id, 3600)

        docusign.configuration.api_client = self._api_client

        template_role_name = 'Needs to sign'

        # 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.'

        # assign template information including ID and role(s)
        envelope_definition.template_id = self._template_id

        # create a template role with a valid template_id and role_name and assign signer info
        t_role = docusign.TemplateRole()
        t_role.role_name = template_role_name
        t_role.name = name
        t_role.email = email

        # create a list of template roles and add our newly created role
        # assign template role(s) to the envelope
        envelope_definition.template_roles = [t_role]

        # send the envelope by setting |status| to "sent". To save as a draft set to "created"
        envelope_definition.status = 'sent'

        auth_api = AuthenticationApi()
        envelopes_api = EnvelopesApi()

        try:
            login_info = auth_api.login(api_password='******', include_account_id_guid='true')
            assert login_info is not None
            assert len(login_info.login_accounts) > 0
            login_accounts = login_info.login_accounts
            assert login_accounts[0].account_id is not None

            self._base_url, _ = login_accounts[0].base_url.split('/v2')
            self._api_client.host = self._base_url
            docusign.configuration.api_client = api_client

            envelope_summary = envelopes_api.create_envelope(login_accounts[0].account_id, envelope_definition=envelope_definition)
            assert envelope_summary is not None
            assert envelope_summary.envelope_id is not None
            assert envelope_summary.status == 'sent'

            print("EnvelopeSummary: ", end="")
            pprint(envelope_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 testRequestSignatureFromTemplate(self):
        template_role_name = 'Needs to sign'

        # 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.'

        # assign template information including ID and role(s)
        envelope_definition.template_id = template_id

        # create a template role with a valid templateId and roleName and assign signer info
        t_role = docusign.TemplateRole()
        t_role.role_name = template_role_name
        t_role.name = 'Pat Developer'
        t_role.email = username

        # create a list of template roles and add our newly created role
        # assign template role(s) to the envelope
        envelope_definition.template_roles = [t_role]

        # send the envelope by setting |status| to "sent". To save as a draft set to "created"
        envelope_definition.status = 'sent'

        auth_api = AuthenticationApi()
        envelopes_api = EnvelopesApi()

        try:
            login_info = auth_api.login(api_password='******',
                                        include_account_id_guid='true')
            assert login_info is not None
            assert len(login_info.login_accounts) > 0
            login_accounts = login_info.login_accounts
            assert login_accounts[0].account_id is not None

            base_url, _ = login_accounts[0].base_url.split('/v2')
            self.api_client.host = base_url
            docusign.configuration.api_client = self.api_client

            envelope_summary = envelopes_api.create_envelope(
                login_accounts[0].account_id,
                envelope_definition=envelope_definition)
            assert envelope_summary is not None
            assert envelope_summary.envelope_id is not None
            assert envelope_summary.status == 'sent'

            print("EnvelopeSummary: ", end="")
            pprint(envelope_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
Exemple #4
0
    def setUp(self):
        self.api_client = docusign.ApiClient(base_path=BaseUrl,
                                             oauth_host_name=OauthHostName)
        self.api_client.rest_client.pool_manager.clear()

        docusign.configuration.api_client = self.api_client
        try:
            email_subject = 'Please Sign my Python SDK Envelope'
            email_blurb = 'Hello, Please sign my Python SDK Envelope.'
            template_id = TemplateId

            role_name = 'Needs to sign'
            name = 'Pat Developer'
            email = Username
            t_role = docusign.TemplateRole(role_name=role_name,
                                           name=name,
                                           email=email)
            # send the envelope by setting |status| to "sent". To save as a draft set to "created"
            status = 'sent'
            # create an envelope definition
            envelope_definition = docusign.EnvelopeDefinition(
                email_subject=email_subject,
                email_blurb=email_blurb,
                template_id=template_id,
                template_roles=[t_role],
                status=status)

            envelopes_api = EnvelopesApi()

            self.api_client.host = BaseUrl
            token = (self.api_client.request_jwt_user_token(
                client_id=IntegratorKey,
                user_id=UserId,
                oauth_host_name=OauthHostName,
                private_key_bytes=PrivateKeyBytes,
                expires_in=3600))
            self.user_info = self.api_client.get_user_info(token.access_token)
            self.api_client.rest_client.pool_manager.clear()
            docusign.configuration.api_client = self.api_client
            envelope_summary = envelopes_api.create_envelope(
                self.user_info.accounts[0].account_id,
                envelope_definition=envelope_definition)
            self.api_client.rest_client.pool_manager.clear()
            self.envelope_id = envelope_summary.envelope_id

        except ApiException as e:
            print("\nException when calling DocuSign API: %s" % e)
        except Exception as e:
            print("\nException when calling DocuSign API: %s" % e)
        self.api_client.rest_client.pool_manager.clear()
    def testRequestSignatureFromTemplate(self):
        template_role_name = 'Needs to sign'

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

        # assign template information including ID and role(s)
        template_id = TemplateId

        # create a template role with a valid templateId and roleName and assign signer info
        role_name = template_role_name
        name = 'Pat Developer'
        email = Username
        t_role = docusign.TemplateRole(role_name=role_name,
                                       name=name,
                                       email=email)

        # create a list of template roles and add our newly created role
        # assign template role(s) to the envelope
        template_roles = [t_role]

        # send the envelope by setting |status| to "sent". To save as a draft set to "created"
        status = 'sent'

        # create the envelope definition with the properties set
        envelope_definition = docusign.EnvelopeDefinition(
            email_subject=email_subject,
            email_blurb=email_blurb,
            template_id=template_id,
            template_roles=template_roles,
            status=status)

        envelopes_api = EnvelopesApi()

        try:
            envelope_summary = envelopes_api.create_envelope(
                self.user_info.accounts[0].account_id,
                envelope_definition=envelope_definition)
            assert envelope_summary is not None
            assert envelope_summary.envelope_id is not None
            assert envelope_summary.status == 'sent'

            print("EnvelopeSummary: ", end="")
            pprint(envelope_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
Exemple #6
0
    def setUp(self):
        self.api_client = docusign.ApiClient(base_path=BaseUrl,
                                             oauth_host_name=OauthHostName)
        self.api_client.rest_client.pool_manager.clear()

        docusign.configuration.api_client = self.api_client
        self.private_key_file_name = "{}/keys/private.pem".format(
            os.path.dirname(os.path.abspath(__file__)))
        try:
            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.'
            envelope_definition.template_id = TemplateId
            t_role = docusign.TemplateRole()
            t_role.role_name = 'Needs to sign'
            t_role.name = 'Pat Developer'
            t_role.email = Username
            envelope_definition.template_roles = [t_role]

            # send the envelope by setting |status| to "sent". To save as a draft set to "created"
            envelope_definition.status = 'sent'
            envelopes_api = EnvelopesApi()

            with open(self.private_key_file_name, 'r') as private_key:
                self.api_client.host = BaseUrl
                token = (self.api_client.request_jwt_user_token(
                    client_id=IntegratorKey,
                    user_id=UserId,
                    oauth_host_name=OauthHostName,
                    private_key_bytes=private_key.read(),
                    expires_in=1))
            self.user_info = self.api_client.get_user_info(token.access_token)
            self.api_client.rest_client.pool_manager.clear()
            docusign.configuration.api_client = self.api_client
            envelope_summary = envelopes_api.create_envelope(
                self.user_info.accounts[0].account_id,
                envelope_definition=envelope_definition)
            self.api_client.rest_client.pool_manager.clear()
            self.envelope_id = envelope_summary.envelope_id

        except ApiException as e:
            print("\nException when calling DocuSign API: %s" % e)
        self.api_client.rest_client.pool_manager.clear()
Exemple #7
0
print('oauth_login_url=%s' % oauth_login_url)

# END OF NOTE

# configure the ApiClient to asynchronously get an access token and store it
api_client.configure_jwt_authorization_flow(private_key_filename,
                                            oauth_base_url, integrator_key,
                                            user_id,
                                            3600)  #TODO we cannot reach this
docusign.configuration.api_client = api_client

##endregion authentication

##region prepare envelope
# 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.'
# assign template information including ID and role(s)
envelope_definition.template_id = template_id

# create a template role with a valid template_id and role_name and assign signer info
t_role = docusign.TemplateRole()
t_role.role_name = template_role_name
t_role.name = 'Pat Developer'
t_role.email = user_name

# create a list of template roles and add our newly created role
# assign template role(s) to the envelope
envelope_definition.template_roles = [t_role]
    def testDownLoadEnvelopeDocuments(self):
        file_contents = open(sign_test1_file, 'rb').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 Text tab somewhere on the document for the signer to sign
        text = docusign.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'

        tabs = docusign.Tabs()
        tabs.text_tabs = [text]
        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'

        auth_api = AuthenticationApi()
        envelopes_api = EnvelopesApi()

        try:
            login_info = auth_api.login()
            assert login_info is not None
            assert len(login_info.login_accounts) > 0
            login_accounts = login_info.login_accounts
            assert login_accounts[0].account_id is not None

            base_url, _ = login_accounts[0].base_url.split('/v2')
            self.api_client.host = base_url
            docusign.configuration.api_client = self.api_client

            envelope_summary = envelopes_api.create_envelope(
                login_accounts[0].account_id,
                envelope_definition=envelope_definition)
            assert envelope_summary is not None
            assert envelope_summary.envelope_id is not None

            print("EnvelopeSummary: ", end="")
            pprint(envelope_summary)

            file = envelopes_api.get_document(login_accounts[0].account_id,
                                              'combined',
                                              envelope_summary.envelope_id)
            assert len(file) > 0
            subprocess.call('open ' + file, shell=True)

        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
Exemple #9
0
def testRequestASignature():
    username = "******"
    password = "******"
    integrator_key = "26ec5e49-a531-4457-ab81-163d76f37a17"
    BASE_URL = "https://demo.docusign.net/restapi"
    user_id = "39c6e30b-3b99-486f-a671-96acc240d7ab"
    oauth_base_url = "account-d.docusign.com"  # use account.docusign.com for Live/Production
    api_client = docusign.ApiClient(BASE_URL)
    redirect_uri = "https://www.docusign.com"
    private_key_filename = 'private_key2.txt'

    # IMPORTANT NOTE:
    # the first time you ask for a JWT access token, you should grant access by making the following call
    # get DocuSign OAuth authorization url:
    oauth_login_url = api_client.get_jwt_uri(integrator_key, redirect_uri,
                                             oauth_base_url)
    # open DocuSign OAuth authorization url in the browser, login and grant access
    # webbrowser.open_new_tab(oauth_login_url)
    print(oauth_login_url)
    # END OF NOTE

    # configure the ApiClient to asynchronously get an access to token and store it
    api_client.configure_jwt_authorization_flow(private_key_filename,
                                                oauth_base_url, integrator_key,
                                                user_id, 3600)

    docusign.configuration.api_client = api_client

    # sign_test1_file = "test/docs/SignTest1.pdf"
    file_contents = open('/Users/lisayoo/Desktop/contract.pdf', 'rb').read()

    # create an envelope to be signed
    envelope_definition = docusign.EnvelopeDefinition()
    envelope_definition.email_subject = "Hi! Here's your annotated contract."
    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 = "test.pdf"
    doc.document_id = '1'
    envelope_definition.documents = [doc]

    # Add a recipient to sign the document
    signer = docusign.Signer()
    signer.email = "*****@*****.**"
    signer.name = 'Kat Wicks'
    signer.recipient_id = '1'

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

    envelope_definition.status = 'sent'

    auth_api = AuthenticationApi()
    envelopes_api = EnvelopesApi()

    try:
        login_info = auth_api.login(api_password='******',
                                    include_account_id_guid='true')
        assert login_info is not None
        assert len(login_info.login_accounts) > 0
        login_accounts = login_info.login_accounts
        assert login_accounts[0].account_id is not None

        base_url, _ = login_accounts[0].base_url.split('/v2')
        api_client.host = base_url
        docusign.configuration.api_client = api_client

        envelope_summary = envelopes_api.create_envelope(
            login_accounts[0].account_id,
            envelope_definition=envelope_definition)
        assert envelope_summary is not None
        assert envelope_summary.envelope_id is not None
        assert envelope_summary.status == 'sent'

        print("EnvelopeSummary: ", end="")
        print(envelope_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 testRequestASignature(self):
        file_contents = open(sign_test1_file, 'rb').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'

        # 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

        envelope_definition.status = 'sent'

        auth_api = AuthenticationApi()
        envelopes_api = EnvelopesApi()

        try:
            login_info = auth_api.login(api_password='******',
                                        include_account_id_guid='true')
            assert login_info is not None
            assert len(login_info.login_accounts) > 0
            login_accounts = login_info.login_accounts
            assert login_accounts[0].account_id is not None

            base_url, _ = login_accounts[0].base_url.split('/v2')
            self.api_client.host = base_url
            docusign.configuration.api_client = self.api_client

            envelope_summary = envelopes_api.create_envelope(
                login_accounts[0].account_id,
                envelope_definition=envelope_definition)
            assert envelope_summary is not None
            assert envelope_summary.envelope_id is not None
            assert envelope_summary.status == 'sent'

            print("EnvelopeSummary: ", end="")
            pprint(envelope_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 testMoveEnvelopes(self):
        with open(SignTest1File, 'rb') as sign_file:
            file_contents = sign_file.read()

        # Set properties for envelope 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]

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

        # 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)
        signer.tabs = tabs

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

        status = 'sent'
        # Now setting all the properties in previous steps create the envelope now
        envelope_definition = docusign.EnvelopeDefinition(
            email_subject=email_subject,
            email_blurb=email_blurb,
            documents=documents,
            recipients=recipients,
            status=status)
        envelopes_api = EnvelopesApi()

        try:
            envelope_summary = envelopes_api.create_envelope(
                self.user_info.accounts[0].account_id,
                envelope_definition=envelope_definition)
            assert envelope_summary is not None
            assert envelope_summary.envelope_id is not None
            assert envelope_summary.status == 'sent'

            folders_api = FoldersApi()
            folders_request = docusign.FoldersRequest(
                envelope_ids=[envelope_summary.envelope_id],
                from_folder_id="sentitems")

            to_folder_id = "draft"

            folders_api.move_envelopes(self.user_info.accounts[0].account_id,
                                       to_folder_id,
                                       folders_request=folders_request)

            # Wait for 3 second to make sure the newly created envelope was moved to the 'sentitems' folder
            # Note: It's discouraged to use sleep statement or to poll DocuSign for envelope status or folder id
            # In production, use DocuSign Connect to get notified when the status of the envelope have changed.
            # 3 Seconds because sometimes when not in public or slow networks, the call takes more time and fails for 1 second.
            sleep(3)
            # Test if we moved the envelope to the correct folder

            search_options = "true"
            list_from_drafts_folder = folders_api.list_items(
                self.user_info.accounts[0].account_id,
                to_folder_id,
                include_items=search_options)

            assert list_from_drafts_folder is not None

            for folder in list_from_drafts_folder.folders:
                for list_item in folder.folder_items:
                    if list_item.envelope_id == envelope_summary.envelope_id:
                        return

            assert False

        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
Exemple #13
0
def create_envelope_definition_for_hpa(docs: HPActionDocuments) -> dse.EnvelopeDefinition:
    """
    Create a DocuSign envelope definition for the given HP Action documents.
    """

    user = docs.user

    xml_bytes = docs.xml_file.open().read()
    case_type = HPAType.get_from_answers_xml(xml_bytes)

    pdf_file = docs.open_emergency_pdf_file()
    if not pdf_file:
        raise Exception(
            "Unable to open emergency HP Action packet (it may only consist " "of instructions)"
        )
    pdf_bytes = pdf_file.read()
    base64_pdf = base64.b64encode(pdf_bytes).decode("ascii")

    document = dse.Document(
        document_base64=base64_pdf,
        name=f"HP Action forms for {user.full_legal_name}",
        file_extension="pdf",
        document_id=HPA_DOCUMENT_ID,
    )

    signer = dse.Signer(
        email=user.email,
        name=user.full_legal_name,
        recipient_id=TENANT_RECIPIENT_ID,
        routing_order="1",
        client_user_id=docusign_client_user_id(user),
    )

    cfg = FormsConfig.from_case_type(case_type)
    cfg.ensure_expected_pages(PyPDF2.PdfFileReader(BytesIO(pdf_bytes)).numPages)
    signer.tabs = cfg.to_docusign_tabs(contact_info=get_contact_info(user))

    carbon_copies: List[dse.CarbonCopy] = [
        dse.CarbonCopy(
            email=user.email,
            name=user.full_legal_name,
            recipient_id="2",
            routing_order="2",
        )
    ]

    court_contacts = get_court_contacts_for_user(user)
    if not court_contacts:
        # This is bad, but we can always manually forward the signed document
        # to the proper court, so just log an error instead of raising
        # an exception.
        logger.error(f"No housing court found for user '{user.username}'!")
    carbon_copies.extend(
        cc_court_contacts(
            court_contacts,
            initial_recipient_id=3,
            routing_order="2",
        )
    )

    envelope_definition = dse.EnvelopeDefinition(
        email_subject=f"HP Action forms for {user.full_legal_name}",
        documents=[document],
        recipients=dse.Recipients(signers=[signer], carbon_copies=carbon_copies),
        status="sent",
    )

    assert isinstance(envelope_definition, dse.EnvelopeDefinition)

    return envelope_definition
    def testMoveEnvelopes(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'

        # 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

        envelope_definition.status = 'sent'

        envelopes_api = EnvelopesApi()

        try:
            envelope_summary = envelopes_api.create_envelope(
                self.user_info.accounts[0].account_id,
                envelope_definition=envelope_definition)
            assert envelope_summary is not None
            assert envelope_summary.envelope_id is not None
            assert envelope_summary.status == 'sent'

            folders_api = FoldersApi()
            folders_request = docusign.FoldersRequest(
                envelope_ids=[envelope_summary.envelope_id],
                from_folder_id="sentitems")

            to_folder_id = "draft"

            folders_api.move_envelopes(self.user_info.accounts[0].account_id,
                                       to_folder_id,
                                       folders_request=folders_request)

            # Wait for 1 second to make sure the newly created envelope was moved to the 'sentitems' folder
            # Note: It's discouraged to use sleep statement or to poll DocuSign for envelope status or folder id
            # In production, use DocuSign Connect to get notified when the status of the envelope have changed.
            sleep(1)
            # Test if we moved the envelope to the correct folder
            list_from_drafts_folder = folders_api.list_items(
                self.user_info.accounts[0].account_id, to_folder_id)

            assert list_from_drafts_folder is not None

            for item in list_from_drafts_folder.folder_items:
                if item.envelope_id == envelope_summary.envelope_id:
                    return

            assert False

        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()

        # 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 testRequestASignature(self):
        with open(SignTest1File, 'rb') as sign_file:
            file_contents = sign_file.read()

        # Set properties and create an envelope 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
        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'
        documents = [doc]

        # 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'
        recipient_id = '1'
        signer = docusign.Signer(email=email,
                                 name=name,
                                 recipient_id=recipient_id,
                                 tabs=tabs)
        signers = [signer]
        recipients = docusign.Recipients(signers=signers)

        status = 'sent'

        # create the envelope definition with the properties set
        envelope_definition = docusign.EnvelopeDefinition(
            email_subject=email_subject,
            email_blurb=email_blurb,
            documents=documents,
            recipients=recipients,
            status=status)

        envelopes_api = EnvelopesApi()

        try:
            envelope_summary = envelopes_api.create_envelope(
                self.user_info.accounts[0].account_id,
                envelope_definition=envelope_definition)
            assert envelope_summary is not None
            assert envelope_summary.envelope_id is not None
            assert envelope_summary.status == 'sent'

            print("EnvelopeSummary: ", end="")
            pprint(envelope_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 createEnv(repReports=extractReport(),
              template_id="a07ff1a4-d135-459a-ac45-e5b1f3f5e021",
              api_client=dsAuth(),
              template_role_name='Rep',
              template_role_cc='Rep Manager'):
    docusign.configuration.api_client = api_client
    data_labels = {
        "CaseNum_Label":
        ["CNum_1", "CNum_2", "CNum_3", "CNum_4", "CNum_5", "CNum_6"],
        "DateEsc_Label":
        ["Date_1", "Date_2", "Date_3", "Date_4", "Date_5", "Date_6"],
        "Subject_Label": [
            "Subject_1", "Subject_2", "Subject_3", "Subject_4", "Subject_5",
            "Subject_6"
        ],
        "CaseRes_Label": [
            "Resolution_1", "Resolution_2", "Resolution_3", "Resolution_4",
            "Resolution_5", "Resolution_6"
        ],
        "T3": ["T3_1", "T3_2", "T3_3", "T3_4", "T3_5", "T3_6"],
        "Link": ["Link_1", "Link_2", "Link_3", "Link_4", "Link_5", "Link_6"]
    }
    # repEmails = get_emails()
    sentListOut = []
    env_count = 0
    # loop through each rep
    for key, val in repReports.items():
        if key != "Bug Backlog" and val[
                'MgrEmail'] != 'n/a':  # '*****@*****.**':  # and val['Email'].lower() == '*****@*****.**':
            # create an envelope to be signed
            envelope_definition = docusign.EnvelopeDefinition()
            if val['MgrEmail'] == '*****@*****.**' or val['Email'].lower() \
                    in ("*****@*****.**","*****@*****.**","*****@*****.**"):
                envelope_definition.email_subject = 'Tier 3 case escalation feedback - ' \
                                                    'here\'s what happened with your recent previously owned cases'
                envelope_definition.email_blurb = 'Hello ' + key.split(' ')[
                    0] + ', \n\nI\'m sending these out to you tier 3 reps as well now so if another tier 3 or dev ' \
                         'support takes on your cases we can close the loop on these as well. \n\nFeel free to message ' \
                         'me for any suggestions on how to make this program even better. \n\nThanks for reading,' \
                         '\n\nKevin\'s Autofeedbacker bot'
            else:
                envelope_definition.email_subject = 'Tier 3 case escalation feedback - here\'s what happened with ' \
                                                    'your recent escalated cases'
                envelope_definition.email_blurb = 'Hello ' + key.split(' ')[
                    0] + ', \n\nWe\'re starting a new program intended to provide you with a followup on how the cases ' \
                         'you escalated to tier 3 were resolved. The purpose of this is to learn from these cases, ' \
                         'we know you\'re too busy to check up on all of those so we\'re making it easy with these ' \
                         'weekly reports. If you\'re missing any cases we may still be working on them so stay tuned. ' \
                         'Feel free to reach out to the tier 3 rep who closed these cases for more details on what ' \
                         'they did. \n\nFeel free to message Kevin Alber for any suggestions on how to make this ' \
                         'program even better. \n\nThanks for reading,\n\nKevin\'s Autofeedbacker bot'

            # assign template information including ID and role(s)
            envelope_definition.template_id = template_id

            # create manager email notification, need to test

            mgr_emailNotification = docusign.RecipientEmailNotification()
            mgr_emailNotification.email_subject = 'Tier 3 case escalation feedback - here\'s what happened with ' + \
                                                  key.split(' ')[0] + '\'s recent escalated cases'
            mgr_emailNotification.email_body = 'Hello ' + val['MgrEmail'].split('.')[
                0].title() + ', \n\n We\'re starting a new program intended to provide your reps with feedback on cases ' \
                             'that they escalated to tier 3 so they can learn from them and you can better coach them. ' \
                             'Please let me, Kevin Alber, know if you have any feedback about this process. \n\nThanks ' \
                             'for reading,\n\nKevin\'s Autofeedbacker bot'

            # create a template role with a valid template_id and role_name and assign signer info
            t_role = docusign.TemplateRole()
            t_role.role_name = template_role_name
            t_role.name = key
            if test_mode == 1:
                t_role.email = '*****@*****.**'  # for real send
            else:
                t_role.email = val['Email']
                print("Envelope going to rep: " + val['Email'])

            # mgr role on template
            t_role_cc = docusign.TemplateRole()
            t_role_cc.role_name = template_role_cc
            t_role_cc.name = val['MgrEmail'].split('@')[0].replace(
                '.', ' ').title()  # might want to just add this to spreadsheet
            if test_mode == 1 or val[
                    'MgrEmail'] == '*****@*****.**':
                t_role_cc.email = '*****@*****.**'  #
            else:
                t_role_cc.email = val['MgrEmail']
            t_role_cc.email_notification = mgr_emailNotification

            # create a list of template roles and add our newly created role
            # assign template role(s) to the envelope
            envelope_definition.template_roles = [t_role, t_role_cc]

            # send the envelope by setting |status| to "sent". To save as a draft set to "created"
            envelope_definition.status = 'created'

            # notif = Notification()
            # notif.use_account_defaults = "True"

            # envelope_definition.notification = notif
            auth_api = AuthenticationApi()
            envelopes_api = EnvelopesApi()

            # create draft
            try:
                login_info = auth_api.login(
                    api_password='******', include_account_id_guid='true')  ###
                assert login_info is not None
                assert len(login_info.login_accounts) > 0
                login_accounts = login_info.login_accounts
                assert login_accounts[0].account_id is not None

                base_url, _ = login_accounts[0].base_url.split('/v2')
                api_client.host = base_url
                docusign.configuration.api_client = api_client

                envelope_summary = envelopes_api.create_envelope(
                    login_accounts[0].account_id,
                    envelope_definition=envelope_definition)
                assert envelope_summary is not None
                assert envelope_summary.envelope_id is not None
                assert envelope_summary.status == 'created'
                env_count += 1
                # print("Envelope Created Summary: ", end="")
                # pprint(envelope_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

            # get array of tab objects on the current envelope
            tab_array = envelopes_api.get_page_tabs(
                login_accounts[0].account_id, 1, envelope_summary.envelope_id,
                1).text_tabs

            # iterate through each case as row in envelope
            row = 0
            tab_list = []
            for v in val['Cases']:
                if row < 6:
                    label = 'CaseNum_Label'
                    target_tab = next(
                        (x for x in tab_array
                         if x.tab_label == data_labels[label][row]), None)
                    assert target_tab is not None
                    t_col1 = docusign.Text()
                    t_col1.tab_label = data_labels[label][row - 1]
                    t_col1.value = str(v['CaseNumber'])
                    t_col1.tab_id = target_tab.tab_id
                    t_col1.documentId = "1"
                    t_col1.recipientId = "1"
                    t_col1.pageNumber = 1
                    tab_list.append(t_col1)
                    # print(str(v['CaseNumber']))
                    sentListOut.append(v['CaseNumber'])

                    label = 'DateEsc_Label'
                    target_tab = next(
                        (x for x in tab_array
                         if x.tab_label == data_labels[label][row]), None)
                    assert target_tab is not None
                    t_col2 = docusign.Text()
                    t_col2.tab_label = data_labels[label][row]
                    t_col2.value = v['DateEscalated']
                    t_col2.tab_id = target_tab.tab_id
                    t_col2.documentId = "1"
                    t_col2.recipientId = "1"
                    t_col2.pageNumber = 1
                    tab_list.append(t_col2)

                    # subMaxChar = charLimit(19, 10, v['Subject'])
                    if len(v['Subject']) > 160:
                        extra = '...'
                    else:
                        extra = ''

                    label = 'Subject_Label'
                    target_tab = next(
                        (x for x in tab_array
                         if x.tab_label == data_labels[label][row]), None)
                    assert target_tab is not None
                    t_col3 = docusign.Text()
                    t_col3.tab_label = data_labels[label][row]
                    t_col3.disable_auto_size = 'True'
                    t_col3.height = '200'
                    t_col3.value = v['Subject'][:160] + extra
                    t_col3.tab_id = target_tab.tab_id
                    t_col3.documentId = "1"
                    t_col3.recipientId = "1"
                    t_col3.pageNumber = 1
                    tab_list.append(t_col3)

                    if len(v['CaseResolution']) > 184:
                        extra = '...'
                    else:
                        extra = ''

                    label = 'CaseRes_Label'
                    target_tab = next(
                        (x for x in tab_array
                         if x.tab_label == data_labels[label][row]), None)
                    assert target_tab is not None
                    t_col4 = docusign.Text()
                    t_col4.tab_label = data_labels[label][row]
                    t_col4.disable_auto_size = 'True'
                    t_col4.height = '200'
                    t_col4.value = v['CaseResolution'][:184] + extra
                    t_col4.tab_id = target_tab.tab_id
                    t_col4.documentId = "1"
                    t_col4.recipientId = "1"
                    t_col4.pageNumber = 1
                    tab_list.append(t_col4)

                    label = 'T3'
                    target_tab = next(
                        (x for x in tab_array
                         if x.tab_label == data_labels[label][row]), None)
                    assert target_tab is not None
                    t_col5 = docusign.Text()
                    t_col5.tab_label = data_labels[label][row]
                    t_col5.value = v['T3RepName']
                    t_col5.tab_id = target_tab.tab_id
                    t_col5.documentId = "1"
                    t_col5.recipientId = "1"
                    t_col5.pageNumber = 1
                    tab_list.append(t_col5)

                    label = 'Link'
                    target_tab = next(
                        (x for x in tab_array
                         if x.tab_label == data_labels[label][row]), None)
                    assert target_tab is not None
                    t_col6 = docusign.Text()
                    t_col6.tab_label = "#HREF_" + data_labels[label][row]
                    t_col6.name = v['link']
                    t_col6.value = 'Go to Case'
                    t_col6.tab_id = target_tab.tab_id
                    t_col6.documentId = "1"
                    t_col6.recipientId = "1"
                    t_col6.pageNumber = 1
                    tab_list.append(t_col6)

                    row += 1
                else:
                    print("We're over 6 cases for rep" + val['Email'] +
                          ", dropped case " + str(v['CaseNumber']))

            # now update those tabs using my list of tab definitions, then update status to sent
            tabs = docusign.Tabs()
            tabs.text_tabs = tab_list
            envelopes_api.update_tabs(login_accounts[0].account_id,
                                      envelope_summary.envelope_id,
                                      1,
                                      tabs=tabs)
            envelope_definition.status = 'sent'
            envelope_summary2 = envelopes_api.update(
                login_accounts[0].account_id,
                envelope_summary.envelope_id,
                envelope=envelope_definition)
            if test_mode != 1:
                updateSentList(sentListOut)

            # print("Sent: " +str(key)+ " envId: " + ) # + "EnvelopeSummary: ", end="")
            # pprint(envelope_summary2)
    print("Count: " + str(env_count))
Exemple #18
0
    def send_document_for_signatures(template_id, email, user_full_name):
        """
        Creates a document for the user to sign

        :param template_id: (string) -> The docusign template to use for the documents
        :param email: (string) -> The user email to send the documents to
        :param user_full_name: (string) -> The full name of the user
        :return: (string|None) -> Returns either the envelope_id of the created documents or None if there was a failure
        """

        # Create the role name
        template_role_name = 'Client'

        # create an envelope to be signed
        envelope_definition = docusign.EnvelopeDefinition()
        envelope_definition.email_subject = 'Please Sign the Cocoon Documents'
        envelope_definition.email_blurb = 'Hello, Please sign my Cocoon Documents.'

        # assign template information including ID and role(s)
        envelope_definition.template_id = template_id

        # create a template role with a valid template_id and role_name and assign signer info
        t_role = docusign.TemplateRole()
        t_role.role_name = template_role_name
        t_role.name = user_full_name
        t_role.email = email

        # create a list of template roles and add our newly created role
        # assign template role(s) to the envelope
        envelope_definition.template_roles = [t_role]

        # send the envelope by setting |status| to "sent". To save as a draft set to "created"
        envelope_definition.status = 'sent'

        # Initialize the auth and envelope api
        auth_api = AuthenticationApi()
        envelopes_api = EnvelopesApi()

        try:
            # Login into the api
            login_info = auth_api.login(api_password='******',
                                        include_account_id_guid='true')
            assert login_info is not None, "Login_info is None"
            assert len(login_info.login_accounts) > 0, "There are 0 accounts"
            login_accounts = login_info.login_accounts
            assert login_accounts[
                0].account_id is not None, "Account id is None"

            # Create and send the envelope to the user
            envelope_summary = envelopes_api.create_envelope(
                login_accounts[0].account_id,
                envelope_definition=envelope_definition)
            assert envelope_summary is not None, "Envelope_summary is None"
            assert envelope_summary.envelope_id is not None, "Envelope id is None"
            assert envelope_summary.status == 'sent', "Envelop status != sent"

            logger.debug(envelope_summary)

            # Returns the envelope_id so that it can be stored in the database
            return envelope_summary.envelope_id

        except ApiException as e:
            logger.error("\nException when calling DocuSign API: %s" % e)
            return None

        except AssertionError as e:
            logger.error("\nAssertionError in {0}: {1}".format(
                DocusignWrapper.send_document_for_signatures.__name__, e))
            return None
Exemple #19
0
    def testListTabs(self):
        # For this the template Role should be manager
        template_role_name = 'Manager'

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

        # assign template information including ID and role(s)
        template_id = TemplateId

        # create a template role with a valid templateId and roleName and assign signer info
        role_name = template_role_name
        name = 'Pat Developer'
        email = Username
        t_role = docusign.TemplateRole(role_name=role_name,
                                       name=name,
                                       email=email)

        # create a list of template roles and add our newly created role
        # assign template role(s) to the envelope
        template_roles = [t_role]

        # send the envelope by setting |status| to "sent". To save as a draft set to "created"
        status = 'sent'

        # create the envelope definition with the properties set
        envelope_definition = docusign.EnvelopeDefinition(
            email_subject=email_subject,
            email_blurb=email_blurb,
            template_id=template_id,
            template_roles=template_roles,
            status=status)
        try:
            envelopes_api = EnvelopesApi()

            # Create Envelope with the new role
            envelope_summary = envelopes_api.create_envelope(
                self.user_info.accounts[0].account_id,
                envelope_definition=envelope_definition)
            # Read the new Envelope
            created_envelope = envelopes_api.get_envelope(
                account_id=self.user_info.accounts[0].account_id,
                envelope_id=envelope_summary.envelope_id)

            recipients = envelopes_api.list_recipients(
                account_id=self.user_info.accounts[0].account_id,
                envelope_id=created_envelope.envelope_id)

            tabs = envelopes_api.list_tabs(
                account_id=self.user_info.accounts[0].account_id,
                envelope_id=created_envelope.envelope_id,
                recipient_id=recipients.signers[0].recipient_id)
            list_tabs = tabs.list_tabs

            assert list_tabs is not None

        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
        except Exception 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 testEmbeddedSigning(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

        envelope_definition.status = 'sent'

        envelopes_api = EnvelopesApi()

        try:

            return_url = 'http://www.docusign.com/developer-center'
            recipient_view_request = docusign.RecipientViewRequest()
            recipient_view_request.return_url = return_url
            recipient_view_request.client_user_id = client_user_id
            recipient_view_request.authentication_method = 'email'
            recipient_view_request.user_name = 'Pat Developer'
            recipient_view_request.email = Username

            envelope_summary = envelopes_api.create_envelope(
                self.user_info.accounts[0].account_id,
                envelope_definition=envelope_definition)
            envelope_id = envelope_summary.envelope_id

            view_url = envelopes_api.create_recipient_view(
                self.user_info.accounts[0].account_id,
                envelope_id,
                recipient_view_request=recipient_view_request)

            assert view_url is not None
            assert view_url.url is not None

            # This Url should work in an Iframe or browser to allow signing
            print("ViewUrl is ", end="")
            pprint(view_url)

        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 testDownLoadEnvelopeDocuments(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 Text tab somewhere on the document for the signer to sign
        text = docusign.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'

        tabs = docusign.Tabs()
        tabs.text_tabs = [text]
        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

            file1 = envelopes_api.get_document(
                self.user_info.accounts[0].account_id, 'combined',
                self.envelope_id)

            assert len(file1) > 0
            subprocess.call('open ' + file1, shell=True)

        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
Exemple #22
0
def handle_message(message):  # server has recieved a message from a client
    print(message)
    if (message['type'] == 'coordinates'):
        petitions = mongo.db.petitions.find_one(
            {'username': message['username']})

        petition = {
            'petition_name': message['petition_name'],
            'petition_decr': message['petition_name'],
            'lng': message['lng'],
            'lat': message['lat']
        }

        if petitions:
            p_list = list(petitions['petitions'])
            p_list.append(petition)
            mongo.db.users.update_one({"username": message["username"]},
                                      {"$set": {
                                          "petitions": p_list
                                      }})

        else:
            p_list = list()
            p_list.append(petition)
            print(p_list)
            mongo.db.petitions.insert_one({"username": message["username"]},
                                          {"petitions": []})

            mongo.db.petitions.update_one({"username": message["username"]},
                                          {"$set": {
                                              "petitions": p_list
                                          }})

    elif (message['type'] == 'getPetitions'):
        room = connectedUsers[message["username"]]

        all_p = mongo.db.petitions.find()
        p_list = list()
        for message in all_p:
            for petitions in list(message['petitions']):
                p_list.append(petitions)

        sendToRoom(
            socketio, {
                "type": "gotPetitions",
                "petitions": json.loads(json_util.dumps(p_list)),
                "room": room
            })

    elif (message['type'] == 'sendDocument'):
        user_name = "60d34380-6d41-4fa8-9701-05490acea776"
        integrator_key = "fe7f0a39-3572-4979-9fa7-79f38d969132"
        base_url = "https://demo.docusign.net/restapi"
        oauth_base_url = "account-d.docusign.com"  # use account.docusign.com for Live/Production
        redirect_uri = "https://www.docusign.com/api"
        private_key_filename = "keys/docusign_private_key.txt"
        user_id = "60d34380-6d41-4fa8-9701-05490acea776"
        template_id = "e82be205-2edb-46da-98e6-e9c20417b474"

        api_client = docusign.ApiClient(base_url)

        # IMPORTANT NOTE:
        # the first time you ask for a JWT access token, you should grant access by making the following call
        # get DocuSign OAuth authorization url:

        # oauth_login_url = api_client.get_jwt_uri(integrator_key, redirect_uri, oauth_base_url)

        # open DocuSign OAuth authorization url in the browser, login and grant access
        # webbrowser.open_new_tab(oauth_login_url)
        # END OF NOTE

        # configure the ApiClient to asynchronously get an access token and store it
        api_client.configure_jwt_authorization_flow(private_key_filename,
                                                    oauth_base_url,
                                                    integrator_key, user_id,
                                                    3600)

        docusign.configuration.api_client = api_client

        template_role_name = 'test'

        # 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.'

        # assign template information including ID and role(s)
        envelope_definition.template_id = 'e82be205-2edb-46da-98e6-e9c20417b474'

        # create a template role with a valid template_id and role_name and assign signer info
        t_role = docusign.TemplateRole()
        t_role.role_name = 'test'
        t_role.name = 'Signer'
        t_role.email = '*****@*****.**'

        # create a list of template roles and add our newly created role
        # assign template role(s) to the envelope
        envelope_definition.template_roles = [t_role]

        # send the envelope by setting |status| to "sent". To save as a draft set to "created"
        envelope_definition.status = 'sent'

        auth_api = AuthenticationApi()
        envelopes_api = EnvelopesApi()

        try:
            login_info = auth_api.login(api_password='******',
                                        include_account_id_guid='true')
            assert login_info is not None
            assert len(login_info.login_accounts) > 0
            login_accounts = login_info.login_accounts
            assert login_accounts[0].account_id is not None

            base_url, _ = login_accounts[0].base_url.split('/v2')
            api_client.host = base_url
            docusign.configuration.api_client = api_client

            envelope_summary = envelopes_api.create_envelope(
                login_accounts[0].account_id,
                envelope_definition=envelope_definition)
            assert envelope_summary is not None
            assert envelope_summary.envelope_id is not None
            assert envelope_summary.status == 'sent'

            print("EnvelopeSummary: ", end="")
            pprint(envelope_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 testGetDiagnosticLogs(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()
        diag_api = DiagnosticsApi()

        try:
            docusign.configuration.api_client = self.api_client

            diagnostics_settings_information = docusign.DiagnosticsSettingsInformation(
            )
            diagnostics_settings_information.api_request_logging = 'true'
            diag_api.update_request_log_settings(
                diagnostics_settings_information=
                diagnostics_settings_information)
            envelope_summary = envelopes_api.create_envelope(
                self.user_info.accounts[0].account_id,
                envelope_definition=envelope_definition)
            envelope_id = envelope_summary.envelope_id

            file1 = envelopes_api.get_document(
                self.user_info.accounts[0].account_id, 'combined', envelope_id)
            assert len(file1) > 0
            subprocess.call('open ' + file1, shell=True)

            logs_list = diag_api.list_request_logs()
            request_log_id = logs_list.api_request_logs[0].request_log_id
            file2 = diag_api.get_request_log(request_log_id)
            assert len(file2) > 0
            subprocess.call('open ' + file2, shell=True)

        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 testEmbeddedSigning(self):
        with open(SignTest1File, 'rb') as sign_file:
            file_contents = sign_file.read()

        # Set properties and create an envelope 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]

        # Add a recipient to sign the document
        email = Username
        name = 'Pat Developer'
        recipient_id_for_doc = '1'

        # 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'

        # create sign here object with the properties
        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)

        signer = docusign.Signer(email=email,
                                 name=name,
                                 recipient_id=recipient_id_for_doc,
                                 client_user_id=client_user_id,
                                 tabs=tabs)

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

        status = 'sent'
        # create the envelope definition with the properties set
        envelope_definition = docusign.EnvelopeDefinition(
            email_subject=email_subject,
            email_blurb=email_blurb,
            documents=documents,
            recipients=recipients,
            status=status)

        envelopes_api = EnvelopesApi()

        try:

            return_url = 'http://www.docusign.com/developer-center'
            recipient_view_request = docusign.RecipientViewRequest()
            recipient_view_request.return_url = return_url
            recipient_view_request.client_user_id = client_user_id
            recipient_view_request.authentication_method = 'email'
            recipient_view_request.user_name = 'Pat Developer'
            recipient_view_request.email = Username

            envelope_summary = envelopes_api.create_envelope(
                self.user_info.accounts[0].account_id,
                envelope_definition=envelope_definition)
            envelope_id = envelope_summary.envelope_id

            view_url = envelopes_api.create_recipient_view(
                self.user_info.accounts[0].account_id,
                envelope_id,
                recipient_view_request=recipient_view_request)

            assert view_url is not None
            assert view_url.url is not None

            # This Url should work in an Iframe or browser to allow signing
            print("ViewUrl is ", end="")
            pprint(view_url)

        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 testDownLoadEnvelopeDocuments(self):
        with open(SignTest1File, 'rb') as sign_file:
            file_contents = sign_file.read()

        # Set properties and create an envelope to be signed
        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")
        document_name = 'TestFile.pdf'
        document_id = '1'
        doc = docusign.Document(document_base64=base64_doc,
                                name=document_name,
                                document_id=document_id)
        documents = [doc]

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

        # Create a Text tab somewhere on the document for the signer to sign
        text_document_id = '1'
        page_number = '1'
        recipient_id = '1'
        x_position = '100'
        y_position = '100'
        text = docusign.Text(document_id=text_document_id,
                             page_number=page_number,
                             recipient_id=recipient_id,
                             x_position=x_position,
                             y_position=y_position)

        text_tabs = [text]
        tabs = docusign.Tabs(text_tabs=text_tabs)

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

        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

            file1 = envelopes_api.get_document(
                self.user_info.accounts[0].account_id, 'combined',
                self.envelope_id)

            assert len(file1) > 0
            subprocess.call('open ' + file1, shell=True)

        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
Exemple #26
0
def render():
    if 'filename' in request.args:
        user_name = "30c0525d-e78d-4b50-8d1c-ecaaeb951a12"
        integrator_key = "23e1947d-fd87-4a62-95c4-3c2b0f419d53"
        base_url = "https://demo.docusign.net/restapi"
        oauth_base_url = "account-d.docusign.com"  # use account.docusign.com for Live/Production
        redirect_uri = "https://www.docusign.com/api"
        private_key_filename = "keys/docusign_private_key.txt"
        user_id = "30c0525d-e78d-4b50-8d1c-ecaaeb951a12"
        template_id = "31edfa30-c5f8-4802-9beb-5978cac10c74"
        myfilename = request.args.get('filename')
        api_client = docusign.ApiClient(base_url)

        # IMPORTANT NOTE:
        # the first time you ask for a JWT access token, you should grant access by making the following call
        # get DocuSign OAuth authorization url:
        # print(api_client)
        # print(integrator_key, redirect_uri,oauth_base_url)
        oauth_login_url = api_client.get_jwt_uri(integrator_key, redirect_uri,
                                                 oauth_base_url)
        # open DocuSign OAuth authorization url in the browser, login and grant access
        # webbrowser.open_new_tab(oauth_login_url)
        # print(oauth_login_url)

        # END OF NOTE

        # configure the ApiClient to asynchronously get an access token and store it
        # print(private_key_filename)
        api_client.configure_jwt_authorization_flow(private_key_filename,
                                                    oauth_base_url,
                                                    integrator_key, user_id,
                                                    3600)
        # print("test")
        docusign.configuration.api_client = api_client

        template_role_name = 'client'

        # 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.'
        print(envelope_definition)

        # assign template information including ID and role(s)
        envelope_definition.template_id = template_id

        # create a template role with a valid template_id and role_name and assign signer info
        t_role = docusign.TemplateRole()
        t_role.role_name = template_role_name
        t_role.name = 'Pat Developer'
        t_role.email = "%(filename)s"

        # # create a list of template roles and add our newly created role
        # # assign template role(s) to the envelope
        envelope_definition.template_roles = [t_role]

        # # send the envelope by setting |status| to "sent". To save as a draft set to "created"
        envelope_definition.status = 'sent'

        auth_api = AuthenticationApi()
        envelopes_api = EnvelopesApi()

        try:
            login_info = auth_api.login(api_password='******',
                                        include_account_id_guid='true')
            assert login_info is not None
            assert len(login_info.login_accounts) > 0
            login_accounts = login_info.login_accounts
            assert login_accounts[0].account_id is not None

            base_url, _ = login_accounts[0].base_url.split('/v2')
            api_client.host = base_url
            docusign.configuration.api_client = api_client

            envelope_summary = envelopes_api.create_envelope(
                login_accounts[0].account_id,
                envelope_definition=envelope_definition)
            assert envelope_summary is not None
            assert envelope_summary.envelope_id is not None
            assert envelope_summary.status == 'sent'

            # print("EnvelopeSummary: ", end="")
            # pprint(envelope_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

            return app.send_static_file('index.html', envelope_summary)
        else:
            return app.send_static_file('index.html')